What I am currently looking to do is rename all files in a folder, where there are also other files of different format. See the example:
PASTA - BEFORE
1.txt 2.txt 3.txt Daniela.jpg Amanda.jpg Lucia.jpg
What I can not do is exactly create a loop for
with command sed
and / or mv
so that I can reach the goal.
PASTA - AFTER
Daniela.txt Amanda.txt Lucia.txt Daniela.jpg Amanda.jpg Lucia.jpg
Even though it may seem strange to anyone who reads, keep in mind that I want to copy the names and remain extension .
Example of what I tried:
cd /home/$USER/pasta/
QUANTIDADE='ls *.jpg | wc -l'
LISTA='ls *.txt'
for ARQUIVO in 'seq $QUANTIDADE'
do
mv "$ARQUIVO" "$LISTA"
done
cd ..
Instructions - For those who wish to have a thought-out idea of what is needed to help with the issue. Here is a step-by-step guide for you to recreate in your MAC system; Minix; OpenBSD; FreeBSD or GNU / Linux my work environment. To know:
1 - Create a directory named "folder" in your home directory / home / user:
$ mkdir pasta
2 - Populate the previously created folder with dummy files:
$ touch 1.txt 2.txt 3.txt /home/$USER/pasta/
$ touch Daniela.jpg Amanda.jpg Lucia.jpg /home/$USER/pasta/
3 - Finally, copy the sample script. Give common execution permission:
$ sudo chmod +x <script.sh>
Now, just perform the tests to see what you give.
I do not have rename
command on my system so please anyone who wants to help me by answering the question, do not elaborate with this tool.
Another detail is that, I prefer to use syntax that runs in Bourne shell instead of Bash . Nothing against it, it's just for portability.