Move all files except one
Solution 1:
If you use bash and have the extglob
shell option set (which is usually the case):
mv ~/Linux/Old/!(Tux.png) ~/Linux/New/
Solution 2:
Put the following to your .bashrc
shopt -s extglob
It extends regexes. You can then move all files except one by
mv !(fileOne) ~/path/newFolder
Exceptions in relation to other commands
Note that, in copying directories, the forward-flash cannot be used in the name as noticed in the thread Why extglob except breaking except condition?:
cp -r !(Backups.backupdb) /home/masi/Documents/
so Backups.backupdb/
is wrong here before the negation and I would not use it neither in moving directories because of the risk of using wrongly then globs with other commands and possible other exceptions.
Solution 3:
I would go with the traditional find & xargs way:
find ~/Linux/Old -maxdepth 1 -mindepth 1 -not -name Tux.png -print0 |
xargs -0 mv -t ~/Linux/New
-maxdepth 1
makes it not search recursively. If you only care about files, you can say -type f
. -mindepth 1
makes it not include the ~/Linux/Old
path itself into the result. Works with any filenames, including with those that contain embedded newlines.
One comment notes that the mv -t
option is a probably GNU extension. For systems that don't have it
find ~/Linux/Old -maxdepth 1 -mindepth 1 -not -name Tux.png \
-exec mv '{}' ~/Linux/New \;