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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With