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

Create a backup of the file.
It will create a backup of the filename. The advantage is that if you list the folder the backups will be sorted by date. The command works on any unix in bash.

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"

Count TCP States From Netstat
Counts TCP states from Netstat and displays in an ordered list.

Count accesses per domain
count the times a domain appears on a file which lines are URLs in the form http://domain/resource.

execute your commands hiding secret bits from history records
$ wget --user=username --password="$password" http://example.org/ Instead of hiding commands entirely from history, I prefer to use "read" to put the password into a variable, and then use that variable in the commands instead of the password. Without the "-e" and "-s" it should work in any bourne-type shell, but the -s is what makes sure the password doesn't get echoed to the screen at all. (-e makes editing work a bit better)

Wget Command to Download Full Recursive Version of Web Page
The example will create a directory called "www.foo.com" that will contain an index.html page and any necessary images/css required for the page to load. Caveats: @imports of css files will not be converted.

A function to find the newest file of a set.
Usage example: $newest Desktop/* Replace "-nt" with "-ot" for oldest. Run $shopt -s dotglob first to include dotfiles.

Close shell keeping all subprocess running

Re-use the previous command output
The $(!!) will expand to the previous command output (by re-running the command), which becomes the parameter of the new command newcommand.

Check how far along (in %) your program is in a file
Say you're started "xzcat bigdata.xz | complicated-processing-program >summary" an hour ago, and you of course forgot to enable progress output (you could've just put "awk 'NR%1000==0{print NR>"/dev/stderr"}{print}'" in the pipeline but it's too late for that now). But you really want some idea of how far along your program is. Then you can run the above command to see how many % along xzcat is in reading the file. Note that this is for the GNU/Linux version of lsof; the one found on e.g. Darwin has slightly different output so the awk part may need some tweaks.


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: