Results 1 to 9 of 9
Can anyone help me with a command for Linux (CentOS):
I have different directories, say:
/01
/02
/03
/04
Each directory has many different files of different extensions...
I want ...
- 01-05-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 5
Help with renaming multiple files in different subdirs...
Can anyone help me with a command for Linux (CentOS):
I have different directories, say:
/01
/02
/03
/04
Each directory has many different files of different extensions...
I want a command wich I can run from 1 directory higher, to check al these subdirs for files with extension .zip for example and add a prefix to these filenames (for example "cyberbomb_filename01.zip"). If the prefix "cyberbomb_" already exists, it should not be added...
Does anyone have a 1-line solution for me ?
Thank you very much !
p.s. I hope this is in the right board, if not, please move me
- 01-06-2010 #2Just Joined!
- Join Date
- Jan 2010
- Posts
- 5
Anyone ???
- 01-06-2010 #3Just Joined!
- Join Date
- Jul 2009
- Location
- Chicago, IL
- Posts
- 9
Please be a little more patient, your listing wasn't even off the first half of the first page when you bumped it. Doing it that soon really does you no good at all.
What are you trying do do this in? That is a fairly specific need so I can almost guarantee you that a one line solution doesn't exist for it. Without knowing the programming language you are doing this in, here is the best I can give you:
1. Input a directory
2. Find all directories for the directory directly below that one
3. Search though each of those individually.
4. Using either regular expressions or splitting the name by period (find the text after the last period), replace each files name and rename the file.
Again, I seriously doubt there is a one line solution to do this in anything.
- 01-06-2010 #4Just Joined!
- Join Date
- Jan 2010
- Posts
- 5
Hi Daniel, thanks for the reply.
This is on my CentOS server... So basicaly command-line only, unless there is a better option (which I suspect there is).
If it's not one-line, no problem, but you do understand what I'm trying to accomplish here...
- 01-06-2010 #5Just Joined!
- Join Date
- Jul 2009
- Location
- Chicago, IL
- Posts
- 9
Yes, I've been faced with this problem too. Don't get too excited though, it was on windows and I wrote a VB program for it. I've tried doing this in C and it is very hard (string still give me trouble). I would recommend making some sort of bash script for it, use Google to find yourself a guide for each step. I would first get familiar with bash, then do each step in order before integrating them together.
- 01-06-2010 #6Just Joined!
- Join Date
- Jan 2010
- Posts
- 5
I did this:
[code=bash]
for i in */*.zip; do echo "$i" "$(dirname "$i")/cyberbomb_$(basename "$i")"; done
[/code]
This is with "echo". I see what I want to do, but when I replace "echo" with "mv" I get: mv: cannot stat `*/*.zip': No such file or directory
It's like I was so close, yet, so far... Yarrr
(prefix: cyberbomb_)
- 01-06-2010 #7Just Joined!
- Join Date
- Jul 2009
- Location
- Chicago, IL
- Posts
- 9
I don't know enough about bash to help you here, you'll have to wait for someone else to find this. Just as a possibility, are you missing a slash between dirname and i?
- 01-06-2010 #8Just Joined!
- Join Date
- Jan 2010
- Posts
- 5
lol, this is what worked for me !
for i in */*.zip; do mv -i "$i" "$(dirname "$i")/cyberbomb_$(basename "$i")"; done
- 01-07-2010 #9Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Each time you run your code, it adds a cyberbomb_ prefix to any .zip file, even if it is already prefixed. I doubt you can do this with a one line code (which a for loop is not).


Reply With Quote

