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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using touch from sorted by
Terminal - Commands using touch - 49 results
for file in $( git ls-files ); do echo $file; touch -t $(git --no-pager log --date=local -1 --format="%ct" $file | php -r 'echo @date( "YmdHi.s", trim( file_get_contents( "php://stdin" ) ) );') $file; done
touch -t 197001010000 ./tmp && find . -newer ./tmp && rm -f ./tmp
2014-11-18 00:29:26
User: sergeylukin
Functions: find rm touch

Sometimes you just want to operate on files that were created after specific date. This command consists of 3 commands:

- Create a dummy file with the custom date

- Find all files with "creation time" further than our custom date by using `-newer` find option. Add your crazy stuff here, like moving, deleting, printing, etc.

- Remove the dummy file

touch -r "source_file" "destination_file"
tstouch() { [[ $1 =~ $2 ]] && touch -t ${BASH_REMATCH[1]} $1; }
2013-10-01 20:00:34
User: bartonski
Functions: touch
Tags: bash touch

tstouch takes two arguments: a filename containing a timestamp, and an extended regular expression with the parenthesized section matching a timestamp of the form YYYYMMDDhhmm or YYYYMMDDhhmm.ss.

It then touches the file with that timestamp.

echo "template file: ";read tpl;echo "new file(s separated w. space):"; read fl;touch $fl;find $fl -exec cp -ap $tpl "{}" \;
2013-03-08 10:00:36
User: knoppix5
Functions: cp echo find read touch

make a bunch of files with the same permissions, owner, group, and content as a template file

(handy if you have much to do w. .php, .html files or alike)

touch file{1..10}.txt ; ls *txt| sed -e "p;s/\.txt$/\.csv/"|xargs -n2 mv
touch ~/.hushlogin
2012-12-05 18:03:41
User: elofland
Functions: touch
Tags: login motd

I'm annoyed by the boilerplate "don't login unless you are supposed messages in our environment" - this shuts them up.

edit-notime () { FILE=$1; TMP=`mktemp /tmp/file-XXXXXX`; cp -p $FILE $TMP; $EDITOR $TMP; touch -r $FILE $TMP; cp -p $TMP $FILE; rm -f $TMP; }
2012-10-31 00:54:19
User: jecxjoopenid
Functions: cp rm touch

Copies file to a temporary location, edit and set to real file's time stamp then copy back. Assumes access to /tmp and has $EDITOR, but can be replaced with better values.

touch filename
touch -t 201208211200 first ; touch -t 201208220100 last ; find /path/to/files/ -newer first ! -newer last | xargs -ifile mv -fv file /path/to/destination/ ; rm first; rm last;
2012-08-22 09:51:40
User: ktopaz
Functions: file find last mv rm touch xargs

touch -t 201208211200 first ; touch -t 201208220100 last ;

creates 2 files: first & last, with timestamps that the find command should look between:

201208211200 = 2012-08-21 12:00

201208220100 = 2012-08-22 01:00

then we run find command with "-newer" switch, that finds by comparing timestamp against a reference file:

find /path/to/files/ -newer first ! -newer last

meaning: find any files in /path/to/files that are newer than file "first" and not newer than file "last"

pipe the output of this find command through xargs to a move command:

| xargs -ifile mv -fv file /path/to/destination/

and finally, remove the reference files we created for this operation:

rm first; rm last;

cd / && touch ./\-i
2012-04-05 20:55:37
User: joedhon
Functions: cd touch

Somehow, i prefer forcing to rm interactively to accidently rm'ing everything...

find . -newer /tmp/foo -exec touch --date "2011-12-12" {} \;
2011-12-15 04:55:57
User: djangofan
Functions: find touch

Modify all files newer than another file and touch them to a specific date.

touch -d $(zenity --calendar --date-format=%F) filename
function right { bc <<< "obase=8;ibase=2;$1"; }; touch foo; chmod $(right 111111011) foo; ls -l foo
2011-11-16 22:43:31
User: nerd
Functions: bc chmod ls touch

I simply find binary notation more straightforward to use than octal in this case.

Obviously it is overkill if you just 600 or 700 all of your files...

touch --date "2010-01-05" /tmp/filename
for i in /usr/bin/* ;do touch ${i##*/}; done
2011-10-20 12:38:45
User: _john
Functions: touch
Tags: bash find xargs zsh

You could avoid xargs and sed in this case (shorter command and less forking): At least bash and zsh have some mighty string modifiers.

I would also suggest using find with exec option to get more flexibility. You may leave out or include "special" file for example.

touch -t [[CC]AA]MMJJhhmm[.ss]
for i in `seq 100`; do mkdir f${i}; touch ./f${i}/myfile$i ;done
2011-09-29 01:03:46
Functions: mkdir touch
Tags: seq mkdir touch

creates 100 directories f(1-100) with a file in each matched to the directory (/f1/myfile1, .. /f98/myfile98,/f99/myfile99/,/f100/myfile100,etc )

switchMonitor () { LF=/tmp/screen-lock; if [ -f $LF ]; then rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi };
2011-08-26 17:55:44
User: totti
Functions: rm sleep touch

Use the command to create a script and bind it to a key using keyboard shortcut.


Script locks the screen in a loop until the command is executed again.At first it

find . -type f -exec touch "{}" \;
touch -t 201001010000 begin; touch -t 201012312359.59 end; find . -newer begin -a ! -newer end
2011-06-22 20:09:05
Functions: find touch
Tags: find dates touch

Example above will recursively find files in current directory created/modified in 2010.

touch file{1,2,3,4,5}.sh
cd <directory>; touch ./-i
2011-05-12 11:01:58
User: ljmhk
Functions: cd touch
Tags: touch

Forces the -i flag on the rm command when using a wildcard delete.

touch pk.pem && chmod 600 pk.pem && openssl genrsa -out pk.pem 2048 && openssl req -new -batch -key pk.pem | openssl x509 -req -days 365 -signkey pk.pem -out cert.pem
2011-05-11 18:09:33
User: bfreis
Functions: chmod touch

This will create, in the current directory, a file called 'pk.pem' containing an unencrypted 2048-bit RSA private key and a file called 'cert.pem' containing a certificate signed by 'pk.pem'. The private key file will have mode 600.

!!ATTENTION!! ==> this command will overwrite both files if present.

find . -exec touch {} \;