Add a file extension to a bunch of file names
This should not be this hard :(
I have a considerable number of files in a subdirectory (some fascinating old military clips from archive.org - search on Big Picture if interested). Anyhow, I am downloading them using Internet Download Manager running in an XP virtual machine in VMWare on my Ubuntu 10.04 PC (due to the queuing, restart and speed capabilities of IDM). But I digress - the files are being saved on the host (Samba share) without a file extension. So I have a collection of files with names like Quote:
Quote:
Any suggestions? At the moment I am renaming them from the Windows VM while they are sitting on the Samba share using the ancient File Manager program from Windows NT which works great on XP. I have experimented with the file rename facility in Gnome Commander however, it does not seem to want to do something so simple. TIA, Ken |
Not knowing whether there's any pattern to your file names
the safest bet is a loop. Code:
for i in *; do mv "$i" "$i".mp4;done Cheers, Tink |
Thanks Tink - that does the trick!
Ken |
Or if using your rename in ubuntu:
Code:
rename -n 's/\..*/.mp4/' * |
Thanks grail but that does not seem to work - I did remove the -n.
Ken |
Did it show output with -n still in?
|
No output with -n
|
So last sill question, you are running it in a directory with files that have dot and an extension?
|
I do not have any .extension files in the directory
Quote:
Quote:
|
Quote:
Code:
rename -n 's/$/.mp4/' * |
Thanks grail, that did the trick. As you have put so much effort into answering my question I feel obligated to take the time to understand what your command does.
I understand that -n tells rename to show what would be done but not to do it. - and that s means to substitute the second expression .mp4 for the first. - and the * means to match any file - that is to process all flies in the directory However, the $ as me stumped. I understand that $ in a regular expression matches the (right hand) end of a string. In the example at hand I wish to concatenate .mp4 to the end of the file name, not replace the last character or characters with .mp4. Well wait a minute. I reread the description of $. Since it matches the position at the end of the string - now that makes sense. The command is replacing the nothingness following the file name with .mp4 - exactly what I wished to do. These simple things always trip me up - but give me something more complex like moving 80k engineering design documents for a nuclear power plant from one server to another while changing the file names and directory structure to comply with a new document management system convention and at the same time providing traceability of where the old files went and where the new files came from... a piece of cake. (Windows servers but what can I say - that is where the data was). dump a "dir /s" to a text file load the text file into a data table in Visual FoxPro a little programming to generate the new path and file name and populate "new" fields in the table write a few SQL commands to generate shell scripts to - create an md5 digest of each original file in its original location and echo to a text file - create the new directory structure on the receiving server - copy the files to the new server and rename them on the fly dumped dir /s on the new server to a text file loaded that text file into the database a little more sql to generate a script to generate the md5 digest of all files on the new server loaded the before and after md5 data into tables, joined them and produced a report showing the old file name and location, old md5, matching new md5, new file name and location The clients were amazed, I was bored. But let me come across something a simple as the situation we have been discussing and... Thanks again, Ken |
All times are GMT -5. The time now is 03:32 AM. |