Move every file that is not a directory

Regex aren't involved here. Wildcards in bash (like most other shells) only match files based on the file names, not based on the file type or other characteristics. There is one way to match by type: adding / at the end of the pattern makes it only match directories or symbolic links to directories. This way, you can move directories, then move what's left, and move directories back — cumbersome but it works.

tmp=$(TMPDIR=.. mktemp -d)
mv -- */ "$tmp"
mv -- * other_directory/
mv "$tmp"/* .
rmdir "$tmp"

(that approach should be avoided if the current directory is the mount point of a filesystem, as that would mean the moving of directories away and back would have to copy all the data in there twice).

A standard way to match files by type is to call find.

find . -name . -o -type d -prune -o -exec sh -c 'mv "$@" "$0"' other_directory/ {} +

(also moves symlinks, whether they point to directories or not).

In zsh, you can use glob qualifiers to match files by type. The . qualifier matches regular files; use ^/ to match all non-directories, or -^/ to also exclude symbolic links to directories.

mv -- *(.) other_directory/

In any shell, you can simply loop.

for x in *; do
   if ! [ -d "$x" ]; then
     mv -- "$x" other_directory/
   fi
done

(does not move symlinks to directories).


You could use something like

find . -maxdepth 1 \( ! -type d \) -exec sh -c 'mv  "$@" MYDIR' _ {} \;

First we use find to look only within the current directoy, then we ignore directories by using ! -type d finally we execute sh and move everything to the destination dir. You might try {} + at the end which will be faster.


It's potentially a bit dangerous but

cp * destination/
rm *

As both cp and rm won't operate on directories without the -r switch.