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

Find and copy scattered mp3 files into one directory
No problem with word splitting. That should works on many Unix likes.

remove all spaces from all files in current folder

FizzBuzz in one line of Bash
The (in)famous "FizzBuzz" programming challenge, answered in a single line of Bash code. The "|column" part at the end merely formats the output a bit, so if "column" is not installed on your machine you can simply omit that part. Without "|column", the solution only uses 75 characters. The version below is expanded to multiple lines, with comments added. for i in {1..100} # Use i to loop from "1" to "100", inclusive. do ((i % 3)) && # If i is not divisible by 3... x= || # ...blank out x (yes, "x= " does that). Otherwise,... x=Fizz # ...set x to the string "Fizz". ((i % 5)) || # If i is not divisible by 5, skip (there's no "&&")... x+=Buzz # ...Otherwise, append (not set) the string "Buzz" to x. echo ${x:-$i} # Print x unless it is blanked out. Otherwise, print i. done | column # Wrap output into columns (not part of the test).

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"

Query an NFS host for its list of exports

Find and copy scattered mp3 files into one directory
This command copies all filenames in the current dir and subdirs that end in .mp3 regardless of case (also matches .MP3 .mP3 and .Mp3) It copies all the files to the "mp3" folder in your home directory. If you want to see the files that are beeing copied, replace "cp {}" with "cp -v {}"

Make a directory named with the current date
Create a directory named with the current date in ISO 8601 format (yyyy-mm-dd). Useful for storing backups by date. The --iso switch may only work with GNU date, can use format string argument for other date versions.

reverse order of file

LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
This version eliminates the grep before the awk, which is always good. It works for GNU core utils and ensures that the date output of ls matches the format in the pattern match, regardless of locale, etc. On BSD-based systems, you can easily eliminate both the grep and the awk: find . -maxdepth 1 -Btime -$(date +%kh%lm) -type f

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"


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: