Check These Out
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22)
(all files & folders on destination server/folder will be deleted)
Print 0 through 99, each on a separate line.
This command will let you just type c-a b (which means press 'ctrl' then 'a' then 'b'), and screen will save your copy buffer to /tmp/screen-exchange, and then execute xsel to copy the contents of that file into the system's X clipboard.
1. Install Conrad Parker's xsel from http://www.vergenet.net/~conrad/software/xsel/
2. Add these lines to your .screenrc
# Add cool line to make copying to x clipboard possible.
# This binds C-a b to copy screen's copy buffer to the system clipboard.
bind b eval writebuf 'exec /bin/sh -c "xsel -i -b < /tmp/screen-exchange"' 'exec /bin/sh -c "killall xsel"'
3. Restart screen.
4. Test it by typing c-a [ to enter copy mode.
5. Select some text using vi movement keys (h, j, k, l, etc...) and starting your selection by hitting the space bar, moving with vi movement keys, and then ending your selection with the space bar.
6. Type C-a b, and screen will use xsel to copy your screen copy buffer to the system's X clipboard buffer.
7. Then you can paste the screen copy buffer into any X program.
Note: If you're using Mac OSX, you can use pbcopy instead of xsel.
Also Note: The second exec in the .screenrc file, which runs killall on xsel, is necessary, because even when you redirect a file to xsel, xsel waits for you to press ctrl-c to kill it, and have it stop waiting for more input. Since xsel forces screen to wait, and I don't want to press ctrl-c, I send the equivalent of ctrl-c with killall causing xsel to write /tmp/screen-exchange to the X clipboard, and then exit. It's a hack, but it works. If you know how to get this to work without a lame hack leave a comment explaining how.
lists files and folders in a folder with summary.
Sometimes commands give you too much feedback.
Perhaps 1/100th might be enough. If so, every() is for you.
$ my_verbose_command | every 100
will print every 100th line of output.
Specifically, it will print lines 100, 200, 300, etc
If you use a negative argument it will print the *first* of a block,
$ my_verbose_command | every -100
It will print lines 1, 101, 201, 301, etc
The function wraps up this useful sed snippet:
$ ... | sed -n '0~100p'
don't print anything by default
$ sed -n
starting at line 0, then every hundred lines ( ~100 ) print.
$ '0~100p'
There's also some bash magic to test if the number is negative:
we want character 0, length 1, of variable N.
$ ${N:0:1}
If it *is* negative, strip off the first character ${N:1} is character 1 onwards (second actual character).
The PID will only be printed if you're holding a root equivalent ID.
(here is character '+' repeated 80 times)
Sometimes needed to enhance the title of the script.
Create a persistent SSH connection to the host in the background. Combine this with settings in your ~/.ssh/config:
Host host
ControlPath ~/.ssh/master-%r@%h:%p
ControlMaster no
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.