[UPDATE-1]: If possible, give me cons for motivation to learn the simplest commands.
So, I have one file in directory:
ls | grep *.mp4
video.mp4
I use this command to randomly rename & move file in another directory:
for a in *.mp4; do mv -n "$a" "${a/*/$RANDOM.mp4}"; done; mv *.mp4 /home/misdeed/Documents
Is ok, I get randomly name for video.mp4
cd Documents; ls | grep *.mp4
19889.mp4
Qestion:
How to use is:
a="This is name file"
echo $a
This is name file
for rename *.mp4 (not randomly) and for get
This is name file.mp4
I need something like it:
a="This is name file"
COMMAND FOR RENAME BUT WITHOUT $RANDOM. I WANT USE $a in renamed file
mv something.mp4 "$a".mp4
? Is the problem you don't know in advance whatsomething
is? In that case what if there are two files matching*.mp4
? Is the premise there's always exactly one such file?ttyrec
->ttyrec2gif
->ffmpeg -i tty.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
mv *.mp4 "$a".mp4; mv *.mp4 /home/misdeed/Documents; cd Documents; ls | grep *.mp4
. Thank you very much!video.mp4
, right? Thenmv video.mp4 "$a".mp4
. I'm confused and maybe not getting this right. You started with relatively complex code that involves random names and iterating over files, but in the end the question is "how to rename a file with a known name to a new name which is stored in a variable?" So basicmv
and shell variable usage. If the variable is available whenffmpeg
runs, you can pass"$a".mp4
instead ofvideo.mp4
in the first place.*.mp4
! It only works because you have just one matching file. Franklyls | grep *.mp4
is very wrong but it only affects what you see. If you ask a new question "what is wrong withls | grep *.mp4
?" you will learn a lot.