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:
These re the best option combination that works fine for compressing my database dumps. It's possible that there are another option or value that might improve the compression ratio, by these are the ones that worked, the syntax for 7zr it's a little messy...
Once you've made the snapshot you can resume any stopped services and then back up the file system (using the snapshot) without having to worry about changed files.
When finished, the snapshot can be removed :
mdconfig -d -u 1
rm /var/.snap/snap_var_`date "+%Y-%m-%d"`
'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 :
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.
Opens a snapshot of a live UFS2 filesystem, runs dump to generate a full filesystem backup which is run through gzip. The filesystem must support snapshots and have a .snap directory in the filesystem root.
To restore the backup, one can do
zcat /path/to/adXsYz.dump.gz | restore -rf -
This is just a little snippit to split a large file into smaller chunks (4mb in this example) and then send the chunks off to (e)mail for archival using mutt.
I usually encrypt the file before splitting it using openssl:
openssl des3 -salt -k <password> -in file.tgz -out file.tgz.des3
To restore, simply save attachments and rejoin them using:
cat file.tgz.* > output_name.tgz
and if encrypted, decrypt using:
openssl des3 -d -salt -k <password> -in file.tgz.des3 -out file.tgz
edit: (changed "g" to "e" for political correctness)
Dumps a compressed svn backup to a file, and emails the files along with any messages as the body of the email
This deals nicely with files having special characters in the file name (space ' or ").
Parallel is from https://savannah.nongnu.org/projects/parallel/
Use if you have pictures all over the place and you want to copy them to a central location
Find jpg files
translate all file names to lowercase
backup existing, don't overwrite, preserve mode ownership and timestamps
copy to a central location
This script creates date based backups of the files. It copies the files to the same place the original ones are but with an additional extension that is the timestamp of the copy on the following format: YearMonthDay-HourMinuteSecond
The command as given would create the file "/result_path/result.tar.gz" with the contents of the target folder including permissions and sub- folder structure.
When need to pack the ZODB...
creates a compressed tar archive of files in /path/foo and writes to a timestamped filename in /path.
Use tar command for a backup info with a date of creation
A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command
This command clone the first partition of the primary master IDE drive to the second partition
of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)
The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info.
I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function.
Use `zless` to read the content of your *rss.gz file:
Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.
This will backup the _contents_ of /media/SOURCE to /media/TARGET where TARGET is formatted with ntfs. The --modify-window lets rsync ignore the less accurate timestamps of NTFS.
This will compress the root directory to an external hard drive and split it to parts once it reaches the 4 Gigs file system limit.
You can simply restore it with:
restore ivf /media/My\ Passport/Fedora10bckup/root_dump_fedora
Very simple and useful, you need to change the word "directory" for your directory
create an archive of files with access time older than 5 days, and remove original files.