Commands using watch (155)

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

Generate diff of first 500 lines of two files
Useful for massive files where doing a full diff would take too long. This just runs diff on the first 500 lines of each. The use of subshells to feed STDIN is quite a useful construct.

Get the 10 biggest files/folders for the current direcotry

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"

Downmix from stereo to mono and play radio stream with mplayer
The solution to a year long (and extremely frustrating) problem I've had, caused by the fact that I only have one speaker; this command downmixes the stream to monophonic output, making sure I don't miss any of the music. NOTE: When stream is in .m3u format, a -playlist option is required, as shown below: $ mplayer -af pan=1:0.5:0.5 -channels 1 -playlist radiostream.m3u This command works great with aliases for various channels in .bashrc. Sample below: $ alias radio1='mplayer -af pan=1:0.5:0.5 -channels 1 radio1stream.pls'

for ssh uptime
This will run them at the same time and timeout for each host in ten seconds. Also, mussh will append the ip addres to the beginning of the output so you know which host resonded with which time. The use of the sequence expression {1..50} is not specific to mussh. The `seq ...` works, but is less efficient.

geoip information
geoip from maxmind try to get the small utility via: apt-get install geoip

Check if *hardware* is 32bit or 64bit
This command tell you if your hardware is 32 or 64 bits even if you install a 32bits OS on a 64 bits hardware. If your distro don't support the -q switch, try doing : $ grep &>/dev/null '\' /proc/cpuinfo && echo 64 bits || echo 32 bits

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

Prettify an XML file
Like `tidy`, `xmllint` can be used to prettify XML files. The --nsclean option is also useful to remove redundant namespaces.

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: