Move files older than 30 days in current folder to

find . -mtime +30 -exec mv {} old/ \;
Use find's built-in "exec" option to avoid having to do any weirdness with quoting.

By: minnmass
2014-02-09 23:05:41

1 Alternatives + Submit Alt

What Others Think

Useful, but there's a few problems with the command as it is. The 'old' directory can't be a subdirectory of the current directory, or find will get upset. The command doesn't do the right thing with directories, so you need to add "-type f" to find. Also, if you have any duplicate filenames they'll get trampled, so you might want to change mv to mv --backup=numbered
flatcap · 408 weeks and 1 day ago
i eschew : find ... -exec stuff , preferring file ... | xargs stuff why? have you ever counted the questions from people wondering why the -exec didn't work? "i didn't see my '..' files". duh? why not first run the find and inspect the files you'll see. so for this sort of thing: $ find . -mtime +30 -type f | cpio -pdluvm $(needir ../old)| xargs rm -f where: $ needir () { [[ -d $1 ]] || mkdir -p $1; echo $1; }
applemcg · 406 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: