Monday, October 22, 2012

Mac OSX Terminal : Unmount


force unmount on mac os x

Inspired by: http://loopkid.net/articles/2008/06/27/force-unmount-on-mac-os-x

When using Mac OS X you might have encountered this message.
The disk "foobar" is in use and could not be ejected.
Try quitting appplications and try again.
This message may occur even if you have all closed all programs. The guilty party for this behavious may be Leopard’s FSEvents, which sometimes has a lock on a volume. To force the unmount of a volume just open a Terminal and use umount.
sudo umount -f /Volumes/FooBar
According to a commentator, if that doesn’t work you can also try
sudo diskutil umount force /Volumes/FooBar

Mac OSX Terminal : Prevent your mac from falling asleep


caffeinate -i -s /bin/ssh ...
Explanation:
-i - Prevent idle sleep.
-s - Prevent system sleep (entirely, even if you close the lid). Note: it only works while on AC power.
/bin/ssh - Just keep writing the command you want to execute. Using ssh directly instead of/bin/ssh should also work.
Results: Your system will not sleep as long as the ssh command is running.

Mac OSX Terminal : How to rename a file or folder


You need to use the mv command to rename a folder under UNIX operating systems. You must have write permission for all folders.

Syntax

The syntax is as follows:
mv old-folder-name new-folder-name
mv /path/to/old /path/to/new

Example

In this example, a folder called drivers is renamed as olddrivers. Open a terminal (shell prompt) and type the following commands:
ls
mv drivers oldrivers
ls

Mac OSX Terminal Commands : Ways to search for a file


1) find : To search for files on the command line you can use the command “find”. The following is syntax for the “find” command:
find path criteria action
“path” - The section of the files system to search (the specific directories and all the sub directories). If nothing is specified the file system below the current directory is used.
“criteria” - The file properties.
“action” - Options that influence conditions or control the search as a whole, ie,
“–print”

2) locate : The command “locate” is an alternative to the command “find -name”. The command find must search through the selected part of the file system, a process that can be quite slow. On the other hand, locate searches through a database previously created for this purpose (/var/lib/locatedb), making it much faster. The database is automatically created and updated daily. But change made after the update has been performed are not taken into account by locate, unless the database is updated manually using the command updatedb.

3) whereis : The command “whereis” returns the binaries (option -b), manual pages (option -m), and the source code (option -s) of the specific command. If no options is used all the information is returned, if the information is available. This command is faster than “find” but is less thorough.

4) which : The “which” command searches all paths listed in the variable PATH for the specific command and returns the full path of the command. the command is specifically useful if several version of a command exist in different directories and you want to know which version is executed when entered without specifying a path.

5) type : The “type” command can be used to find out what kind of command is executed when command is entered - a shell built in command or an external command. The option -a delivers all instances of a command bearing this name in the file system.