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

Copy the full path of a file to the clipboard (requires xclip or similar)
Handy for those times you need to paste a file path in an IDE or some other app. sudo apt-get install xclip Then, for convenience, alias xclip to 'xclip -selection c' so you can just do something like realpath . | xclip

Count lines in a file with grep
Returns the number of lines in a file, emulates "wc -l" behavior with grep.

Create a file of a given size in linux
If you're trying to create a sparse file, you can use dd by 'skip'ing to the last block instance. ls -ls shows the actual size vs. the reported size

Show highlighted text with full terminal width
Show a full terminal line inverted with custom text.

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" }

Backup files incremental with rsync to a NTFS-Partition
This will backup the _contents_ of /media/SOURCE to /media/TARGET where TARGET is formatted with ntfs. The --modify-window lets rsync ignore the less accurate timestamps of NTFS.

Simple way to envoke a secure vnc session through ssh enabled router.
The ip address is of the remote machine running the vncserver. Must log in first to the router then the VNC session. Very nice if you have open-wrt or dd-wrt on your router.

find out how much space are occuipied by files smaller than 1024K (sic) - improved
The original didn't use -print0 which fails on weird file names eg with spaces. The original parsed the output of 'ls -l' which is always a bad idea.

Debian Runlevel configuration tool
This tool configures system services in connection with system runlevels. It turns on/off services using the scripts in /etc/init.d/. Rcconf works with System-V style runlevel configuration. It is a TUI(Text User Interface) frontend to the update-rc.d command.

View facebook friend list [hidden or not hidden]
There's no need to be logged in facebook. I could do more JSON filtering but you get the idea... Replace u=4 (Mark Zuckerberg, Facebook creator) with desired uid. Hidden or not hidden... Scary, don't you?


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: