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

Both view and pipe the file without saving to disk
This is a cool trick to view the contents of the file on /dev/pts/0 (or whatever terminal you're using), and also send the contents of that file to another program by way of an unnamed pipe. All the while, you've not bothered saving any extra data to disk, like you might be tempted to do with sed or grep to filter output.

Multi-line grep
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible. See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk. Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.

list block devices
Shows all block devices in a tree with descruptions of what they are.

Find and copy scattered mp3 files into one directory
I used this command to recursively gather all mp3 files that were previously imported into their own directories (sorted by band name) in Songbird.

Synchronize date and time with a server over ssh
If you are stuck behind a firewall and want to synchronize time with another server but you do not want to port forward NTP (which uses UDP) then this command is handy. It gets the time from a server and sets the local time. It is not that accurate but I can live with a second or so drift.

count how many cat processes are running
'ps ax' provides the fill list of running processes. 'grep -c [c]at' will find all processes that match 'cat' without matching itself....

Instead of writing a multiline if/then/else/fi construct you can do that by one line
instead of writing: if [[ "$1" == "$2" ]]; then echo "$1 is equal $2" else echo "$1 differs from $2" fi do write: [[ "$1" == "$2" ]] && echo "$1 is equal $2" || echo "$1 differs from $2"

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Generate a random password 30 characters long
The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible. Human-memorable passwords are never going to be as secure as completely completely random passwords. [from pwgen man page]

Takes all file except file between !()
Go to tmp : cd /tmp; mkdir retmp; cd retmp Create 10 files : for i in {1..10}; do touch test$i; done Remove all files except test10 : rm !(test10)


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: