This is useful if you'd like to see the output of a script while you edit it. Each time you save the file the command is executed. I thought for sure something like this already exists - and it probably does. I'm on an older system and tend to be missing some useful things.
Examples:
ontouchdo yourscript 'clear; yourscript somefiletoparse'
Edit yourscript in a separate window and see new results each time you save.
ontouchdo crufty.html 'clear; xmllint --noout crufty.html 2>&1 | head'
Keep editing krufty.html until the xmllint window is empty.
Note: Mac/bsd users should use stat -f%m. If you don't have stat, you can use perl -e '$f=shift; @s=stat($f); print "$s[9]\n";' $1
Cycles continuously through a string printing each character with a random delay less than 1 second. First parameter is min, 2nd is max. Example: 1 3 means sleep random .1 to .3. Experiment with different values. The 3rd parameter is the string. The sleep will help with battery life/power consumption.
cycle 1 3 $(openssl rand 100 | xxd -p)
Fans of "The Shining" might get a kick out of this:
cycle 1 4 ' All work and no play makes Jack a dull boy.'
Use the following variation for FreeBSD:
openssl rand 6 | xxd -p | sed 's/\(..\)/\1:/g; s/:$//'
This version transfers gzipped data which is unzipped as it arrives at the remote host.
This version uses the indent C formatting utility. Doesn't appear to be included with ubuntu. But CentOS and MacOS have it.
This version uses netcat to check a particular service.
Looking for carriage returns would also identify files with legacy mac line endings. To fix both types:
perl -i -pe 's/\r\n?/\n/g' $(find . -type f -exec fgrep -l $'\r' "{}" \;)
Great idea camocrazed. Another twist would be to display a different man page based on the day of the year. The following will continuously cycle through all man pages:
man $(ls /bin | sed -n $(($(date +%j) % $(ls /bin | wc -l)))p)
Looks like you're stuck with sed if your ls doesn't have a -Q option.
Splitting on tags in awk is a handy way to parse html.
If your grep doesn't have an -o option, you can use sed instead.
Tested on CentOS, Ubuntu, and MacOS.
Here's a version that uses perl. If you'd like a trailing newline:
perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg; END {print "\n"}'
Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error.
Here's a version that uses netcat (although I'd much rather use curl!).
Just shortened the awk a bit and removed sed. Edit: I'm assuming there are no spaces in the path. To support white space in pathname try:
awk '($1 < 2048) {sub(/^[0-9]+[ \t]+/,""); print $0}'
Here's a version that doesn't use find.
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.
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
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: