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

Monitoring sessions that arrive at your server

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

Show max lengths of all fields in a pipe delimited file with header row

Insert the last command without the last argument (bash)
$/usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.google.com/ then $!:- http://www.commandlinefu.com/ is the same as $/usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.commandlinefu.com/

Check to make sure the whois nameservers match the nameserver records from the nameservers themselves
Change the $domain variable to whichever domain you wish to query. Works with the majority of whois info; for some that won't, you may have to compromise: domain=google.com; for a in $(whois $domain | grep "Domain servers in listed order:" --after 3 | grep -v "Domain servers in listed order:"); do echo ">>> Nameservers for $domain from $a

Connect via sftp to a specific port
I use this for connect via sftp to a server listening on a non default ssh port.

count the number of specific characters in a file or text stream
In this example, the command will recursively find files (-type f) under /some/path, where the path ends in .mp3, case insensitive (-iregex). It will then output a single line of output (-print0), with results terminated by a the null character (octal 000). Suitable for piping to xargs -0. This type of output avoids issues with garbage in paths, like unclosed quotes. The tr command then strips away everything but the null chars, finally piping to wc -c, to get a character count. I have found this very useful, to verify one is getting the right number of before you actually process the results through xargs or similar. Yes, one can issue the find without the -print0 and use wc -l, however if you want to be 1000% sure your find command is giving you the expected number of results, this is a simple way to check. The approach can be made in to a function and then included in .bashrc or similar. e.g. $ count_chars() { tr -d -c "$1" | wc -c; } In this form it provides a versatile character counter of text streams :)

Convert any sequence of spaces/tabs to single space/tab
Remove empty lines additionally: $ tr -s ' \t\n' 2.txt identical with: $ tr -s '[:space:]' 2.txt To "clean perfectly" a text or code file, You can combine this command with another one: $ while read l; do echo -e "$l"; done 2.txt (= remove all leading and trailing spaces or tabs from all lines of a text file)

Print all /etc/passwd lines with duplicated uid
Prints all the lines in /etc/passwd belonging to users with a duplicated uid. It also adds the hostname to the beginning of the line. It's been tested in AIX, Solaris and Linux.

open a seperate konsole tab and ssh to each of N servers (konsole 4.2+)
creates a new tab for each of N servers in listofservers.txt and ssh's to said servers then, try the "send to all sessions" feature of konsole to do the same work on all servers at the same time. BIG time saver, but be careful!


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: