2
What I am currently looking to do is rename all files in a folder, where there are also other files of different format. See Example:
FOLDER - BEFORE
1.txt 2.txt 3.txt Daniela.jpg Amanda.jpg Lucia.jpg
What I’m not getting is exactly creating a bond for
commanding sed
and/or mv
so that, I can achieve the goal.
FOLDER - AFTER
Daniela.txt Amanda.txt Lucia.txt Daniela.jpg Amanda.jpg Lucia.jpg
Even if it seems strange to those who read, keep in mind that I want copy the names remaining the 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 an idea formulated in the mind of what is necessary to help the question. I make it clear here a step-by-step so that you can recreate my desktop environment on your MAC system; Minix; Openbsd; Freebsd or GNU/Linux. Let us 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 example script. Give common execution permission:
$ sudo chmod +x <script.sh>
Now, just run the tests to see what comes.
I have no command rename
in 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 rotates in Bourne shell instead of Bash. Nothing against, it’s only for portability.
I don’t understand your doubt, you want to change the name of all files regardless of format? Or you want to rename a particular file type based on another file type?
– Alessandro Schneider
We have a problem, all 01 will be renamed Daniela, 02 to Amanda and 03 to Lucia? If not, first we have to have a DE-PARA stating that such a filename will go to another filename. We have to have a filename pattern.
– Diego
@Alessandroschneider You understood yes! That’s exactly what you said in your comment - [...]rename a particular file type based on another file type.
– Diego Henrique