Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
When I try to rename files from a console, the command 'rename' does not work.
It happens with proper write permissions (I tried both from a normal user account and from a root console). The command exits with 0 and no errors show up; however, the name of the files remains unchanged.
On the contrary, 'mv' works, but this command does not work with several files (in the same directory; that is, using it for renaming instead of moving).
Also, I can rename files from the different file managers I use, but I have to do it one by one and I would like the convenience of being able to rename several files at the same time from a console.
Yes, 'mv' works, but I cannot use it as a substitute of 'rename' to change the name of several files at the same time. Quoting from 'info mv': "It is an error if the last argument is not a directory and more than two files are given."
Of course, I could use 'mv' to rename/move them to another directory and then copy them back to the original directory, deleting the files with the old name, but this adds extra work to the process, and I'd really want to know why 'rename' does not behave as it should.
If you want to rename a group of files, you will need to use the find command, or a for loop to select the files.
For example, to rename all *.JPG files to *.jpg try:
for pic in *.JPG; do mv $pic ${pic%.JPG}.jpg; done
If any of the files have spaces in their names, you will need double quotes around the variables.
for pic in *.JPG; do
> mv "$pic" "${pic%.JPG}.jpg"
> done
The rename command in linux doesn't work as in DOS. The man page says the usage is rename <from> <to> <file>, where <from> is the string you want to rename, <to> is the string you want to rename it to, and <file> are the file(s) you want to rename. From the man page:
Code:
DESCRIPTION
rename will rename the specified files by replacing the first occurrence of <from> in
their name by <to>.
For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278.
And
rename .htm .html *.htm
will fix the extension of your html files.
Bebo, you're damn right. I had read the man page of 'rename' before, but I missed the whole point. Now I understand, and of course if you do it right it works.
Tinkster, thanks for suggesting 'ren'. It seems interesting. What I wanted to do was related with names more than extensions, as until now I used 'krename' to change the latter. But now I can change names and extensions from the command line, which I prefer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.