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

Commands tagged logging from sorted by
Terminal - Commands tagged logging - 10 results
watch -n 4 "tail -n $(expr $(tput lines) - 4) /var/log/apache2/access.log | cut -c 1-$(tput cols)"
2013-12-03 23:45:25
User: atw527
Functions: watch
0

This bash one-liner will let you watch the tail end of a log file in real time.

logger -t MyProgramName "Whatever you're logging"
logme(){ echo "$(date +%d-%m-%Y-%H:%M) => $0 @ $1 returned error" >> persoscript.log }
2013-10-22 15:55:01
User: qcjn
Functions: echo
Tags: logging
0

Put this logging function in you're script, when need it call it.

command || logme "Error with command"

pygmentize -l pytb myapp.log | less -SR
while sleep 1; do date; (netstat -a -n | grep 80) ; done
sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -s -b
2010-12-13 17:37:33
User: allinurl
Functions: sed
0

GoAccess is an open source real-time Apache web log analyzer and interactive viewer that runs in a terminal in *nix systems. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. http://goaccess.prosoftcorp.com/

tail -f file |xargs -IX printf "$(date -u)\t%s\n" X
alias sshv='ssh -vvv -o LogLevel=DEBUG3'
2010-10-30 11:23:52
User: AskApache
Functions: alias
3

When debugging an ssh connection either to optimize your settings ie compression, ciphers, or more commonly for debugging an issue connecting, this alias comes in real handy as it's not easy to remember the '-o LogLevel=DEBUG3' argument, which adds a boost of debugging info not available with -vvv alone.

Especially useful are the FD info, and the setup negotiation to create a cleaner, faster connection.

sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
2010-07-30 18:20:00
User: vutcovici
Functions: echo eval grep ls sed sudo tail xargs
-1

Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux.

The list of all log files opened by java process:

sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'
*/5 * * * * root /usr/local/nagios/sbin/nsca_check_disk 2>&1 |/usr/bin/logger -t nsca_check_disk
2010-07-02 00:47:05
6

This command will log the output of your simple cronjobs to syslog, and syslog will take it from there. Works great for monitoring scripts which only produce simple output.

Advantages:

* This can be used by regular users, without modifying system files like /etc/syslog.conf

* Reduce cron spam to root@localhost (Please stop spaming the sysadmins)

* Uses common tools like syslog (and logrotate) so that you don't need to maintain yet another krufty logfile.

* Still ensures that the output is logged somewhere, for posterity. Perhaps it's stored the secure, central syslog server, for example.

* Seems to work fine on Ubuntu, CentOS, FreeBSD & MacOSX