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:
Watch is a very useful command for periodically running another command - in this using mysqladmin to display the processlist. This is useful for monitoring which queries are causing your server to clog up.
In this case it's better do to use the dedicated tool
I did not know this, i'd like to share...
If you enable multiuser, then you can permit others to share your screen session. The following conditions apply:
1. screen must be suid root;
2. "multiuser on" must be configured in ~/.screenrc;
3. control the others user(s) access with "aclchg":
# ----- from ~/.screenrc-users -----
aclchg someuser +rx "#?" #enable r/o access to "someuser"
aclchg someuser -x "#,at,aclchg,acladd,acldel,quit" # don't allow these
aclchg otheruser +rwx "#?" # enable r/w access to "otheruser"
aclchg otheruser -x "#,at,aclchg,acladd,acldel,quit" # don't allow them to use these commands
After doing this (once), you start your session with:
Then, the other user can join your terminal session(s) with youruserid:
$ screen -r youruserid/
Note: the trailing "/" is required.
Multiple users can share the same screen simultaneously, each with independent access controlled precisely with "aclchg" in the ~/.screenrc file.
I use the following setup:
# default screenrc on any host
Then, the base configurations are in ~/.screenrc-base; the host-specific configurations are in ~/.screenrc-$HOST, and the user configurations are in ~/.screenrc-users.
The host-specific .screenrc file might contain some host-specific screen commands; e.g.:
screen -t 'anywhere' /bin/tcsh
screen -t 'anywhere1' /bin/tcsh
The .screenrc-base contains:
## I find typing ^a (Control-a) awkward. So I set the escape key to CTRL-j instead of a.
termcapinfo xterm* ti@:te@:
Create a persistent SSH connection to the host in the background. Combine this with settings in your ~/.ssh/config:
All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won't create a new socket each time to open an ssh connection.
Read 32GB zero's and throw them away.
How fast is your system?
The biggest advantage of this over the functions is that it is portable.
Of course you need to be able to access host A for this ;-)
Usage: cmdfu hello world
'dpkg -S' just matches the string you supply it, so just using 'ls' as an argument matches any file from any package that has 'ls' anywhere in the filename. So usually it's a good idea to use an absolute path. You can see in the second example that 12 thousand files that are known to dpkg match the bare string 'ls'.
Also works with:
chgrp --reference file1 file2
chown --reference file1 file2
It deletes all removed files, updates what was modified, and adds new files.
Directly attach a remote screen session (saves a useless parent bash process)
This command shows the various shortcuts that can be use in bash, including Ctrl+L, Ctrl+R, etc...
You can translate "\C-y" to Ctrl+y, for example.
parse `lsmod' output and pass to `dot' drawing utility then finally pass it to an image viewer
You can get one specific line during any procedure. Very interesting to be used when you know what line you want.
If you use Mac OS X or some other *nix variant that doesn't come with ssh-copy-id, this one-liner will allow you to add your public key to a remote machine so you can subsequently ssh to that machine without a password.
Good for one off jobs that you want to run at a quiet time. The default threshold is a load average of 0.8 but this can be set using atrun.
Nothing special required, just wget, sed & tr!
run 'nc yourip 5000', 'nc yourip 5001' or 'nc yourip 5002' elsewhere will produce an exact same mirror of your shell. This is handy when you want to show someone else some amazing stuff in your shell without giving them control over it.
This command takes a snapshot of the open files for a PID 1234 then waits 10 seconds and takes another snapshot of the same PID, it then displays the difference between each snapshot to give you an insight into what the application is doing.
Remove security from PDF document using this very simple command on Linux and OSX. You need ghostscript for this baby to work.
The empty file /forcefsck causes the file system check fsck to be run next time you boot up, after which it will be removed.
This works too: