$ mkdir backup && mv * backup/
mv: cannot move `backup' to a subdirectory of itself, `backup/backup'

Works, but issues a warning. Also exit code is 1.

How to do it properly (but not [much] longer)?

up vote 7 down vote accepted


shopt -s extglob
mkdir backup && mv !(backup) backup

Also bash, and sh (afaik):

$ mkdir .backup && mv * .backup/ && mv .backup backup

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.