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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged date from sorted by
Terminal - Commands tagged date - 102 results
read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done
2010-12-02 22:04:49
User: __
Functions: echo fold read

Like 7171, but fixed typo, uses fewer variables, and even more cryptic!

read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";done
for a in $(date +"%H%M"|cut -b1,2,3,4 --output-delimiter=" ");do case "$a" in 0)echo "....";;1)echo "...*";;2)echo "..*.";;3)echo "..**";;4)echo ".*..";;5)echo ".*.*";;6)echo ".**.";;7)echo ".***";;8)echo "*...";;9)echo "*..*";;esac;done
tail -f file |xargs -IX printf "$(date -u)\t%s\n" X
echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=' ') f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"
2010-11-24 23:49:21
User: unefunge
Functions: echo printf tr xargs

displays current time in "binary clock" format

(loosely) inspired by: http://www.thinkgeek.com/homeoffice/lights/59e0/



.... - 1st hour digit: 0

*..* - 2nd hour digit: 9 (8+1)

.*.. - 1st minutes digit: 4

*..* - 2nd minutes digit: 9 (8+1)

Prompt-command version:

PROMPT_COMMAND='echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=" ") f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"'

tail -f file | while read line; do printf "$(date -u '+%F %T%z')\t$line\n"; done
2010-11-24 05:50:12
User: derekschrock
Functions: file printf read tail
Tags: tail date

Should be a bit more portable since echo -e/n and date's -Ins are not.

tail -f file | while read line; do echo -n $(date -u -Ins); echo -e "\t$line"; done
2010-11-19 10:01:57
User: hfs
Functions: date echo file read tail
Tags: tail date

This is useful when watching a log file that does not contain timestamps itself.

If the file already has content when starting the command, the first lines will have the "wrong" timestamp when the command was started and not when the lines were originally written.

find . -type f | while read line; do NEW_TS=`date -d@$((\`stat -c '%Y' $line\` + <seconds> )) '+%Y%m%d%H%M.%S'`; touch -t $NEW_TS ${line}; done
2010-11-18 14:03:32
User: angleto
Functions: find read touch

Increase the modification date for the files selected with the find command.

echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
2010-09-23 09:50:13
User: jyro
Functions: echo
Tags: date

Saves all the "cut" hacks

LASTMONTHNUM=`date -d "last month" +%m`
LASTMONTH=`date -d "last month" +%B`
package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1)
2010-09-20 18:10:19
User: pipeliner
Functions: cat echo exit read stat
Tags: apt dpkg date stat

This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there.

It could be wrong on noatime partitions.

Here is non-oneliner:




inst=$(stat "$list" -c %X);

cat $list |


while read file; do

if [ -f "$file" ]; then

acc=$(stat "$file" -c %X);

if [ $inst -lt $acc ]; then

echo used $file

exit 0




exit 1


date --date=yesterday +%Y%m%d
2010-09-08 12:29:31
User: vinayv
Functions: date
Tags: bash date

The "date' command has options to easily format the date, day, month, time, etc. But what if you want a relative date or time. Like, I wanted yesterday's date in a particular format. You may want the exact date of "2 months ago" or "-3 days" nicely formatted. For that, you can use this command. The --date option takes fuzzy parameters like the ones mentioned in the previous sentence.

truss date 2>&1 | awk '/^time/{print $3}'
echo "($(date +%s)-$(date +%s -d "march 1"))/86400"|bc
2010-07-22 19:44:50
User: nickwe
Functions: echo
Tags: echo bc date

Exactly the same number of characters, exactly the same results, but with bc

TZ=PST8PDT+72 date '+%Y_%m_%d'
2010-07-02 00:29:27
Functions: date
Tags: date nongnu

This command prints the Date (Not time) from 3 days ago (72 hours ago).

This works on systems without GNU date (MacOSX , Solaris, FreeBSD).

sudo find . -maxdepth 1 -cnewer olderFilesNameToMove -and ! -cnewer newerFileNameToMove -exec mv -v {} /newDirectory/ \;
2010-06-30 20:40:30
User: javamaniac
Functions: find mv sudo

In a folder with many files and folders, you want to move all files where the date is >= the file olderFilesNameToMove and

watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
2010-06-26 11:56:11
User: prayer
Functions: date expr watch
Tags: date time

Change HH:MM with your target time.

This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with:

# apt-get install bash coreutils toilet toilet-fonts

touch file-$(date +%Y%m%d)
grep -i "$(date +%b\ %d\ %H)" syslog
2010-05-23 16:18:15
User: rubenmoran
Functions: grep
Tags: log date

Uses date to grep de logfile for today and uses it to get the last hour logs. Can be used to get last minute logs or today's logs.

utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
utime(){ date -d "1970-01-01 GMT $1 seconds"; }
utime { date -d @$1; }
2010-05-12 12:21:15
User: deltaray
Functions: date

More recent versions of the date command finally have the ability to decode the unix epoch time into a human readable date. This function makes it simple to utilize this feature quickly.

alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'

If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command.

# creating a date-based ssh-key for askapache.github.com

ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C [email protected]' # [email protected]

# create a tar+gzip backup of the current directory

tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) . # tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz .

I personally find myself having to reference

date --help

quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner.

Here's the old version:

alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t'

This trick from my [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ]