Day: April 7, 2016

Moving all files and directories to a new subdirectory with a single command

This is a nice trick I learned today thank to this post.

If you are inside a directory with many files and subdirectories and you want to move everything to a new subdirectory you don’t need to move one-by-one, you can use this trick:

$ cd ~/Download
$ ls
fileA fileB fileC
dirAA dirBB dirCC
$ mkdir Download
$ shopt -s extglob
$ mv !(Download) Download

This command will move all files and directories to a new subdirectory, except the hidden files and directories (files/dir started with .something).