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

Perl One Liner to Generate a Random IP Address

python2 -m CGIHTTPServer
In case you need to test some CGI scripts this does the job. It also has the functionality of a http server. Enjoy!

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"

This is how you should push a string in a command's stdin.
Don't do this: $echo word | command Using a bash "here strings" and "here documents" look leeter than piping echo into the command. Also prevents subshell execution. Word is also expanded as usual.

Copy the full path of a file to the clipboard (requires xclip or similar)
Handy for those times you need to paste a file path in an IDE or some other app. sudo apt-get install xclip Then, for convenience, alias xclip to 'xclip -selection c' so you can just do something like realpath . | xclip

fdiff is a 'filtered diff'. Given a text filter and two inputs, will run the filter across the input files and diff the output.
Fdiff will run the command given by the first argument against the input files given as the second and third arguments, and diff the results. It will use 'diff' as the default diff program, but this can be changed by setting $DIFFCMD, e.g. $ export DIFFCMD=vimdiff; $ fdiff zcat 0716_0020005.raw.gz 0716_0030005.raw.gz ... This function will work under bash, but requires the use of command substitution, which is not available under a strict ANSI shell.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

find files beginning with filename* that do not include "string"
Inverse grep, to find files without the string

Indent a one-liner.
I often write a one-liner which I want to use later in a script.


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: