skip to Main Content

How to use mv command exclude directory

How To Use Mv Command Exclude Directory

The mv (short from move) is a Unix command that use to rename and move files and directories from one place to another. The syntax of the mv command is as follow :

mv [OPTIONS] SOURCE DESTINATION

Let’s assume we have the directory structure like below:

|parent
    |--dir1
    |--dir2
    |--dir3
    |--file1
    |--fiel2
    |--file3
    |--file4
    |--file5

And we want to move all files and directories to directory dir1, so that it would appear like,

|parent
    |--dir1
    |   |--dir3
    |   |--file1
    |   |--file2
    |   |--file3
    |   |--file4
    |   |--file5
    |--dir2

In this case, you need to exclude two directories dir1 and dir2, and move rest of the files and directories into dir1 directory. So we need to use command like below :

mv *[^dir1dir2]* dir1

This will move all of rest of the directories into dir1 directory.

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top
Search