Wednesday, September 30, 2015

Move only subfolders or only files to another location using bash script

If you want to move only subfolders from your folder to another locations the following bash code

for x in *; do
        if [ -d "$x" ]; then
        echo "$x"
        mv -- "$x" /path/to/folder/
        fi
done

If you want to move files and not subfolders to another location use:
for x in *; do
        if ! [ -d "$x" ]; then
        echo "$x"
        mv -- "$x" /path/to/folder/
        fi
done


No comments:

Post a Comment