Score:1

Move files with specific number of characters in the extension

ke flag

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.

Someone avatar
my flag
`.jpeg` extension does not exist. Generally, the extension is `jpg`.
Score:4
cn flag
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/ {} + 
waltinator avatar
it flag
@Rizwind Since Questioner didn't say whether there were a few files, many files, or millions of files, the alternative form might be better `mv -t .. *.mp3 *.zip`. Although, for millions of files, `find` piped to `xargs`, and the `mv -t /destination` is da bomb.
waltinator avatar
it flag
I use `echo mv ...` for testing. It lets me see the exact command, and if I like the looks, a simple `^echo ^^` runs the `mv`.
cn flag
@waltinator I totally agree :D but the question was too simple for a find+xargs :D Added ;)
waltinator avatar
it flag
@Rizwind `-maxdepth 1` should be close to the directory, before the `-iname '*.mp3'`, and you should use single quotes to avoid the wildcard from matching files in the current directory..
ke flag
@Rizwind Thanks! :D mv *.??+ /destination was exactly whati was looking for.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.