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

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"

Apply new patch for a directory (originDir)

Prints new content of files
Useful to e.g. keep an eye on several logfiles.

Netstat Connection Check
This command does a tally of concurrent active connections from single IPs and prints out those IPs that have the most active concurrent connections. VERY useful in determining the source of a DoS or DDoS attack.

Mac OS X: remove extra languages to save over 3 GB of space.
This will get the job done in the most efficient way - spawning only one `rm` process. "On-the-fly" find data is displayed through `tee` and you should have plenty of time to ctrl-c if needed before it's too late. You may need to re-run this after major Software Updates. To leave more languages in, add more ``-and \! -iname "lang*"'' statements: $ sudo find / -iname "*.lproj" -and \! -iname "en*" -and \! -iname "spanish*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv **Edit: note the 2nd sudo near the end of the pipeline - this is necessary.

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"

Speed up builds and scripts, remove duplicate entries in $PATH. Users scripts are oftern bad: PATH=/apath:$PATH type of thing cause diplicate.
Thanks to the authors of: $ awk '!x[$0]++' and the author of: $ joinargs() { (local IFS="$1"; shift && echo "$*") } and others, we can have a fast Linux or android. IMPORTANT if you find a priority order problem in PATH you can push a path directory to the front without duplication as follows: $ PATH=/bin:$PATH then ... Check duplication with: $ echo $PATH|tr : '\n'|sort|uniq -d Finally do a very neat line by line list of $PATH: $ echo "${PATH//:/$'\n'} The speed up is very noticeable for android, and builds on Linux Ubantu are much faster with make and scripts. I will update the command on request. Timothy from SONY

Find directory depth
Returns a the directory depth.

All what exists in dir B and not in dir A will be copied from dir B to new or existing dir C
Assumed dir A, B, C are subdirs of the current dir Exact syntax of the command is: rsync -v -r --size-only --compare-dest=/path_to_A/A/ /path_to_B/B/ /path_to_C/C/ (do not omit end-slashes, since that would copy only the names and not the contents of subdirs of dir B to dir C) You can replace --size-only with --checksum for more thorough file differences validation Useful switch: -n, --dry-run perform a trial run with no changes made

5 Which Aliases
5 helpful aliases for using the which utility, specifically for the GNU which (2.16 tested) that is included in coreutils. Which is run first for a command. Same as type builtin minus verbosity $ alias which='{ command alias; command declare -f; } | command which --read-functions --read-alias' Which (a)lias $ alias whicha='command alias | command which --read-alias' Which (f)unction $ alias whichf='command declare -f | command which --read-functions' Which e(x)ecutable file in PATH $ alias whichx='command which' Which (all) alias, function, builtin, and files in PATH $ alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a' # From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html


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: