ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to rename multiple files (hundreds) that are now on an NTFS partition.
Would this be better done in Windows environment, or Linux?
How do I delete characters from multiple files' titles.
MS knowledge base has syntax for ADDING characters, but not for DELETING characters.
For adding a character:
Quote:
For example, if you had files that are named smitha.doc, smithb.doc, and smithc.doc, you could use the ren smith*.doc smythe*.doc command. All file names automatically show the new spelling, and are renamed smythea.doc, smytheb.doc, and smythec.doc.
But I want to DELETE the first 4 characters from multiple files. I have something like this:
For something like this, I doubt if there is any real difference between Linux and Windows. I have the impression that CLI work is easier and more powerful in Linux, but I nver did it in Windows--so I have nothing concrete.
From Linux, accessing the NTFS stuff should be no issue--most modern distros come with NTFS support set up by default.
Quote:
ren br3t*.doc *.doc
(For Linux, replace "ren" with "mv".) That syntax will not work in Linux, and I would be surprised if it did in Windows. At least in Linux, I know of NO case where you can have a wildcard in the target of a command like mv, cp, etc.
Assuming the files are all in one directory:
Code:
for oldname in $(ls); do
newname = echo $oldname|cut -c 5-
mv $oldname $newname
done
Probably will not work if it encounters Window filenames with spaces in them. Watch out for other special characters also.
I want to rename multiple files (hundreds) that are now on an NTFS partition.
Would this be better done in Windows environment, or Linux?
doesn't matter, as long as there are tools for you to do renaming..
Quote:
But I want to DELETE the first 4 characters from multiple files. I have something like this:
on windows, you can use vbscript..better than DOS(cmd.exe) in many ways and it comes natively installed. See here example 6 for renaming using vbscript.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
My rename is a symbolic link to prename which is [obviously] a Perl script. It is part of the package perl in Debian Lenny.
There are an awful lot of rename packages around so I am not surprised that they differ in syntax.
Noted!!---I guess i instintinctively avoid that because it is less obvious what it does. For example, will it see hidden files by default?
ls by itself doesn't display hidden files.
Code:
for files in .*
do
echo "hidden file: $i"
done
Quote:
Code:
for oldname in $(ls)
this is same as
Code:
for oldname in *
Quote:
Code:
for oldname in $(ls -a)
this is same as
Code:
for oldname in .* *
of course, if one needs the added functionality of ls with its other switches then i guess its still alright, however always take care of "spaces in filename" problem when using for loop...if not, use a while loop
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.