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:
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
This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it.
USAGE: SEE SAMPLE OUTPUT
The file is composed of three parts:
a) The legible script (about 242 bytes)
b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242)
c) The actual filesystem
Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option.
PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :)
It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file.
The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables.
In order to create a new encrypted filing system managed by cryptmount,
you can use the supplied 'cryptmount-setup' program, which can be used
by the superuser to interactively configure a basic setup.
Alternatively, suppose that we wish to setup a new encrypted filing
system, that will have a target-name of "opaque". If we have a free
disk partition available, say /dev/hdb63, then we can use this directly
to store the encrypted filing system. Alternatively, if we want to
store the encrypted filing system within an ordinary file, we need to
create space using a recipe such as:
dd if=/dev/zero of=/home/opaque.fs bs=1M count=512
cryptmount --generate-key 32 opaque
cryptmount --prepare opaque
cryptmount --release opaque
cryptmount -m opaque
cryptmount -u opaque
For detail see sample output
Clone a root partition. The reason for double-mounting the root device is to avoid any filesystem overlay issues. This is particularly important for /dev.
Also, note the importance of the trailing slashes on the paths when using rsync (search the man page for "slash" for more details). rsync and bash add several subtle nuances to path handling; using trailing slashes will effectively mean "clone this directory", even when run multiple times. For example: run once to get an initial copy, and then run again in single user mode just before rebooting into the new disk.
Using file globs (which miss dot-files) or leaving off the trailing slash with rsync (which will create /mnt/target/root) are traps that are easy to fall into.
Ever ask yourself "How much data would be lost if I pressed the reset button?"
Scary, isn't it?
cloning root filesystem without suffering to possible interruptions. useful when moving a running system to a new partition. also works as a solid backup solution.
preserve all except context and xattr. useful when moving a running system to a new partition.
Necessary for fsck for example.
The remount functionality follows the standard way how the mount command works with options from fstab. It means the mount command doesn't read fstab (or mtab) only when a device and dir are fully specified. After this call all old mount options are replaced and arbitrary stuff from fstab is ignored, except the loop= option which is internally generated and maintained by the mount command.
It does not change device or mount point.
This one-liner is for cron jobs that need to provide some basic information about a filesystem and the time it takes to complete the operation. You can swap out the di command for df or du if that's your thing. The |& redirections the stderr and stdout to the mail command.
How to configure the variables.
FSCKDEV=`grep $TOFSCK /proc/mounts | cut -f1 -d" "`
MAILSUB="weekly file system check $TOFSCK "
To create directory, use:
Curious about differences between /bin, /usr/bin, and /usr/local/bin? What should be in the /sbin dir? Try this command to find out.
Tested against Red Hat & OS X
Iozone with a file of 2GB, 64KB record size, write/rewrite and read/re-read test, using just one thread.
use the locate command to find files on the system and verify they exist (-e) then display each one in full details.
since fuse mounts do not appear in /etc/mtab (fuse can't write there, dunno if it would if it could) this is propably a better way.
When a fs hangs and you've just one console, even # ls could be a dangerous command. Simply put a trailing "&" and play safe
Before doing this, back-up all data on any ext3 partitions that are to be converted to ext4.
After running previous command you MUST run fsck, is needed to return the filesystem to a consistent state.
fsck -pDf /dev/yourpartition
Edit /etc/fstab and change the 'type' from ext3 to ext4 for any partitions that are converted to ext4.
Create a temporary file that acts as swap space. In this example it's a 1GB file at the root of the file system. This additional capacity is added to the existing swap space.
the middle command between the ; and ; is the vi commands that insert that line into the last line of the file, the esc with the carets is literally hitting the escape key, you have to have the smbfs package installed to do it, I use it to access my iTunes music on my mac from my linux PC's with amarok so I can play the music anywhere in the house. among other things, it allows you to access the files on that share from your computer anytime you're on that network.
Finds all directories containing more than 99MB of files, and prints them in human readable format. The directories sizes do not include their subdirectories, so it is very useful for finding any single directory with a lot of large files.