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 -- * "$tmp"/other_directory/
mv "$tmp"/* .
rmdir "$tmp"
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/ {} +
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 include 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
mv **/*(.) ./other_directory
- with bash you'd need to resort to external commands likefind
, though. – godlygeek Jul 29 '14 at 18:47