Commands by nikc (2)

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

Recursive search and replace (with bash only)
Replaces a string matching a pattern in one or several files found recursively in a particular folder.

Find directory depth
Returns a the directory depth.

Download all recently uploaded pastes on pastebin.com

List your largest installed packages (on Debian/Ubuntu)
The other commands were good, but they included packages that were installed and then removed. This command only shows packages that are currently installed, sorts smallest to largest, and formats the sizes to be human readable.

Generate random IP addresses
It never ends

Get a range on line with sed (first two)
Get the two first lines of a file and quit.

Add forgotten changes to the last git commit
It's pretty common to forgot to commit a files, be it a modification, or a brand new file. If you did forget something, git add the files you want, and then git commit --amend. It will essentially redo the last commit, with the changes you just added. It seeds the commit message with the last commit message by default. You probably shouldn't do this if you've already pushed the commit.

Edit video by cutting the part you like without transcoding.
Examples: The following will take frames starting at 15.2 seconds for a total of 45.9 seconds: $ mencoder -ss 15.2 -endpos 30.7 -oac copy -ovc copy mymovie.avi -o myeditedmovie.avi Keep in mind -endpos is the total time, i.e. the output video in this is 3 minutes 3 seconds in length: $ mencoder -ss 1 minute -endpos 2 minutes 3 seconds -oac copy -ovc copy mymovie.avi -o myeditedmovie.avi

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Download all images from a site
This recursively downloads all images from a given website to your /tmp directory. The -nH and -nd switches disable downloading of the directory structure.


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: