Posts filed under 'Tips & Tricks'
I often use the UNIX command line tool scp (secure copy) to copy a file to a remote server. However, scp has one major drawback: It doesn’t support resuming a transfer. So whenever I’m transferring a file and something comes up which interrupts my transfer–which is bound to happen–I’m cursing away at scp. The solution? Use rsync. It is overkill for most things I do, but when a transfer is interrupted, it is handy. Now, on to the doing.
I want to transfer the file “myFile” to the server “remoteMachine”, which I do with scp:
scp myFile remoteMachine:dirToPutIn/
(You should know this already if you’re reading this in the first place.)
(Muzak while the transfer is in progress; a loud wail and the sound of hair being torn out by its roots as the transfer comes to a grinding halt.)
Time to resume the file with rsync, which I do thusly:
rsync --partial --progress myFile remoteMachine:dirToPutIn/
The “–partial” argument is what does the trick. I added “–progress” because I like to see how the transfer is going; rsync understandably doesn’t show this by default as it is mostly used for purposes which don’t require live progress reporting (e.g. scheduled backups).
Because I know I’ll have this problem again at some point, I have created an alias in my shell’s (zsh) configuration file (~/.zshrc):
alias scpresume="rsync --partial --progress"
I know that rsync and scp are not necessarily related, but the name “scpresume” reflects the purpose of the task I wish to do. And getting it done is what matters the most after all.
Update:
Jan pointed out in a comment that rsync communication is not secure by default, and that you should use tunneling to achieve secure communication. Andi provides the solution which is quite simple: Use --rsh=ssh (use ssh as the remote shell). Thus, our alias from before would look like this:
alias scpresume="rsync --partial --progress --rsh=ssh"
April 5th, 2006
In System Preferences > Energy Saver, I have my display set to turn off after one minute. Since my iMac never goes to sleep, and it’s in my room, I prefer this setting. But it can get annoying when my display goes to sleep after one minute because I’m reading something and thus am not using the mouse or keyboard.
I tried finding a way to manually turn off the display (app, AppleScript, shell script, anything), but in vain. However, I stumbled upon a very simple workaround: Whenever I wish to prevent my display from going to sleep, I simply turn on the Visualizer in iTunes.
Note: This will not work if hide iTunes or disable the iTunes window, as both of these will stop the Visualizer.
February 27th, 2006
The other day I installed iLife ‘06. When it was done, the Dock quit but did not relaunch. To get it back, I would normally log out and back in. I didn’t want to do that in the middle of a DVD burn, and I didn’t want to wait either (duh! I’m an impatient, solution oriented geek).
Using the system without the Dock would normally have been pretty much impossible. However, I was running QuickSilver, so I just used that to lanch Opera. I googled, but wasn’t able to immediately find anything useful. Then it struck me that I’d seen the Dock in Activity Monitor running as an application, not a service or anything fancy.
So I fired up Terminal (again thanks to QS) and typed find / -name "Dock.app". And bingo, there it was: /System/Library/CoreServices/Dock.app/.
With that little piece of information, launching the dock was trivial:
open /System/Library/CoreServices/Dock.app/
There you have it. You know, just in case.
February 3rd, 2006
Sometimes it’s annoying that you can’t carry your iBook (and PowerBook/MacBook Pro I must assume) around in “clamshell” mode; that is with the lid closed, but not in sleep mode. When I wish to carry my iBook from e.g. my desk to a meeting room, I close the lid as much as possible without putting the iBook to sleep. I found out that the difference between too little and too much is the equivalent of the width of my thumb. Try it: Let your thumb rest (sideways) on the edge of the hand rest, then pull the lid down until it touches your thumb–my thumb has the perfect size, but your milage may vary. That’s it!
When I set up my blog, I created a category called “Tips & Tricks”. The idea was to supply exactly what the name says. This was very trivial but it’s a start and I hope someone can use it.
January 29th, 2006
I stumbled upon a nifty trick for quickly switching keyboard layouts in console mode on Linux: simply make the commands asdf and aoeu load Dvorak and Qwerty, respectively. I have seen different solutions using scripts and programs, but those are overkill and don’t fit my situation. I chose the simple way out by creating aliases in my shell’s settings:
alias asdf="xmodmap ~/.dvorak_layout"
alias aoeu="xmodmap ~/.norwegian_layout"
As I don’t use the standard Dvorak layout, I found it easier to do it with xmodmap than anything else; I used it before and it works well. I created the Norwegian layout file (the actual layout of my keyboard is Norwegian) to keep it simple and consistent. This way, anyone who needs to type on my computer doesn’t get lost.
September 10th, 2005