Mac OS X Commands +10 Common command-line tools

Source: Internet
Author: User

Many friends are scratching their heads at the command-line operations under OSX, most of which are expected to start touching computers in the Windows ERA. DOS-based should be seen to understand, and played Linux should be pro. This post hope to see the command line on the head of the Big Brother some help, the command is basically limited to install kext, modify the plist, replace the core of the operation encountered. If you want to learn more about UNIX commands, look for more articles on Linux commands online.
The Masters are free to read, but hope to pick fault, and then to add two sentences ...


OSX's File system
OSX uses the Unix file system, all the files are hanging in the directory/below, so there is no need to have the concept of the drive letter under Windows.
The hard drives you see on the desktop are hung under/volumes.
For example, after a mobile drive called USBHD, the desktop will show a hard disk icon, where is it actually?
Execute LS/VOLUMES/USBHD in the terminal to see if the contents of this mobile drive are displayed.

root directory location is/core Mach_kernel right here,
Drive Location/systme/library/extensions
User folder location/user/user name
The location of the desktop/user/user name/desktop

File wildcard character Asterisk *

Note: In UNIX systems, there is a difference between uppercase and lowercase characters, and A.txt is not equal to a.txt.
Root flag/Not dispensable, cd/system means to go to the system under the directory, and the CD system means to go to the system in the current directory


How to enter command line operation mode
In the graphical interface, open the Application utility terminal with the Finder
If even the graphical interface can not be entered (such as the wrong display driver), when the boot press F8, start with the-s parameter, and then enter the command MOUNT-UW/

Get permission
In order to prevent misoperation to destroy the system, then the user state when there is no permission operating system important files, so first to get root permissions
Then enter the password, enter the password without any echo, even the asterisk is not, just lose the return on the line.


Basic commands
List files
LS parameter directory name
Example: Want to see what is in the directory,
Want to see what's in the drive directory,
Parameter-W displays Chinese,-l details,-a including hidden files
Converting catalogs
Example: Think of a drive directory to stroll around

Create a new directory
mkdir Directory Name
Example: Create a backup directory in the driver directory
Build a backup directory on the desktop back up
mkdir/user/User name/desktop/backup

Copy files
CP parameter source file destination file
Example: Want to copy the desktop Natit.kext to the drive directory
Cp-r/user/User Name/desktop/natit.kext/system/library/extensions
The parameter R indicates a recursive operation of the directory, and Kext looks like a file under the graphical interface, which is actually a folder.
Back up all files in the drive directory to desktop backup
Cp-r/system/library/extensions/*/user/User name/desktop/backup

deleting files
RM parameter File
Example: To delete a driver's cache
Parameter-RF is recursive and mandatory, be careful to use, if executed RM-RF/your system is gone

Moving files
MV File
Example: Want to move Applehda.kext to the desktop
mv/system/library/extensions/applehda.kext/user/User name/desktop
Want to move the Applehda.kext to the backup directory

Change file permissions
chmod parameter Permission file
Example: Set all files in the drive directory to root read/write, other users read only
Chmod-r 755/system/library/extensions
The parameter R is recursive, and 755 represents the permissions of each user

Change file Owner
Chown parameter User: Group file
Example: Change all the files in the drive directory to the root user
Chown-r root:wheel/system/library/extensions
Parameter r indicates a recursive operation

Fix permissions on files throughout the system
Diskutil repairpermissions/
Strictly speaking, this is not a Unix command, but OSX is a software that remembers the modification or addition of the driver to execute once.

Text editing
Nano file name
Example: Edit Natit info.plist
After editing, use Ctrl +o to save, ctrl+x exit
Another text editing software is VI, the operation is a bit odd, cooked is very useful, and in all Unix-like systems, it is not afraid to go all over the world.

Run script command
SH Script file name
Example to modify the driver after all the required operations into a script, after the driver has been modified to run once this script is OK, convenient
1. Running Nano/clean in terminal
2. Paste the following code into the nano
Chown-r root:wheel/system/library/extensions
Chmod-r 755/system/library/extensions
Diskutil repairpermissions/
3. Ctrl +o disk, ctrl+x exit
4. Once the driver is moved, run it once in the terminal Sh/clean

Little Tricks

Use the Tab key to auto-complement commands
For example, think of the/system directory, enter the Cd/sy and then press the TAB key, the command will automatically fill into equal Cd/system

Manipulate files and directories with spaces in the name
Spaces are written in the command, for example, to enter My Documents, the command is CD My Documents

View detailed help for a command
Man command name
For example, to see the detailed use of the LS command, execute the man ls

Typical Operating Procedures
(assuming you've made a clean script, remember to sudo-s get system permissions before each operation)

Suppose you download a video card driver, the desktop decompression to get a natit.kext, how to do it?

For the sake of insurance, back up all the drivers first.
mkdir/user/User name/desktop/backup Create a backup folder on the desktop
Cp-r/system/library/extensions/*/user/User name/desktop/backup backup driver file

Now you can install it safely.
Cp-r/user/user name/desktop/natit.kext/system/library/extensions copy it to the system-driven directory location
Sh/clean Execute cleanup Script, Operation complete

Re-boot failed, into the desktop, found that should not be the driver, how to recover it?
Power on F8, start with-s parameter
Execute MOUNT-UW/
rm-rf/user/User name/desktop/natit.kext Delete this driver
Sh/clean Execute cleanup Script, Operation complete

Restart, back to the original state, do not forget Ah, no special effects how to do it, and heard the need to modify the Natit Info. plist file is fine.
Cp-r/user/user name/desktop/natit.kext/system/library/extensions copy it to the system-driven directory location
After editing, use Ctrl +o to save, ctrl+x exit
Sh/clean Execute cleanup Script, Operation complete

Restart, this time, the Carter effect has been, the sound card, God knows what will happen, we have to protect the existing results.
mkdir/user/User name/desktop/gooddrivers to create a directory for valid drivers
Cp-r/system/library/extensions/natit.kext/user/user name/desktop/gooddrivers backup

This sound card requires Applehda.kext to delete and edit the Appleazaliaaudio.kext in the Info.plist file, who knows later will not still use AppleHDA it, rather temporarily disable it.
mkdir/system/library/extensions/disabled Creating a disabled directory
Mv/system/library/extensions/applehda.kext/system/library/extensions/disabled move Past
After editing, use Ctrl +o to save, ctrl+x exit
Sh/clean Execute cleanup Script, Operation complete
Successful, but also put the modified driver back up


The command-line interface of Mac OS X is the basis of thousands of programs, which are often unknown to users. Relying on years of effort from the GNU Foundation and the open source community, Apple has designed an exceptional operating system that does not require the use of commands. While you don't have to use the command line for daily operations, the command line can save you a lot of time and occasionally make you laugh if used properly. I hope you can enjoy the 10 OS X command-line tools mentioned here!

1. SSH

This small "gem" is contained in every version of Mac OS X, which was originally developed to replace Rsh/rlogin and is now an integral part of the Linux/unix (including Mac OS X) community. The main function of OpenSSH is safe remote management. Open the System Preferences, click "Share", tick "remote login", you can start the Mac OS X built-in SSH service. Now if you want to connect to a computer that you're not around, you can connect your Mac's IP address by using a client like PuTTY (Windows platform) or by typing "ssh" into the terminal window of Mac OS x. After you sign in with your username and password, you get the full operation of the Mac OS X command line. In addition, OPENSSH has many applications, some of which are quite remarkable. I like to use SSH to get a SOCKS agent so I can surf the internet safely in public places. For more tips on using SSH on your Mac, you can browse this page!

2. Top

Top is another classic tool that has long been used for the Linux/unix community, using it to simply open the terminal input "top". In the blink of an eye, you'll see a window full of text-every process running on your MAC will be listed. If my Mac slows down, top is the first choice to let me know what's going on. Click here to see a complete overview of top.

3, Lsbom

If you accidentally find a cool enough new piece of software on a Mac site (like OS X Daily) that you can't help but want to install and you're hesitant, then Lsbom is good for you. With it, you can test the contents of your MAC OS X installation package (. pkg) and know exactly what's going to be plugged into your beloved file system. To use Lsbom, you need to start the terminal and enter the directory where the. pkg file resides. If your installation package is. DMG, you may need to copy the. pkg file to your desktop and then enter the Desktop directory. Once you have confirmed the location of the. pkg file, type "Lsbom .pkg/contents/> | More ". Wow! What you see is the complete list of files that will be installed by the new program.

4, say

This command is unique to Mac OS X and is more interesting than any other. Open terminal input "Say hello" try it!

5, Softwareupdate

The Softwareupdate command provides a quick and easy way to install Apple software updates. Open the terminal and enter "Softwareupdate-i-a", and your Mac will install all available updates. If you only want to install the "recommended" update, then enter "Softwareupdate-i-r".

6, Ipconfig

The fastest and easiest way to get your Mac IP address is definitely "ipconfig", just open terminal input "ipconfig". You can see a lot of information, including the MAC address of your network card. I like to enter "ipconfig | grep inet "Only rewards My computer's IP information. You can also disable a network connection by typing "ifconfig en0 down" (this gives an example of "En0"), and if you want to restore it, enter "ipconfig en0 up". This is a lot faster than using the system presets!

7, Lipo

Lipo is a tool that handles generic programs (Universal Binaries) in Mac OS x. Many (almost all) programs that are now on sale or available for download are marked with "Universal", meaning they both have code that PowerPC and Intel chips can handle. But since you probably don't care about one of them, you can use Lipo to "slim down" your program. For example, you want the Notes application to contain only Intel (i386) code:
Lipo I386-output
RM stickies
MV Stickies.i386 Stickies

8, Screencapture


PWD Displays the full path where the current file resides

Use shortcut keys to control restart, logoff, and sleep under Mac OS


If you want to reprint, please specify the source!
Author: Luo [email protected]

Immediately Reboot Mac OS X
Control + Command + Eject

Immediately Shutdown Mac OS X
Command + Option + Control + Eject

Immediately Log User out of Mac OS X
Control + Option + Shift + Q

Immediately Put Your Mac to Sleep
Command + Option + Eject (hold the buttons under for 2 seconds) and a bonus tip!

Immediately Shut Off Your Mac Display
Shift + Control + Eject

F12 is the eject key, long press can ...

Mac OS X Commands +10 Common command-line tools

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.