One approach could be to use grep in combination with xargs:
ls -A | egrep -v sonDir | xargs -i mv {} sonDir
- first list all files and folders in the current directory (ie. fatherDir) with
ls
- make sure to read out hidden files as well with the
-A
flag
egrep -v
lets you exclude sonDir of the printed output
- create command line from standard input with
xargs
and replace {}
with regarding filename. Option -i
is required here!
That's it! I use this approach rather frequently since it lets you exclude not only a folder, but different folders and files at the same time. In case you want to exclude e.g. sonDir
daughterDir
and nephew.file
you can do so by simply specifying egrep -v '(sonDir|daughterDir|nephew.file)'
, the rest of above shown command stays the same... and there is lots of variations!