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:
This command makes a small graph with the histogram of size blocks (5MB in this example), not individual files. Fine tune the 4+5*int($1/5) block for your own size jumps : jump-1+jump*($1/jump)
Also in the hist=hist-5 part, tune for bigger or smaller graphs
This will write to TAPE (LTO3-4 in my case) a backup of files/folders. Could be changed to write to DVD/Blueray.
Go to the directory where you want to write the output files : cd /bklogs
Enter a name in bkname="Backup1", enter folders/files in tobk="/home /var/www".
It will create a tar and write it to the tape drive on /dev/nst0.
In the process, it will
1) generate a sha512 sum of the tar to $bkname.sha512; so you can validate that your data is intact
2) generate a filelist of the content of the tar with filesize to $bkname.lst
3) buffer the tar file to prevent shoe-shining the tape (I use 4GB for lto3(80mb/sec), 8gb for lto4 (120mb/sec), 3Tb usb3 disks support those speed, else I use 3x2tb raidz.
4) show buffer in/out speed and used space in the buffer
5) show progress bar with time approximation using pv
To eject the tape :
; sleep 75; mt-st -f /dev/nst0 rewoffl
1) When using old tapes, if the buffer is full and the drive slows down, it means the tape is old and would need to be replaced instead of wiping it and recycling it for an other backup. Logging where and when it slows down could provide good information on the wear of the tape. I don't know how to get that information from the mbuffer output and to trigger a "This tape slowed down X times at Y1gb, Y2gb, Y3gb down to Zmb/s for a total of 30sec. It would be wise to replace this tape next time you want to write to it."
2) Fix filesize approximation
3) Save all the output to $bkname.log with progress update being new lines. (any one have an idea?)
4) Support spanning on multiple tape.
5) Replace tar format with something else (dar?); looking at xar right now (https://code.google.com/p/xar/), xml metadata could contain per file checksum, compression algorithm (bzip2, xv, gzip), gnupg encryption, thumbnail, videopreview, image EXIF... But that's an other project.
1) You can specify the width of the progressbar of pv. If its longer than the terminal, line refresh will be written to new lines. That way you can see if there was speed slowdown during writing.
2) Remove the v in tar argument cvf to prevent listing all files added to the archive.
3) You can get tarsum (http://www.guyrutenberg.com/2009/04/29/tarsum-02-a-read-only-version-of-tarsum/)
and add >(tarsum --checksum sha256 > $bkname_list.sha256) after the tee to generate checksums of individual files !
This command sorts the content including hidden files in human readable format of the current directory.
Add date time to output whithin the current directory
Very quick! Based only on the content sizes and the character counts of filenames. If both numbers are equal then two (or more) directories seem to be most likely identical.
if in doubt apply:
diff -rq path_to_dir1 path_to_dir2
AWK function taken from here:
Lists directory size up to a maximum traversal depth on systems like IBM AIX, where the du command doesn't have Linux's --max-depth option. AIX's du uses -g to display directory size on gigabytes, -m to use megabytes, and -k to use kilobytes. tr### is a Perl function that replaces characters and returns the amount of changed characters, so in this case it will return how many slashes there were in the full path name.
this will give u the details in MB's; from high to low....
I added -S to du so that you don't include /foo/bar/baz.iso in /foo, and change sorts -n to -h so that it can properly sort the human readable sizes.
Shows the 10 biggest files/dirs
Sorted in human readable format.
When you do a ls -1 | xargs rm it wouldn't workd because those files have spaces. So you must use
find -print0 and xargs -0
To sort the list by file/directory size, insert `sort -n |` before `awk`.