This post follows up on the previous 2 posts. Here we will look at some advanced commands. Note that this is by no means a comprehensive list. You can visit the online version of the man pages: Apple Man Pages
Here are the links for the previous posts.
Terminal Commands – Part 1
Terminal Commands – Part 2
The commands are explained with some common tasks in mind. Some of the steps are there to illustrate the usage of the commands. To find out other tasks that can be performed using these commands simply refer to the man pages.
The diskutil command is a handy tool to run disk utility via the terminal. A full list of tasks that can be executed are available via the man command.
There could be situations where you have encrypted your USB drive & have forgotten the password for the same. While there is no way to retrieve the data, it is still possible for you to use the USB disk. Let’s use the diskutil command to do this.
– Launch terminal
– Make sure that the USB is properly connected
– Run the command diskutil cs list
– This lists all the core-storages that are connected to your system.
– Next to the Logical Volume Group select the alphanumeric id & copy it (make sure you select the correct logical volume group).
– Type the command diskutil cs delete <id>
– Replace the id with the alphanumerics id you copied earlier.
– This will completely remove the encrypted partition. As mentioned earlier you will loose all the data that is already there on the partition.
diskutil man page
File System Check command. This command is used to check different Filesystems by invoking the corresponding sub command.
fsck man page
hdiutil is used to perform some other tasks related to storage devices. A good example of this is the creation of different kinds of disk images.
Let us create a disk image for the ~/Documents directory
– Launch the terminal application
– cd ~/
– mkdir ImageDemo
– hdiutil create -srcfolder ImageDemo ImageDemo.dmg
Apart from the above example, there are a lot of other tasks that can be performed using hdiutil. For full information run the man command.
hdiutil man page
The mount command is used to mount a volume via the terminal. A volume can be mounted as a Read-Write or a read only. For full details on the functionality run the man mount command
Syntax: mount <options> <volume location>
mount man page
GETTING INFORMATION RELATED TO THE SYSTEM & FILES
Shows how long the system has been running.
uptime man page
Get information out of the io registry.
Suppose we want to get information about the serial number. We would use the ioreg command.
– launch terminal
– cd ~/Documents
– ioreg -l | grep “IOPlatformSerialNumber”
Optionally you can pipe the information to a file & read it later.
ioreg man page
Used to get system related information. it can generate a small or a detailed report depending on what option is used. For full information access the man pages for the command.
system_profiler man page
Displays information about the various processes running within the system including the usage 7 state. To get more information about the full functionality visit the man pages.
top man page
Used to get the metadata for a given file or folder. The data is displayed on the screen.
mdls man page
Manages spotlight search indexes.
mdutil man page
This command is used to access the information that is found within the System Preferences > Network Preferences pane.
You can use this command to do some quick command line configuration of the network settings.
A good example is to manually configure the settings while booted in the OS X Recovery partition. Here is an Apple Support Document which talks about the same.
networksetup man page
Used to compress file(s) into a single tar file or decompress.
This example demonstrates how to use the tar command.
– Launch terminal
– cd ~/Documents
– mkdir Docs
– cd Docs
– echo “A” | cat > file1
– echo “A” | cat > file2
– echo “A” | cat > file3
– echo “A” | cat > file4
Now to compress all the files
– tar -cvf compressedFiles.tar file*
To uncompress them all
– tar -xvf compressedFiles.tar
tar man page
Manage Time machine from the terminal. Useful command to manage time machine from the command line.
tmutil man page
Used to mange file-vault from the command line
fdesetup man page