[SOLVED] I can't figure out how to use mv :( lol

About writing shell scripts and making the most of your shell
Forum rules
Before you post please read how to get help
Aztaroth
Level 3
Level 3
Posts: 168
Joined: Mon Jan 11, 2021 1:48 am

Re: [SOLVED] I can't figure out how to use mv :( lol

Post by Aztaroth »

Hello,
Going a bit further :
- About ls, you can also redirect the output to a file. For example,

Code: Select all

ls -R > MyList.txt
will put the result of ls -R in MyList.txt instead of putting it on screen.

- About mv and renaming files,

Code: Select all

i=1; for file in *.mp3; do echo mv "$file" "Song $i".mp3; i=$((i+1)); done
will simulate the renaming of all the mp3 files of a directory to Song 1, Song 2, Song 3, a.s.o
I used the term simulate because the code contains the command echo which puts the result on the screen without doing the job (in case the result is not the one expected). The same line without echo will perform the task.
As long as you keep echo in the command, feel free to test anything. Of course, be careful when not using echo.
Post Reply