All commands (14,187)

What's this?

commandlinefu.com 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


Check These Out

Automaticly cd into directory
Makes bash-4.x like zsh. Automatic cd into a directory if a command with that name doesnt exists. Ready for your ~/.bashrc file

Mac Sleep Timer
Schedule your Mac to sleep at any future time. Also wake, poweron, shutdown, wakeorpoweron. Or repeating with $ sudo pmset repeat wakeorpoweron MTWRFSU 7:00:00 Query with $ pmset -g sched Lots more at http://www.macenterprise.org/articles/powermanagementandschedulingviathecommandline

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Sort files by size

A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram

Display email addresses that have been sent to by a postfix server since the last mail log rollover
This assumes your mail log is /var/log/mail.log

Get the time from NIST.GOV
The format is JJJJJ YR-MO-DA HH:MM:SS TT L DUT1 msADV UTC(NIST) OTM and is explained more fully here: http://tf.nist.gov/service/acts.htm

Get absolut path to your bash-script
Another way of doing it that's a bit clearer. I'm a fan of readable code.

To print a specific line from a file
Just one character longer than the sed version ('FNR==5' versus -n 5p). On my system, without using "exit" or "q", the awk version is over four times faster on a ~900K file using the following timing comparison: $ testfile="testfile"; for cmd in "awk 'FNR==20'" "sed -n '20p'"; do echo; echo $cmd; eval "$cmd $testfile"; for i in {1..3}; do time for j in {1..100}; do eval "$cmd $testfile" >/dev/null; done; done; done Adding "exit" or "q" made the difference between awk and sed negligible and produced a four-fold improvement over the awk timing without the "exit". For long files, an exit can speed things up: $ awk 'FNR==5{print;exit}'

Search for a string inside all files in the current directory
shorter typing with no need to use xargs.


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: