I have a folder with several files that I want to move to a subfolder:
mkdir subfolder
mv ./* subfolder
But when I do this, I get:
mv: cannot move 'subfolder' to a subdirectory of itself
How can I simply avoid this?
Using extglob
you can do this:
shopt -s extglob
mv !(subfolder) subfolder
Glob expression !(subfolder)
will match everything except subfolder
.
Was this on Windows Subsystem for Linux (WSL)?
If so, Windows recognizes the directory Jerry as equal to directory jerry, and WSL follows certain Windows rules for compatibility.
If you want to rename the directory Jerry to jerry, you could do the following:
mv Jerry placeholder_name
mv placeholder_name jerry
There is an easy solution
mv * subfolder | mkdir subfolder
It will move all the files from the folder to the subfolder without any errors.
Umm I had a similar problem. Took me a couple of tries! But I ended up with
mkdir ../subfolder
mv * ../subfolder
mv ../subfolder .
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