Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

remove files and directories with acces time older than a given date

Terminal - remove files and directories with acces time older than a given date
find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ;
2009-11-20 16:31:58
User: angleto
Functions: awk find rm xargs
-2
remove files and directories with acces time older than a given date

remove files with access time older than a given date.

If you want to remove files with a given modification time replace %A@ with %T@. Use %C@ for the modification time.

The time is expressed in epoc but is easy to use any other ordered format.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
touch -t "YYYYMMDDhhmm.ss" ~/.ts ; find . -newer ~/.ts
2010-10-26 19:45:32
User: poffey21
Functions: find touch
4

This is great for looking for files that have been updated recently. Logs especially or monitoring what files were added during an install.

touch -t "YYYYMMDDhhmm.ss" dummy ; find . -anewer dummy
2009-11-21 04:05:45
Functions: find touch
2

touch a dummy file with the specified date, then use find with -anewer .

find -amin +[n] -delete
2009-11-20 17:15:28
User: TeacherTiger
Functions: find
-2

Deletes files older than "n" minutes ago. Note the plus sign before the n is important and means "greater than n". This is more precise than atime, since atime is specified in units of days. NOTE that you can use amin/atime, mmin/mtime, and cmin/ctime for access, modification, and change times, respectively. Also, using -delete is faster than piping to xargs, since no piping is needed.

Know a better way?

If you can do better, submit your command here.

What others think

find -atime -delete

Comment by TeacherTiger 249 weeks and 3 days ago

@TeacherTiger

is not the same, atime allow to specify a delta expressed in days

The command I wrote allow to specify an exact date and time.

Comment by angleto 249 weeks and 3 days ago

Then you can use "find -amin -n -delete", where n is the number of minutes in the past that the file was accessed. Note the minus sign before n is important (meaning "for less than n"). It's still not down to the second level, but usually you don't care about that, and this is *much* shorter and simpler.

Comment by TeacherTiger 249 weeks and 3 days ago

again, the options -amin, -atime, -mtime, -mmin ... etc. allows only to specify a delta, you can ever calculate the delta, but with the command I wrote you don't need to do it.

For instance, if you want delete the files with access time older than 2009 10 21, you don't need to calculate how much is the delta between the access time of the files and the time of command execution.

Comment by angleto 249 weeks and 3 days ago

Hi angleto,

I think your command is exactly whar I have been looking for. But unfortunately it is giving me an error on AIX find: 0652-017 -printf is not a valid option. Any suggestion?

Thanks

Comment by rubenryhan 240 weeks and 5 days ago

Hi rubenryhan,

try to replace:

find -printf '%p : %A@\n' | ...

with:

find | xargs stat -c '%n : %Y' | ...

Comment by angleto 239 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts