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

Remove all but One
$ rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; } Add this to your .bashrc file. Then whenever you need to remove all files/directories but one from present working directory. Run: $ rm-but Notes: 1. This doesn't affect the hidden files. 2. Argument is actually as string. And all files/directories having this string in there name are left untouched.

List the size (in human readable form) of all sub folders from the current location
Simple and easy to remember. -h is human, -d1 = depth 1. disk usage, human, depth 1

Do not clear the screen after viewing a file with less
From the manpage: $ man less -X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen. Bonus: If you want to clear the screen after viewing a file this way that had sensitive information, hit or just type clear. Since is readily available, I don't know why less bothers to automatically clear. If you're viewing the file at all, chances are you want to see the output from it after you quit.

Print a row of 50 hyphens
Get there by going backwards and forgetting the numbers.

Batch resize all images in the current directory that are bigger than 800px, height or weight.
You need to install imagemagick. On Debian type: # apt-get install imagemagick

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

Create an SSH tunnel for accessing your remote MySQL database with a local port

Search some text from all files inside a directory

What is My WAN IP?
The curl command retrieve the HTML text containing the IP address. The grep command picks out the IP address from that HTML text.

complete extraction of a debian-package
extracts the debian-package $debfile to $extractdir, including all packaging-information. to repack the package, just type: $dpkg-deb -b $extractdir


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: