Commands by chongopants (1)

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

Bash scripts encryption and passphrase-protection
This function will encrypt a bash script and will only execute it after providing the passphrase. Requires mcrypt to be installed on the system.

Calculate days on which Friday the 13th occurs
Alter the years in the first brace expansion to select your year range. Modify date format to your liking but leave " %w" at the end.

Search back through previous commands
Searches backwards through your command-history for the typed text. Repeatedly hitting Ctrl-R will search progressively further. Return invokes the command.

SED - Substitute string in next line
source: http://sed.sourceforge.net/sed1line.txt

Find broken symlinks and delete them
This command is adapted from http://otomaton.wordpress.com/2012/12/26/find-broken-symbolic-links/ Solutions with $ find -L don't work when the link is a loop, an error message is printed.

change ownership en masse of files owned by a specific user, including files and directories with spaces
In the example, uid 0 is root. foo:foo are the user:group you want to make owner and group. '.' is the "current directory and below." -print0 and -0 indicate that filenames and directories "are terminated by a null character instead of by whitespace."

watch process stack, sampled at 1s intervals
This command repeatedly gets the specified process' stack using pstack (which is an insanely clever and tiny wrapper for gdb) and displays it fullscreen. Since it updates every second, you rapidly get an idea of where your program is stuck or spending time. The 'tac' is used to make the output grow down, which makes it less jumpy. If the output is too big for your screen, you can always leave the 'tac' off to see the inner calls. (Or, better yet--get a bigger screen.) Caveats: Won't work with stripped binaries and probably not well with threads, but you don't want to strip your binaries or use threads anyway.

Save a file you edited in vim without the needed permissions
probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Look for English words in /dev/urandom
Little faster alternative.


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: