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:
Takes a screenshot of x11 and pipes it over ssh to the preview application on a mac. Requires imagemagick on the server side.
This command will ask for remote sudo password before executing a remote command.
There must be no space between -p and the password
This is just a quick and dirty way to play remote audio files *locally* in your PC.
The best way is to mount the remote Music directory into the local FS, say by using sshfs:
sshfs user@remote:/remote/music/dir/ /mnt/other_pc/
This creates an archive that does the following:
(Everyone seems to like -z, but it is much slower for me)
-a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
-H: preserves hard-links
-A: preserves ACLs
-X: preserves extended attributes
-x: don't cross file-system boundaries
-v: increase verbosity
--numeric-ds: don't map uid/gid values by user/group name
--delete: delete extraneous files from dest dirs (differential clean-up during sync)
--progress: show progress during transfer
-T: turn off pseudo-tty to decrease cpu load on destination.
-c arcfour: use the weakest but fastest SSH encryption. Must specify "Ciphers arcfour" in sshd_config on destination.
-o Compression=no: Turn off SSH compression.
-x: turn off X forwarding if it is on by default.
Flip: rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" [source_dir] [dest_host:/dest_dir]
When your ssh session hanged (probably due to some network issues) you can "kill" it by hitting those 3 keys instead of closing the entire terminal.
Alternative for machines without ssh-copy-id
Requires software found at: http://lpccomp.bc.ca/remserial/
Remote [A] (with physical serial port connected to device)
./remserial -d -p 23000 -s "115200 raw" /dev/ttyS0 &
Local [B] (running the program that needs to connect to serial device)
Create a SSH tunnel to the remote server:
ssh -N -L 23000:localhost:23000 user@hostwithphysicalserialport
Use the locally tunnelled port to connect the local virtual serial port to the remote real physical port:
./remserial -d -r localhost -p 23000 -l /dev/remser1 /dev/ptmx &
Example: Running minicom on machine B using serial /dev/remser1 will actually connect you to whatever device is plugged into machine A's serial port /dev/ttyS0.
Super fast way to ftp/telnet/netcat/ssh/ping your loopback address for testing. The default route 0.0.0.0 is simply reduced to 0.
Cleaned up and silent with &>/dev/null at the end.
Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system.
Maybe there's an easier way to set a timeout in the ssh options...
Run this within a steady screen session.
You can get the approximate time when the remote server went down or other abnormal behavior.
This will check if a user is logged in using ssh and will log out the user automatically after the specified time in seconds without data retrieval on the server side.
Will work with bash and zsh so put it into your sourced shell file on the server side.
Be aware that users can change this themselves as it's just a envoronment variable.
This command adds your pem key to SSH so that you no longer have to manually specify it when connecting to EC2 instances.
# you can do this:
# instead of this:
ssh -i ~/.ssh/KEY_PAIR_NAME.pem ec2-instance.amazonaws.com
ssh compresion -C option ...
on slow connection VNC performs better but in local LAN native secure X protocol is an option
if you use tmux and wish to automatically reattach you previously detached sessions when logging in.
Example: remote install an application(wine).
sshpass -p 'mypssword' ssh -t firstname.lastname@example.org "echo 'mypassword' | sudo -S apt-get install wine"
Tested on Ubuntu.
Use as: $ s host1
Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN.
Adapted from Hack 34 in Linux Server Hacks 2nd Addition.
You can ran this also with cat for example:
tar zcvf - /folder/ | ssh email@example.com "cat > /dest/folder/file.tar.gz"
Or even run other command's:
tcpdump | ssh firstname.lastname@example.org "cat > /tmp/tcpdump.log"