Home » Questions » Computers [ Ask a new question ]

How to move only files in Unix

How to move only files in Unix

How can I move only the plain files (not the directories) from one folder in Linux to another folder using the mv command?

Asked by: Guest | Views: 289
Total answers/comments: 2
bert [Entry]

"@Mereghost is very close. Here's what I get to move all files (including hidden files), but not directories:

find . -maxdepth 1 -type f -name '*' -exec mv -n {} /destination_path \;

The . after find assumes you current directory is the source of the files you want to move. If not, the command can be revised, as follows:

find /source_path -maxdepth 1 -type f -name '*' -exec mv -n {} /dest_path \;

If you want to move only regular files and not hidden files:

find . -maxdepth 1 -type f -name '[!.]*' -exec mv -n {} /dest_path \;

If you want to move only hidden files and not regular files:

find . -maxdepth 1 -type f -name '.*' -exec mv -n {} /dest_path \;"
bert [Entry]

mv `find ./sourcedir/* -type f` ./destdir
mv `find ./sourcedir/* -type f` ./destdir