Search code examples
directorycommand-line-interfacemovepwd

move many directories to another directory using CLI


I want to copy some of the directories in a directory to another directory in that directory itself.

For Example:

I have the structure like the below

myname@compname:~/root/app/pages$ ls

dir1, dir2, dir3

I want the dir1 and dir2 to be moved into dir3 and the final structure has to be as the following:

myname@compname:~/root/app/pages$ ls

dir3

myname@compname:~/root/app/pages/dir3$ ls

dir1, dir2

I know the there are many shell programs for it. but I want this to happen using the CLI itself in just a single lined statement.


Solution

  • mv dir1 dir2 dir3
    

    will do it

    mv dir1 dir2
    mv dir2 dir3
    

    does the same thing, in two steps.

    Technically mv dir[123] would also do the same thing (for these file names), but would potentially be confusing as the destination is determined alphabetically