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:
get master info:
head -n 40 /home/db_bak.sql |awk '$0~/MASTER_LOG_FILE/
change master ??.
Copy a local directory to a remote server using ssh+tar (assume server is lame and does not have rsync).
this will tar/send/untrar a whole directory.
It requires https://jqplay.org/, that comes with brew: brew install jq
The files are automatically uncompressed when they reach the destination machine. This is a fast way to backup your server to your local computer while it's running (shutting down services is recommended).
A file named "exclude.txt" is needed at /tmp/ containing the following :
Should be the notify-send package installed
Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out
Provides a SOCKS5 proxy on localhost port 8080 which will tunnel all connections through srv1 and run in the background.
Tunneling an SSH session through TOR for anonymity.
Using openbsd's netcat.
Tested on Ubuntu 14.04
This also works with any proxy type: http, socks4 and socks5
For http proxy, replace -X 5 with -X connect
For socks4 proxy, replace -X 5 with -X 4 (DNS leak may occur)
Proxy host defined after -x
Replace -x localhost:9050 with proxy server of your choice
Copies files between hosts which don't have access to each other. It uses a proxy host which has access to both of them.
ssh from local to remote and pipe output of file to the local clipboard
While `sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH` "pulls" a directory from the remote server to the local host, the above command does the reverse and "pushes" a directory from the local host to the remote server.
This makes use of the "slave" option of sshfs which instructs it to communicate over plain stdin/stdout and the `dpipe` tool from vde2 to connect the sftp-server stdout to the sshfs stdin and vice-versa.
Copy changed files from remote git repository, _including binary ones_, staged and unstaged alike. Note that this command doesn't handle deleted files properly.
Securely stream a file from a remote server (and save it locally).
Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth.
This is an extension of snipertyler's idea.
Note: This command uses an encrypted connection, unlike the original.
I sue this in my .bashrc file
This will also do auto-completion for scp and sftp
If you are blocked or need to use a Socks proxy
The directories are created in the local host with the same structure below of a remote base directory, including the 'basedir' in case that it does not exists.
You must replace user and remotehost (or IP address) with your proper values
ssh will ask for the password of the user in remotehost, unless you had included properly your hostname in the remote .ssh/known_hosts file.
By adding this to your bashrc, when SSH'ing to a server while screen is active it will change the window tittle to the name of the server you going to.
The above is OK if you not worried about security, as per sshpass man pages:
" The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command."
So, instead what I do is use the -e option:
" -e The password is taken from the environment variable "SSHPASS"."