Archives: May 2009

How to access HFS+ formatted HDD from a Windows PC?

There are several ways you can access a Mac HDD from Windows PC. If you have a Mac and a PC you can activate the File Sharing in System Preferences on your Mac and you are ready to go. The Mac should appear under network. You can make the process easier by mapping the network drive.

If you don’t have access to a Mac but want to connect to a HFS+ formatted HDD, there are two possibilities.

  1. Read only access
  2. Download the HFSExplorer from catacombae. To mount the HFS+ partition you should select the “Run HFSExplorer in Administrator mode”. As mentioned above this tool can only read.

  3. Read and write access
  4. MacDrive7(MacDrive 8 is coming soon) is a commercial software that can both read and write a HFS+ formatted HDD. You can download a trial version from their website.

Synchronize folders using rsync and ssh

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Rsync finds files that need to be transferred using a “quick check” algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data does not need to be updated.

By combining rsync with ssh it is really easy to securely synchronize folders.

To sync a remote folder with a local folder, use the following command.

rsync -avze ssh /localpath(source)/ user@remoteaddress:/remotepath/(destination)

Note that this will update the remote path not the other way around.
Eg.

rsync -avze ssh /User/john/Documents/ me@remote.com:/home/me/Documents/

The above method won’t remove any files existing on the remote path, which are not on the local path. If you also want to remove files/folders if they are not existing on the local path, use the following command.

rsync -avze ssh --delete /localpath/ user@remoteaddress:/remotepath/

Shutdown your Mac using a terminal command

The shutdown command comes in handy if you want to shutdown or reboot your Mac at a specific time. Here are some of the examples. You should be a super user to use these commands.

sudo shutdown [options] when [message]

Some examples.
Shutdown immediately:

sudo shutdown -h now

Restart immediately:

sudo shutdown -r now

Shutdown at 9 pm:

sudo shutdown -h 21:00

Shutdown in 5 minutes:

sudo shutdown -h +5

Restart immediately

sudo reboot

Shutdown immediately

sudo halt

If you are not an admin user non of the above commands are going to help. If that’s the case try the following commands.
Shutdown immediately:

osascript -e 'tell application "System Events" to shut down'

Restart immediately:

osascript -e 'tell application "System Events" to restart'

Sleep:

osascript -e 'tell application "System Events" to sleep'

Logout:

osascript -e 'tell application "System Events" to log out'

Setup a secure ftp server for remote access on OS X

Recently quite a number of forum members asked about how to transfer large file between remote locations. The online services such as DropBox and Wuala do a good job but if you already have a Mac or a Linux machine, it is so much easier and also secure to setup your own FTP (File Transfer Protocol) server using vsftpd (Very Secure File Transfer Protocol Daemon). In this article I will try to guide you through the entire setup process. Lets get started, shall we?

  1. First you need to install the vsftpd using Mac Ports. Open the Terminal.app, enter the following command and hit Enter. If you don’t have Mac Ports installed, get it from here.
  2. sudo port install vsftpd
  3. Now you have to create a vsftpd.config file which defines the rules to secure your ftp server. Fortunately, when you install vsftpd using Mac Ports, it will create a sample config file at /opt/local/etc/ directory. Use the following command to create a config file from the sample file.
  4. sudo cp /opt/local/etc/vsftpd.config.sample /opt/local/etc/vsftpd.config
  5. Open the vsftpd.config file on any editor and make the following changes.
  6. sudo vim /opt/local/etc/vsftpd.config

    To deny access to anonymous users, activate
    anonymous_enable=NO

    To allow local users to access their home directories
    local_enable=YES

    Add a welcome message
    ftpd_banner=Welcome to my FTP service!

    Lock the users in their root directories
    chroot_local_user=YES

    There are several other settings you could activate/deactivate on the config file. Do as it fits.

  7. To run the server, use the following command
  8. sudo /opt/local/sbin/vsftpd

    If you have done everything correctly so far the server should be up and running.

  9. To do an initial test try the following command in a separate tab.
  10. ftp 192.168.1.2

    Replace the ip address with your local ip address.
    This should ask you for a user name and password. Try the user name and the password you use for log-in to your Mac.

  11. Next step is to enable users to access your newly setup FTP server from a remote location. For this you need a service such as DynDNS or No-IP. You can sign-up for a free account with both providers. Once the registration is completed, go ahead and add a new host as shown in the following example.
  12. dyndns

    Do not forget to activate the service.

    If you have done everything correctly, you should be able to connect to the newly set up ftp server from any remote location.

    In case if you have a router in your home network don’t forget to do a port forward.

    That’s all. ;)
    Let me know how it went.

How to use the OS X built-in screen capture utility?

If you haven’t discovered yet, there is nice OS X hidden gem called screen capture, which could be quit useful taking snapshots of your screen. If you want to take a screen shot of the full screen press Command + Shift + 3. For a selected area, press Command + Shift + 4 and highlight the area. By default the images are saved in PNG format. If you want to change the format type the appropriate command in the Terminal.app and press enter. Here are some examples.

  • defaults write com.apple.screencapture type pdf
  • defaults write com.apple.screencapture type png
  • defaults write com.apple.screencapture type jpg
  • defaults write com.apple.screencapture type tif
  • You may have to restart the Mac to take the command into effect.

    Creating Aliases for the Terminal.app

    If you are using certain commands on the Terminal.app in a regular basis, it is a good ideal to create aliases to increase your productivity. Here is how you do it.

    1. Open the Terminal.app from Applications > Utilities > Terminal.app
    2. To create/Open .bashrc, type
      vim .bashrc
    3. Press i to change vim to edit mode and go the the end of the file.
    4. Add any aliases you like as shown below
    5. alias v='vim'
      alias lla ='ls -al'
      alias ..='cd ..'
      alias ...='cd .. ; cd ..'
    6. Press Esc, type :wq to save and exit vim.
    7. To see all your existing aliases, type
      alias

      and press enter.

    Happy coding!