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.
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.
» 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:
'data' is the directory to backup, 'backup' is directory to store snapshots.
Backup files on a regular basis using hard links. Very efficient, quick. Backup data is directly available.
Same as explained here :
http://blog.interlinked.org/tutorials/rsync_time_machine.html
in one line.
Using du to check the size of your backups, the first backup counts for all the space, and other backups only files that have changed.
Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux.
The list of all log files opened by java process:
sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'
Can anyone make a shorter one?
This doesn't work:
git log --reverse -1 --format=%H
requires "youtube-dl" -- sure you can do this with wget and some more obscurity but why waste your time when this great tool is available?
the guts consist of mplayer converting a video to a gif -- study this command and read the man page for more information
mplayer video.flv -ss 00:23 -endpos 6 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
generates a 6 second gif starting at 23 seconds of play time at 5 fps and a scale of 400x300
start time (-ss)/end time (-endpos) formats: 00:00:00.000
end time should be relative to start time, not absolute. i.e. -endpos 5 == seconds after 0:42 = 0:47 end point
play with fps and scale for lower gif sizes
the subshell is a solution for the -b flag on youtube-dl which downloads the best quality video, sometimes, which can be various video formats $(ls ${url##*=}*| tail -n1)
using tail first won't do it because tail counts from the bottom of the file. You could do it this way but I don't suggest it
tail -n X | head -n 1
prints a specific line, where X is the line number
Instead of having someone else read you the Digg headlines, Have OSX do it. Requires Curl+Sed+Say. This could probably be easily modified to use espeak for Linux.
Plays the mp3 stream of The Current as a background job. When you are done run:
fg %1
then to exit
Quite possible with Growl for mac I'd guess, although have not tried.
Libnotify needed for notification, stream will still work otherwise
Netcat is used to serve a log-file over a network on port 1234.
Point a browser to the specified server/port combo to view log-file updates in real-time.
Debian-specific but very useful as cron files are prone to very subtle gotchas
Just a quick hack to give reasonable filenames to TrueType and OpenType fonts.
I'd accumulated a big bunch of bizarrely and inconsistently named font files in my ~/.fonts directory. I wanted to copy some, but not all, of them over to my new machine, but I had no idea what many of them were. This script renames .ttf files based on the name embedded inside the font. It will also work for .otf files, but make sure you change the mv part so it gives them the proper extension.
REQUIREMENTS: Bash (for extended pattern globbing), showttf (Debian has it in the fontforge-extras package), GNU grep (for context), and rev (because it's hilarious).
BUGS: Well, like I said, this is a quick hack. It grew piece by piece on the command line. I only needed to do this once and spent hardly any time on it, so it's a bit goofy. For example, I find 'rev | cut -f1 | rev' pleasantly amusing --- it seems so clearly wrong, and yet it works to print the last argument. I think flexibility in expressiveness like this is part of the beauty of Unix shell scripting. One-off tasks can be be written quickly, built-up as a person is "thinking aloud" at the command line. That's why Unix is such a huge boost to productivity: it allows each person to think their own way instead of enforcing some "right way".
On a tangent: One of the things I wish commandlinefu would show is the command line HISTORY of the person as they developed the script. I think it's that conversation between programmer and computer, as the pipeline is built piece-by-piece, that is the more valuable lesson than any canned script.
Another way of counting the line output of tail over 10s not requiring pv.
Cut to have the average per second rate :
tail -n0 -f access.log>/tmp/tmp.log & sleep 10; kill $! ; wc -l /tmp/tmp.log | cut -c-2
You can also enclose it in a loop and send stderr to /dev/null :
while true; do tail -n0 -f access.log>/tmp/tmp.log & sleep 2; kill $! ; wc -l /tmp/tmp.log | cut -c-2; done 2>/dev/null
Displays the realtime line output rate of a logfile.
-l tels pv to count lines
-i to refresh every 10 seconds
-l option is not in old versions of pv. If the remote system has an old pv version:
ssh tail -f /var/log/apache2/access.log | pv -l -i10 -r >/dev/null
Change the cut range for hits per 10 sec, minute and so on... Grep can be used to filter on url or source IP.
This searches the Apache error_log for each of the 5 most significant Apache error levels, if any are found the date is then cut from the output in order to sort then print the most common occurrence of each error.
Several people have submitted commands to do this, but I think this is the simplest solution. It also happens to be the most portable one: It should work with any sh or csh derived shell under any UNIX-like OS.
Oh by the way, with my German locale ($LC_TIME set appropriately) it prints "g" most of the time, and sometimes (on Wednesdays) it prints "h". It never prints "y".
Change open-command and type to suit your needs. One example would be to open the last .jpg file with Eye Of Gnome:
eog $(ls -rt *.jpg | tail -n 1)