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

sudo for launching gui apps in background
Need package: gksu Note: Launching gui app in background that needs sudo, won't work great with our old friendly style of launching: $ sudo gedit /etc/passwd & because this would put sudo in background ! Using gksudo as demonstrated, would popup a gui sudo window. May be this is a common knowledge, but not knowing this frustrated me during my newbie year.

a simple bash one-liner to create php file and call php function

Compare two directories
Output of this command is the difference of recursive file lists in two directories (very quick!). To view differences in content of files too, use the command submitted by mariusbutuc (very slow!): $ diff -rq path_to_dir1 path_to_dir2

Extract tar content without leading parent directory
If archive has leading directory level same as archive name and you want to strip it, this command is for you.

unbuffered tcpdump
Sometimes the question comes up: How to get unbuffered tcpdump output into the next program in the pipe? i.e. if your OS forces you to wait for the buffer to fill before the next program sees any of the output If you use -Uw- then you can't use -A (or -X or -XX) at the same time. When the question comes up, I've never seen anyone suggest this simple solution: chaining 2 tcpdump instances.

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"

show current directory
Opens a file or URL in the user's preferred application.

Backup files older than 1 day on /home/dir, gzip them, moving old file to a dated file.
Useful for backing up old files, custom logs, etc. via a cronjob.

Synchronize both your system clock and hardware clock and calculate/adjust time drift
Do not run this command if you already have ntpd running! This needs to run as root, for example with sudo: $ sudo ntpdate pool.ntp.org && sudo hwclock --systohc && sudo hwclock --adjust This command will fetch accurate time from NTP servers and synchronize your system clock, then it will use the system clock to synchronize your hardware clock, and will calculate the time drift.

find the biggest files recursively, no matter how many
This command will find the biggest files recursively under a certain directory, no matter if they are too many. If you try the regular commands ("find -type f -exec ls -laSr {} +" or "find -type f -print0 | xargs -0 ls -laSr") the sorting won't be correct because of command line arguments limit. This command won't use command line arguments to sort the files and will display the sorted list correctly.


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: