easy script question
so i have a bunch of mp3s in this folder but none of them have *.mp3 at the end of them
there just the name of the file what kinda script or command should i use to attach .mp3 to all the files in this dir? |
You could write a script but what is the point . Just enter the following it a bash shell.
bash$ for i in `ls`; do mv $i $i.mp3; done |
In case you never seen in before the ` in the ls command... are backward quotes (shift + ~). Needed to tell the bash interpreter that ls is a command.
|
Oh if you really want to get technical that previous loop added an environment variable i to your current bash shell. If you want to get rid of it without exiting and loging back in then
$ unset i So to have the command run with cleanup bash$ for i in `ls`; do mv $i $i.mp3; done; unset i |
bash$ for i in `ls`; do mv $i $i.mp3; done; unset i
-bash: syntax error near unexpected token `do' |
Hi,
I don't know why you get that syntax error. The command worked for me though.I just copied it from here and pasted it in a terminal pressed the enter key and it worked without any syntax error. You probable entered it in a wrong way.Check the syntax of the command you entered. However the command given above is an inefficient one : Code:
Suppose you have the following case : Code:
[root@localhost tmp]# for i in `ls`; do mv $i $i.mp3; done; unset i Avril Lavigne - Knockin On Heavens Door i takes up values as : "Avril" then "Lavigne" then "-" then "knockin" and so on........................... With the end result being that only the files with filenames having no spaces in between end up being renamed, rest all remain the same A more efficient example could be : Code:
[root@localhost tmp]# ls Hope that helps |
Ah yes, I never took into account that there could be spaces in the file name. I never put spaces in file names in linux, as it is annoying to escape the spaces in the shell. But I guess someone could download a file with spaces in it.
|
Same here i also don't like those spaces. Coz every time either you have to escape them with a backslash or enclose the entire filename in quotes.
-------neways -------ciao |
All times are GMT -5. The time now is 05:07 AM. |