commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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.
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:
Run "ps -x" (process status) in the background every hour (in this example).
The outputs of both "nohup" and "ps -x" are sent to the e-mail (instead of nohup.out and stdout and stderr).
If you like it, replace "ps -x" by the command of your choice, replace 3600 (1 hour) by the period of your choice.
You can run the command in the loop any time by killing the sleep process. For example
2925 ? S 0:00.00 sh -c unzip E.zip >/dev/null 2>&1
11288 ? O 0:00.00 unzip E.zip
25428 ? I 0:00.00 sleep 3600
14346 pts/42- I 0:00.01 bash -c while true; do ps -x | mail pascalv; sleep 3600; done
643 pts/66 Ss 0:00.03 -bash
14124 pts/66 O+ 0:00.00 ps -x
You have mail in /mail/pascalv
Replace "email@example.com" with your carrier's SMS gateway identifier. The one in the sample is for AT&T. More here https://en.wikipedia.org/wiki/List_of_SMS_gateways. Helpful for getting notifications about long running commands. ";" executes regardless of exit status of last command. && will only notify you if the command succeeds.
Every 20 minutes test if host with IP 192.168.0.14 is 'dead' or not reachable.
The line should be put in your crontab file.
This is a two part command that comes in really handy if you're running commands that take longer than you're willing to wait. The commands are separated by the semicolon(;) The first command is whatever you're attempting to do. The second commands emails you after the job completes.
Counts the number of new emails in the post office (or wherever mail is set up to check).
I created this so I could send myself an email alert when a long-running job was finished, e.g.,
my_long_job.exe ; quickemail my_long_job.exe has finished
Note, you need to replace the email address with your private Instapaper email address.
There are a bunch of possible improvements such as,
- Not writing a temp file
- Doesnt strip tags (tho Instapaper does thankfully)
- Shouldnt require 2 curls
This version uses netcat to check a particular service.
For some reason the 2&>1 does not work for me, but the shorter stdout/stderr redirection >& works perfectly (Ubuntu 10.04).
Checks if a web page has changed. Put it into cron to check periodically.
Change http://www.page.de/test.html and firstname.lastname@example.org for your needs.
A cronjob command line to email someone when a webpages homepage is updated.
It's very common to have cron jobs that send emails as their output, but the From: address is whatever account the cron job is running under, which is often not the address you want replies to go to. Here's a way to change the From: address right on the command line.
What's happening here is that the "--" separates the options to the mail client from options for the sendmail backend. So the -f and -F get passed through to sendmail and interpreted there. This works on even on a system where postfix is the active mailer - looks like postfix supports the same options.
I think it's possible to customize the From: address using mutt as a command line mailer also, but most servers don't have mutt preinstalled.
on this way we can define the body too
Alternative to the ping check if your firewall blocks ping. Uses curl to get the landing page silently, or fail with an error code. You can probably do this with wget as well.
Joker wants an email if the Brand X server is down. Set a cron job for every 5 mins with this line and he gets an email when/if a ping takes longer than 3 seconds.
if "mail -a" fail, try "mutt -a" or "nail -a"
uuencode the file to appear as an attachment
This just reads in a local file and sends it via email. Works with text or binary. *Requires* local mail server.
Replace "email@example.com" with the target e-mail address. Thanks to alediaz for "$HOSTNAME" which is very useful when running the command with Apple Remote Desktop to multiple machines simultaneously.
The uuencode utility will encode your file so that it can be sent as an attachment to an email. It is part of the sharutils package in RHEL/CentOS/Fedora.
An easy one but nice to keep in mind.