Move files with specific number of characters in the extension

How do I move all files that only have three characters in the extension to the parent directory?

E.g. I want to move all the .mp3 and .zip but not all the .sh to the parent directory.

1

1 Answer

mv *.mp3 *.zip /destination/

if you really meant 3 characters:

mv *.??? /destination

but this will also do .xml or .mov or .mp4.

Tip: you can use ls to see what files are shown that will be moved when using mv

If you want to move large numbers of files use...

find . -maxdepth 1 -iname '*.mp3' -exec mv -t /destination/ {} + 
5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like