I'm using this command to rename files:
for fname in *;
do
mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ')
done
But it only renames in the current directory. Let's say I have many directories, and each directory contains some other directories, and last directory tree contains files. I want to rename them with random characters.
I think find . -type f
should work, and have tried it, but still did not get any working command.
Best Answer
With find:
This invokes
SHELL COMMAND
on each found file in turn; the file name is"$0"
. Thus:(Note the use of
printf
rather thanecho
, in case you have a file called-e
or-n
or a few other problematic cases thatecho
mangles.)You can make this a little faster by invoking the shell in batches.
In zsh, there's an easy way to match all the files in the current directory and its subdirectories recursively. The
.
glob qualifier restricts the matches to regular files, andD
includes dot files.In bash ≥4, you can run
shopt -s globstar
and use**/*
to match all files in the current directory and its subdirectories recursively. You'll need to filter regular files in the loop.