Answer the question
In order to leave comments, you need to log in
How to bulk rename files in a directory?
Hello everyone! I again have one of the easiest questions over which I puzzle all day. I have a task here to make a script that will rename files in a specific directory:
File1
...
File5
For example:
File1_renamed
...
File5_renamed
I know that this can be done through suffix , but the catch is that as an example I was given a simple rename files with the addition of this renamed, and you need to do just that. I thought about listing the files and renaming them like this, but I have no idea how to do it so that the changes affect the names of the files themselves in the directory, and not just as output to the console.
Answer the question
In order to leave comments, you need to log in
find /var/www/ -type f -exec mv {} {}_renamed \;
find
-recursive search from the given directory and below
/var/www
- where to look, if in the current directory, then you can replace it with .
-type f
- only files
-exec
execute with found
mv
move
{}
what is found in this case filename
\;
- just end the command.
You can check this way, instead of renaming, you will just get a print of the commands themselves.
Mark as solved, thanks cap.
find /var/www/ -type f -exec echo {} {}_renamed \;
there are many ways to rename, here are google examples Renaming files with find, sed and xargs
specifically in your case you can do this
ls -1 |awk '{print $0,$0"_renamed"}' | xargs -n2 mv
ls -1 |awk '{print "\""$0"\" \""$0"_renamed\""}' | xargs -n2 mv
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question