commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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
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:
"sort_csn" is a function to sort a comma separated list of numbers.
Define the the function with this:
sort_csn () { echo "${1}" | sed -e "s/,/\n/g"| sort -nu | awk '{printf("%s,",$0)} END {printf("\n")}' | sed -e "s/,$//"; }
Use the function like this:
sort_csn 443,22,80,8200,1533,21,1723,1352,25
21,22,25,80,443,1352,1533,1723,8200
One example where this is useful is when port scanning with nmap and getting a list of open ports in random order. If you use Nessus, you may need to create a scan policy for that set of specific ports and it is clearer to read with the port numbers in ascending order (left to right).
Caveat: no spaces in the comma separated list (just number1,number2,number3,etc).
A variation of this to sort a comma separated list of strings:
sort_css () { echo "${1}" | sed -e "s/,/\n/g"| sort -u | awk '{printf("%s,",$0)} END {printf("\n")}' | sed -e "s/,$//"; }
usage:
sort_css apples,pears,grapes,melons,oranges
apples,grapes,melons,oranges,pears
Where COMMAND is the process(es) name. I prefer to get all states but you may add ESTABLISHED in the grep regex.
lsof -c apache2 | egrep -o 'TCP.*ESTABLISHED.*$'
-nP flags are optional and UDP is irrelevant for established connections
Similar but using the process id:
lsof -nP -p PID | egrep -o '(TCP|UDP).*$'
This one-liner will output installed packages sorted by size in Kilobytes.
list top committers (and number of their commits) of svn repository.
in this example it counts revisions of current directory.
Also:
* find . -type f -exec ls -s {} \; | sort -n -r | head -5
* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5
du -m option to not go across mounts (you usually want to run that command to find what to destroy in that partition)
-a option to also list . files
-k to display in kilobytes
sort -n to sort in numerical order, biggest files last
tail -10 to only display biggest 10
This command finds all of the functions defined in any shell script you specify including .bashrc
So your boss wants to know how much memory has been assigned to each virtual machine running on your server... here's how to nab that information from the command line while logged in to that server
This command allows you to find the effective uid and gid of the Apache process regardless of process name (which can be apache2 or httpd depending on distro).