Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files are missing after move

Tags:

unix

I tried to move .html files into a subdirectory called 'html' and now I cannot find the files. Here is what I did (with the error message):

$ mkdir html
$ for FILE in $(ls *html) ; do mv $FILE .html ; done
mv: cannot stat 'html:': No such file or directory
$ cd html
$ ls *.html
ls: cannot access '*.html': No such file or directory

So my question: where have they disappeared?

like image 298
DeeCeeDelux Avatar asked Mar 29 '26 18:03

DeeCeeDelux


2 Answers

You have two problems; first, there is a typo:

mv $FILE .html
         ^

That . shouldn't be there! Second, your list of files will include the html directory itself, so to exclude it, try:

for FILE in *html ; do if ! [ -d "$FILE" ] ; then mv "$FILE" html ; fi ; done

Note that I use *html rather than $(ls *html) to avoid picking up the contents of the html/ directory, then do the move as long as we don't have a directory name.

like image 188
Ken Y-N Avatar answered Apr 03 '26 17:04

Ken Y-N


You have effectively moved all *html files to a file named .html. Only the last *html file will be left since every move will overwrite the previous move.

like image 29
e7andy Avatar answered Apr 03 '26 16:04

e7andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!