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

Create full backups of individual folders using find and tar-gzip
Problem: I wanted to backup user data individually. In this example, all user data is located in "/mnt/storage/profiles", and about 25 folders inside, each with a username ( /mnt/storage/profiles/mike; /mnt/storage/profiles/lucy ...) I need each individual folder backed up, not the whole "/mnt/storage/profiles". So, using find while excluding directories depth and creating two variables (tarfile=username & desdir=destination), tar will create a .tgz file for each folder, resulting in a "mike_full.tgz" and "lucy_full.tgz".

Get the canonical, absolute path given a relative and/or noncanonical path
readlink -f accepts a relative, noncanonical path and emits the corresponding canonical, absolute path.

convert flac to mp3
if you haven't already done so, install lame and flac: sudo apt-get install lame flac

Add a line from 1 file after every line of another (shuffle files together)
After every line in targetfile (empty lines included) insert in a line from addfile. "Save" results to savefile. Addfile should be longer than targetfile since this doesn't loop back to the top of addfile. /^/R addfile -- says for every line that matches "has a start of line" output a line from the file addfile. > savefile (optional) -- redirect output to savefile file.

Shows a specific process memory usage

determine if tcp port is open
Requires netcat.

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

Remove orphaned dependencies on Arch
-Qdt Lists dependencies/packages which are no longer required by any packages -q Output only package name (not the version number) -R Remove package(s) Rest is self-explanatory. I just started out with Arch - so if there is any better/standard method to achieve the same - please suggest.

Download Youtube video with wget!
Nothing special required, just wget, sed & tr!

Is it a terminal?
Oddly, the isatty(3) glibc C call doesn't have a direct analogue as a command 'isatty(1)'. All is not lost as you can use test(1). For example, your script might be run from a tty or from a GUI menu item but it needs to get user-input or give feedback. Now your script can test STDIN with 'isatty 0' or STDOUT with 'isatty 1' and use xmessage(1) if the tty is not available. The other way to test for this is with 'tty -s' - but that's only for STDIN.


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: