Issue
On Ubuntu i have run this command.
sha1sum /home/abcd/random/1/1.mp4
So I have the following directory
/home/abcd/
Inside this folder are sub folders
/home/abcd/1
/home/abcd/2
etc
etc
These sub folders are filled with video files .mp4
extensions
They have multiple files with a file hash of sha1sum
of 3c72363260a32992c3ab2e3a5e9b8cf082e02eac
i wanted to rename all the files NOT matching this file to
vid_1.mp4
vid_2.mp4
etc
etc
How can I achieve this?
Solution
You can try this for
loop with a nested if
loop
for f in /home/abcd/*; do
i=$((i+1));
sum=$(sha1sum "$f" | awk '{print $1}');
if [[ "$sum" != 3c72363260a32992c3ab2e3a5e9b8cf082e02eac ]]; then
mv "$f" "vid_$i.mp4";
fi;
done
Answered By - HatLess Answer Checked By - Cary Denson (WPSolving Admin)