Mac OS terminal command Summary

Source: Internet
Author: User
Tags dbx

How to enter the command line operation mode
Then, use the finder to open the application utility terminal.
If you cannot connect to the graphic interface (for example, if you have installed an incorrect display driver), press F8 at startup, start with the-s parameter, and then enter the command mount-uw/

Get Permissions
In order to prevent misoperation and damage to the system, if the user does not have the permission to operate important files of the system, the user must first obtain the root permission.
Sudo-s
Then enter the password. When you enter the password, there is no echo and no star number. Just press Enter.
----------------------------------------------
Basic commands
List objects
Ls parameter directory name
For example, I want to see what is in the directory,
Ls/
Want to see what is in the driver directory,
Ls/System/Library/Extensions
Parameter-w displays Chinese characters,-l details,-a includes hidden files
Conversion directory
Cd
For example, think of a loop in the driver directory.
Cd/System/Library/Extensions
Create a new directory
Mkdir directory name
For example, create a backup directory backup under the driver directory.
Mkdir/System/Library/Extensions/backup
Create a backup directory backup on the desktop
Mkdir/User name/Desktop/backup
Copy an object
Cp parameter source file target file
For example, you want to copy the Natit. kext file on the desktop to the driver directory.
Cp-R/User name/Desktop/Natit. kext/System/Library/Extensions
The R parameter indicates recursive operation on the directory. kext looks like a file on the GUI, but actually a folder.
Back up all files in the driver directory to the desktop backup
Cp-R/System/Library/Extensions/*/User name/Desktop/backup
Delete an object
Rm parameter file
For example, you want to delete the driver cache.
Rm-rf/System/Library/Extensions. kextcache
Rm-rf/System/Library/Extensions. mkext
Parameter-rf indicates recursion and force. Be careful when using this parameter. If you run rm-rf/your system, it's all gone.

Move files
Mv File
For example, you want to move AppleHDA. Kext to the desktop.
Mv/System/Library/Extensions/AppleHDA. kext/User name/Desktop
I want to move AppleHDA. Kext to the backup directory.
Mv/System/Library/Extensions/AppleHDA. kext/System/Library/Extensions/backup
Change File Permissions
Chmod parameter permission File
For example, set all files in the driver directory to root for read and write, while other users are read-only.
Chmod-R 755/System/Library/Extensions
The R parameter indicates recursion, and 755 indicates the permissions of each user.
Change file owner
Chown parameter User: group file
For example, change the owner of all files in the driver directory to the root user.
Chown-R root: wheel/System/Library/Extensions
The R parameter indicates recursive operation.
Fix file permissions in the entire system
Diskutil repairpermissions/
Strictly speaking, this is not a unix Command, but an osx software. Remember to modify or add the driver and execute it once.
Text editing
Nano file name
For example, edit natit Info. plist.
Nano/System/Library/Extensions/Natit. kext/Info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
Another text editing software is vi, which has some odd operations and is very easy to use. It is also used in all Unix-like systems.
Run the script command
Sh script file name
For example, after the driver is modified, all required operations are saved as a script. After the driver is modified, you only need to run the script once.
1. Run nano/clean in the terminal
2. paste the following code into nano.
Rm-rf/System/Library/Extensions. kextcache
Rm-rf/System/Library/Extensions. mkext
Chown-R root: wheel/System/Library/Extensions
Chmod-R 755/System/Library/Extensions
Diskutil repairpermissions/
Kextcache-k/System/Library/Extensions/
3. Press Ctrl + O to save the disk, press Ctrl + X to exit
4. Run sh/clean once on the terminal as long as the driver is activated.
------------------------------------
Tips
Use the Tab key to automatically complete the command
For example, enter cd/Sy in the/System directory and press the Tab key. The command is automatically merged into cd/System.
Operate files and directories with spaces in names
The space is written as a space in the command. For example, to enter My Documents, the command is cd My Documents ENTs.
View Detailed Help of commands
Man command name
For example, to view the detailed usage of the ls command, execute man ls
------------------------------------
Typical operation process
(Assuming that the cleanup script has been prepared, remember that sudo-s obtained the system permission before each operation)
Assume that you have downloaded a graphics card driver Natit.zip and obtained a Natit. kext file from the desktop. How can this problem be solved?
To be safe, back up all drivers first.
Mkdir/User name/Desktop/backup create a backup folder on the Desktop
Cp-R/System/Library/Extensions/*/User name/Desktop/backup driver File
Now you can install it with peace of mind.
Cp-R/User name/Desktop/Natit. kext/System/Library/Extensions copy it to the System driver directory
Sh/clean: Execute the cleanup script. The operation is complete.
An error occurred while restarting the desktop. I found that the driver should not be installed. How can I restore it?
Press f8. start with the-s parameter.
Run mount-uw/
Rm-rf/User name/Desktop/Natit. kext Delete this driver
Sh/clean: Execute the cleanup script. The operation is complete.
Restart and return to the original status. Don't worry. How can I do without special effects? I heard that I need to modify the Info. plist file of Natit.
Cp-R/User name/Desktop/Natit. kext/System/Library/Extensions copy it to the System driver directory
Nano/System/Library/Extensions/Natit. kext/Info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
Sh/clean: Execute the cleanup script. The operation is complete.
Restart. By the way, all the video effects are available. It's time to get the sound card. You know what will happen, and you have to protect the existing results.
Mkdir/User name/Desktop/gooddrivers create a directory for the effective driver
Cp-R/System/Library/Extensions/Natit. kext/User name/Desktop/gooddrivers backup
This sound card requires that AppleHDA. kext be deleted and edited. Who knows if AppleHDA will be used in the future.
Mkdir/System/Library/Extensions/disabled
Mv/System/Library/Extensions/AppleHDA. kext/System/Library/Extensions/disabled move past
Nano/System/Library/Extensions/Natit. kext/AppleAzaliaAudio. kext/Info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
Sh/clean: Execute the cleanup script. The operation is complete.
Now, back up the modified driver.
Copy the content to the clipboard code:

The following is a unix Command Line for your reference.
Directory operations
Command name
Function Description
Example
Mkdir
Create a directory
Mkdir dirname
Rmdir
Delete a directory
Rmdir dirname
Mvdir
Move or rename a directory
Mvdir dir1 dir2
Cd
Change current directory
Cd dirname
Pwd
Display the path name of the current directory
Pwd
Ls
Display the content of the current directory
Ls-la
Dircmp
Compare the contents of two directories
Dircmp dir1 dir2
File Operations
Command name
Function Description
Example
Cat
Display or connect files
Cat filename
Pg
Display file content by PAGE formatting
Pg filename
More
Split-screen display of File Content
More filename
Od
Show non-text file content
Od-c filename
Cp
Copy a file or directory
Cp file1 file2
Rm
Delete a file or directory
Rm filename
Mv
Change the file name or directory
Mv file1 file2
Ln
Join File
Ln-s file1 file2
Find
Search for files using matching expressions
Find.-name "*. c"-print
File
Display file type
File filename
Select Operation
Command name
Function Description
Example
Head
Display the first few lines of the file
Head-20 filename
Tail
Display the last few lines of the file
Tail-15 filename
Cut
Display certain fields in each row of a file
Cut-f1, 7-d:/etc/passwd
Colrm
Delete several columns from standard input
Colrm 8 20 file2
Paste
Horizontally connected File
Paste file1 file2
Diff
Compare and display the differences between the two files
Diff file1 file2
Sed
Non-interactive stream Editor
Sed "s/red/green/g" filename
Grep
Search by mode in files
Grep "^ [a-zA-Z]" filename
Awk
Find and process the mode in the file
Awk '{print $1 $1}' filename
Sort
Sort or merge files
Sort-d-f-u file1
Uniq
Remove duplicate rows from the file
Uniq file1 file2
Comm
Display public and non-public rows of two ordered files
Comm file1 file2
Wc
Number of characters, words, and lines in the Statistical File
Wc filename
Nl
Add the row number to the file
Nl file1> file2
Security Operations
Command name
Function Description
Example
Passwd
Change User Password
Passwd
Chmod
Change file or directory permissions
Chmod ug + x filename
Umask
Define the permission mask of the created File
Umask 027
Chown
Change the owner of a file or directory
Chown newowner filename
Chgrp
Change the group of a file or directory
Chgrp staff filename
Xlock
Lock the terminal
Xlock-remote
Programming
Command name
Function Description
Example
Make
Maintain the latest version of the executable program
Make
Touch
Update file access and modification time
Touch-m 05202400 filename
Dbx
Command line interface debugging tool
Dbx a. out
Xde
Graphical User Interface debugging tool
Xde a. out
Process operations
Command name
Function Description
Example
Ps
Display current process status
Ps u
Kill
Terminate a process
Kill-9 30142
Nice
Change the priority of the command to be executed
Nice cc-c *. c
Renice
Change the priority of a running process
Renice + 20 32768
Time Operation
Command name
Function Description
Example
Date
Displays the current date and time of the system.
Date
Cal
Show Calendar
Cal 8 1996
Time
Statistical Program Execution time
Time a. out
Network and communication operations
Command name
Function Description
Example
Telnet
Remote Login
Telnet hpc.sp.net.edu.cn
Rlogin
Remote Login
Rlogin hostname-l username
Rsh
Run the specified command on the remote host
Rsh f01n03 date
Ftp
Transfers files between the local host and remote host
Ftp ftp.sp.net.edu.cn
Rcp
Copy files between the local host and remote host
Rcp file1 host1: file2
Ping
Send a Response Request to a network host
Ping hpc.sp.net.edu.cn
Mail
Read and send emails
Mail
Write
Send messages to another user
Write username pts/1
Mesg
Allow or reject receiving packets
Mesg n
Korn Shell command
Command name
Function Description
Example
History
Lists the commands and numbers that have been executed recently.
History
R
Repeat the execution of a recent command.
R-2
Alias
Define an alias for a command
Alias del = rm-I
Unalias
Cancels the definition of an alias.
Unalias del
Other commands
Command name
Function Description
Example
Uname
Displays information about the operating system.
Uname-
Clear
Clear screen or window content
Clear
Env
Display All currently set Environment Variables
Env
Who
List all users currently logged on
Who
Whoami
Displays the username currently performing the operation
Whoami
Tty
Display terminal or Pseudo Terminal name
Tty
Stty
Display or reset control key definitions
Stty-
Du
Query disk usage
Du-k subdir
Df
Displays the total space and available space of the file system.
Df/tmp
W
Displays the total information of the current system activity.

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: info-contact@alibabacloud.com 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.