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.
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.
FILE SYSTEM
diskutil
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.
Example:
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.
fsck
File System Check command. This command is used to check different Filesystems by invoking the corresponding sub command.
hdiutil
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.
Example:
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.
mount
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>
GETTING INFORMATION RELATED TO THE SYSTEM & FILES
uptime
Shows how long the system has been running.
ioreg
Get information out of the io registry.
Example:
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.
system_profiler
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.
top
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.
METADATA
mdls
Used to get the metadata for a given file or folder. The data is displayed on the screen.
mdutil
Manages spotlight search indexes.
NETWORKING
networksetup
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.
http://support.apple.com/kb/HT5034?viewlocale=en_US
MISCELLANEOUS
tar
Used to compress file(s) into a single tar file or decompress.
Example:
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
tmutil
Manage Time machine from the terminal. Useful command to manage time machine from the command line.
fdesetup
Used to mange file-vault from the command line
Saved as a favorite, І reɑlly like your site!
Pingback: Configuring an SVN Server on OS X on your Local Network | Arun Patwardhan's Blog
Pingback: Configuring/Troubleshooting OS X Using Command Line | Arun Patwardhan's Blog
Pingback: Automation on the Mac | Arun Patwardhan's Blog
Pingback: Automation on the Mac | Arun Patwardhan's Blog
Pingback: Useful scripts for macOS | Arun Patwardhan's Blog
Pingback: List of macOS Terminal commands | Arun Patwardhan's Blog
Here is another article for your reference: https://arunpatwardhan.com/2020/07/29/list-of-macos-terminal-commands/