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

reverse order of file

Grab IP address on machine with multiple interfaces
Instead of hard-coding in a check to scrape info from ifconfig based on a specific interface, do it in a more portable way. This works really well if you switch between wired, wireless, bluetooth or even VPN connections. You can get your current IP in a script (since it'll be something like tun0 instead of eth0 or wlan1). This uses a well known public ip address 8.8.8.8, but it doesn't actually connect to it, it just shows you the route it would take.

Delete Last Line of a File if it is Blank
Use sed to remove the last line of a file only if it is empty.

Send e-mail if host is 'dead' or not reachable
Cleaner with a mailto assignment in crontab (if the command fails you get an email): MAILTO=admin@example.com 10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 >/dev/null

Alias for lazy tmux create/reattach

Display the number of connections to a MySQL Database
Count the number of active connections to a MySQL database. The MySQL command "show processlist" gives a list of all the active clients. However, by using the processlist table, in the information_schema database, we can sort and count the results within MySQL.

Monitor RX/TX packets and any subsquent errors
www.fir3net.com

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"

Find the top 10 directories containing the highest number of files
It can be used to pinpoint the path(s) where the largest number of files resides when running out of free i-nodes

Mount a Windows share on the local network (Ubuntu) with user rights and use a specific samba user


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: