Move command

Solved
Poireau007 Posted messages 85 Status Membre -  
debianhunter Posted messages 119 Registration date   Status Membre Last intervention   -
Hello everyone!

I want to move a certain number of files using mv, but I'm stuck...

What I have:
I have lots of folders in the same directory, each containing one file named xxx.html

What I want to do:
move all the xxx.html files to the same location

----
What I've done:
for i in $(ls); do cd $i | mv * /../Users/Ordi/Desktop/Dossier/; done

But it doesn't work, I feel like the pipe is not being interpreted...
Any suggestions?

Thanks.

Configuration: Ibook ^^

1 réponse

debianhunter Posted messages 119 Registration date   Status Membre Last intervention   24
 
Good evening,

Look at the find command, it will be easier:

find . -iname '*html' -exec mv {} . \;


Good luck!
2
Poireau007 Posted messages 85 Status Membre 15
 
Thank you Debian, it works!
Your command is really minimalist compared to mine!
Well, I just have to read the man page of find to try to understand what you did,
I don't quite understand how you move files from one folder to another...

Thanks again!
0
debianhunter Posted messages 119 Registration date   Status Membre Last intervention   24
 
You're welcome ;o)

find will list all the files from the current directory (.) whose name matches the regular expression *html ignoring case (if you don't want that, use name instead of iname) and then executes the command mv {} . which moves (mv) each of the find results ({}) to the current directory (.)

But reading the man page will show you the incredible possibilities of find!
0