The simple way, if there's a single level of subdirectories:
cd source_directory
mv -- */* /path/to/target/directory
If you want to move the files to the parent directory, that's mv -- */* .
. Note that files or directories whose name begins with .
(“dot files”) are excluded. To include them, in bash, run shopt -s dotglob
first. In zsh, run setopt glob_dots
first.
If you want to move files from subsubdirectories and so on recursively as well, with zsh
:
cd source_directory
mv -- */**/*(^/) .
If you try to run the mv
command and get an error like “command line too long”, you'll have to break it down. The simplest way is to use find
. With GNU tools (non-embedded Linux and Cygwin):
find source_directory -mindepth 2 ! -type d \
-exec mv -t /path/to/target/directory -- {} +