I am wondering - how can I move all the files in a directory except those files in a specific directory (as 'mv' does not have a '--exclude' option)?
The mv command is used to move files and directories from one place to another. We can also use it to rename files and directories. This will move all the files from /path/subfolder to /path/ except for hidden files and directories.
Click the first file or folder you want to select. Hold down the Shift key, select the last file or folder, and then let go of the Shift key. Hold down the Ctrl key and click any other file(s) or folder(s) you would like to add to those already selected.
Use the mv command to move files and directories from one directory to another or to rename a file or directory. If you move a file or directory to a new directory without specifying a new name, it retains its original name. Attention: The mv command can overwrite many existing files unless you specify the -i flag.
Lets's assume the dir structure is like,
|parent |--child1 |--child2 |--grandChild1 |--grandChild2 |--grandChild3 |--grandChild4 |--grandChild5 |--grandChild6
And we need to move files so that it would appear like,
|parent |--child1 | |--grandChild1 | |--grandChild2 | |--grandChild3 | |--grandChild4 | |--grandChild5 | |--grandChild6 |--child2
In this case, you need to exclude two directories child1
and child2
, and move rest of the directories in to child1
directory.
use,
mv !(child1|child2) child1
This will move all of rest of the directories into child1
directory.
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