Say I have a directory that contains the following:
dir1/
dir2/
dir3/
...
dir50/
dir1.txt
dir2.txt
dir3.txt
...
dir50.txt
I have been using mv dir* /someotherpath/, then move the *.txt files back. Is there a way to move only the directories?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communitySay I have a directory that contains the following:
dir1/
dir2/
dir3/
...
dir50/
dir1.txt
dir2.txt
dir3.txt
...
dir50.txt
I have been using mv dir* /someotherpath/, then move the *.txt files back. Is there a way to move only the directories?
If your directory structure is only 1 level deep mv dir*/ destination
will accomplish this task.
You can also use find
to accomplish this task
find . -maxdepth 1 -type d -name "dir*" -exec mv '{}' destination/ \;
Change maxdepth
parameter or remove it if you directory structure has more levels
With a file structure like this:
/dir2move2
/dir
/subdir1
/subdir2
index.js
To move only the sub directories and not the files you could just do:
mv ./dir/*/ ./dir2move2