Monthly Archives: January 2013

Use rm to delete a directory

To delete a file or directory in terminal (command line) use the rm command.

Here is how to delete an entire directory:
rm -dfr directory

OPTIONS
-d, –directory
unlink FILE, even if it is a non-empty directory (super-user only)
-f, –force
ignore nonexistent files, never prompt
-i, –interactive
prompt before any removal
-r, -R, –recursive
remove the contents of directories recursively
-v, –verbose
explain what is being done
–help
display this help and exit
–version
output version information and exit

To remove a file whose name starts with a ‘-‘, for example `-foo’, use one of these commands:
rm -- -foo
rm ./-foo

To remove a file whose name contains a ‘*’ (or other special character), you will need to escape it. For example, I wanted to delete all directories starting with ‘~*w’:
rm -dfr ~\*w*

rsync via SSH

To copy files from one server to another via ssh:

First login to the destination server and cd to the directory that you want to copy files into.
Then type rsync -ave ssh username@sourceserver:directory/path/to/copy/ .
NOTE: don’t forget the ‘.’at the end. This is important.

On TextDrive (old FreeBSD servers), the exact path is:
rsync -ave ssh username@server.textdrive.com:domains/mydomain.com/public_html/ .

Expand tar file from Linux command line

If you have a file.tar.gz that you need to expand from the command line, type the following:
tar xfv file.tar.gz

Mac OS X Lion: Install Failed – Disk is Damaged

If you get this message, then your hard drive needs to be repaired. This can be difficult to solve because data may not be backed up and disk utility may not be able to repair your drive. Furthermore, our recovery options are now limited since we can’t buy Install DVD’s anymore. To make matters even worse, the installer creates a perceived loop that will not allow canceling installation or access to disk utility, terminal, or other options.

Here are the steps I followed to solve this issue:

  1. Try installing Lion and get ‘Install Failed – Disk is Damaged’ error
  2. Reboot computer and try installing again – same error (continued reboots do not allow access to install options, disk utility, or terminal; only reboot option)
  3. Reset PRAM to get out of infinite loop (rebooting, attempting to install, failing, …)
    • Turn off computer
    • Locate the following keys on the keyboard: Command (⌘), Option, P, and R. You will need to hold these keys down simultaneously in step 4.
    • Turn on the computer.
    • Press and hold the Command-Option-P-R keys before the gray screen appears.
    • Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    • Release the keys.
    • Now computer should boot normally into the installer
    • For more information, see Apple Support Article About NVRAM and PRAM
  4. I downloaded an installer image from the internet to perform my install. I then used disk utility to copy the files to a flash drive. To boot from this drive, I held option as my computer started and selected this drive. If you don’t have a bootable flash drive, then boot from any installer DVD that you do have.
  5. Go to the Utilities menu and select ‘Disk Utility’
  6. Try to repair the disk here. It may not work. If it doesn’t, then close Disk Utility and open Terminal
  7. When terminal opens, type fsck_hfs -rf /dev/disk0s2 and press return
  8. This may take up to 10-15 minutes, but it should repair your drive. When it is complete, restart your computer and try the installation again. These steps worked for me on a MacBook Air Original. NOTE: your drive may not be disk0s2, so if it is not, then try to lookup the actual drive path in Disk Utility or search on Google.

Mac OS X (10.6, 10.7, 10.8) Disk Utility repair failed

If Disk Utility is unable to repair hard drive, then try booting from any install DVD or USB drive. Then open terminal from the Utilities menu.

When terminal opens, type:
fsck_hfs -rf /dev/disk0s2

Your disk partition may be called something other than ‘disk0s2’. This process may take 10-15 minutes, but is more powerful than the regular Disk Utility repair option.