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).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s