Mac _ terminal command

Source: Internet
Author: User
Tags dbx disk usage

Mac _ terminal command

Mac OS uses Unix file systems

The root directory is/
Driver location/System/Library/Extensions
User folder location/Users/User Name
Desktop location/Users/user name/Desktop
The file wildcard is asterisk *
Note: In the unixsystem, A. txt is not the same as a.txt.
How to enter the command line operation mode

Open the Application> utility> terminal with finder in the graphic interface

Or open Spotlight and enter terminal or terminal]

List files and folders in a directory

Ls/System/Library/Extensions

Parameter-w displays Chinese characters,-l details,-a includes hidden files

. Kext looks like a file in the graphic interface. It is actually a folder.

 

Switch directory

For example, if you want to switch to the user directory under the root directory

Cd/Users/beyond/

 

Create a new directory
Mkdir directory name
For example, create a backup directory backup under the user directory.

Mkdir/Users/beyond/backup

 

Copy an object
Target file of the cp-R parameter source file

For example, you want to copy the 1.txt file under the user directory to the backup directory created above.


When copying a folder, add the R or r parameter to perform recursive operations on the directory,
Back up all files in the driver directory to the backup folder in the user directory.

Cp-R/System/Library/Extensions/*/Users/beyond/backup

Delete an object
Rm parameter file
For example, you want to delete the backup folder in the user directory.
Rm-rf/Users/beyond/backup

Parameter-rf indicates recursion and force. Be careful when using this parameter,

If you run the following command, your system will be gone.

Rm-rf/

It indicates that all contents under the root directory are forcibly deleted.


Move files
Mv File

For example, you want to move 1.txt under the user's directory to the document directory.

Mv/Users/beyond/1.txt/User/beyond/Documents

 


 

Permission

 

Read write execution permission (excute)

Example: 777 permission rwx

The three numbers are divided into three parts,

1st digits, indicating the owner's permissions,

2nd digits, indicating the permissions of users in the same group, that is, other members in the group where the user is located

3rd digits, indicating the permissions of users in other groups

R indicates the read permission. The value is 4,

W indicates the write permission. The value is equal to 2,

X indicates the execution permission. The value is equal to 1.

Therefore, 7 indicates readable, writable, and executable

0 indicates that it cannot be read, written, or executed.

 

For example, the above 777,

The first 7 is equal to 4 + 2 + 1, so rwx is used. The owner has the permission to read, write, and execute data,

The second digit 7 is also 4 + 2 + 1, rwx. users in the same group have read, write, and execute permissions,

The third digit 7 indicates that other users have the permission to read, write, and execute data.

For example, 744,

The first 7 is equal to 4 + 2 + 1, rwx, and the owner has read, write, and execute permissions,

The second digit 4 is equal to 4 + 0 + 0, r--. users in the same group only have read permission,

The third digit 4 is also r-. Users in other groups only have read permission.


Change File Permissions
Chmod parameter permission File

For example, set the 64-4 permission limit for the user directory (rw-r--r--example 1.txt,

Change the permission to 664 (rw-r --): users in the same group can read or write data, while users in other groups are read-only.

Chmod-R 664/Users/beyond/1.txt

The R parameter indicates recursion, and 664 indicates the changed permission.

-Indicates a file, and d indicates a directory.

 


 

Change the file owner
New user with chown parameter: user group file
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 the 1.txt file under the user directory.

Nano/Users/beyond/1.txt

 

^ Represents the Ctrl key  

^ X exit nano

 

^ O save the file

 

^ C: displays the cursor position, in the row, column, and character

 

^ R Insert the content of other files on the disk to the cursor position

 

^ W search string

 

^ Y jump to the previous screen

 

^ V jump to the next Screen

 

^ K cut the text of the row where the cursor is located, save it to the clipboard, or cut the selected content

 

^ U paste the clipboard content to the current row

 

 

 

^ P jump to the first line

 

^ N jump to the next line

 

^ A jump to the beginning of the current row

 

^ E jump to the end of the current row

 

 

 

^ F jump one character forward

 

^ B Jump one character backward

 

 

 

^ M inserts a new row at the cursor position

 

^ D delete a character under the cursor

 

^ H delete a character on the left of the cursor

 

 

 

 

After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.

 

 

Another text editing software is the vi Editor, which is available in all Unix-like systems.

1. Basic concepts of vi
Basically, vi is divided into three states: Command mode, insert mode, and last line mode)

2. insert mode
You can enter text only in insert mode. You can press ESC to return to command mode.
3. last line mode)
In command mode, enter the colon to enter the last line mode,

In this case, you can run the command to save the file or exit vi,

You can also set the editing environment, such as searching strings and listing row numbers ...... .

4. basic operations of vi
5. Go to vi
Enter the vi or vi file name on the terminal to go To the vi full screen editing screen.

After entering vi, you are in "command line mode". Press the I key to enter "insert mode 」

6. Switch to the insert mode.
In "command line mode", click "I" to enter "insert mode.

After editing the content, if you want to save it, press the ESC key and return to the command line mode first.
7. Exit vi and save the file
When you are in [insert mode], press the "ESC" key to return to "command line mode 」

Then, in "command line mode", click ":" colon to enter "Last line mode 」

In this case, the corresponding save and Exit commands can be executed.


: W 2.txt: Write the prepared documents to the disk with the name 2.txt, and save them to the current directory.

: Wq (write to disk and exit vi)
: Q! (Force exit vi without saving the disk)

8. commands in command line mode, that is, function keys


Press "I" to switch to the insert mode. The text is input starting from the previous position of the cursor;

Press "a" to enter the insert mode. The text is input starting from the next position of the current cursor;

After you press "o" to enter the insert mode, Insert a new row and enter text from the beginning of the new row.

9. Return (switch) from the insert mode to the command line mode.
Press ESC.


10. move the cursor in command mode
Vi can move up, down, left, and right with the cursor on the keyboard,

Vi can also contain lowercase letters "h", "j", "k", and "l 」

The cursor is controlled to move one cell to the left, down, up, and right respectively.


Press ctrl + B: the screen moves one page to the back, that is, the page is displayed on the page pageUp.


Press ctrl + f: the screen moves one page to the front, that is, it goes to the top page pageDown.


Press ctrl + u to move the screen to the top half of the page.


Press ctrl + d to move the screen half to the bottom.


Press the number "0": move the cursor to the beginning of the row.


Press g to move to the beginning of the article.

Press G to move to the end of the article.


  Press "$" to move to the end of the row where the cursor is located ".


Press ^ to move the cursor to the beginning of the row"



Press w to start the next word.


Press "e": the cursor jumps to the end of the next word.


Press "B": the cursor returns to the beginning of the previous word

11. delete text


"X": each time you press the button, the "Next" character of the cursor is deleted.


"X": uppercase X. Each time you press it, the "front" character of the cursor is deleted.



Dd: Delete the row where the cursor is located.


「 # Dd 」: delete from the row where the cursor is located # Line, # represents any number


12. copy and paste


"Yw": copy the character at the end of the cursor to the buffer zone.


# Yw: Copy # words to the buffer zone


"Yy": copy the row where the cursor is located to the buffer zone.


"# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down.


  P: paste the characters in the buffer to the cursor position. Note: All copy commands related to "y" are
You must work with "p" to complete the copy and paste function.






13. Undo the last operation


  "U": If a command is mistakenly executed, immediately press "u" to cancel the previous operation. Press "u" multiple times"
You can perform multiple replies.



14. Jump to the specified row


Ctrl + g lists the row numbers of the cursor.


"# G": for example, "4G" indicates moving the cursor to the first row of the article.


15. Introduction to commands in Last line mode
Before using "last line mode", remember to press the "ESC" key to confirm that you are already in the "command m"
Then press ":" colon to enter "last line mode 」.


15.1 list row numbers
 "Set nu": After "set nu" is entered, the row number is listed before each row in the file.




15.2. Jump to a row in the file
:「#」

"#" Indicates a number. Enter a number after the colon and press enter to jump to the row,
If you enter the number 15, press enter to jump to the 15th line of the article.


15.3. Search for characters
: "/Keyword 」

Enter a colon, press the "/" key, and then enter the character you want to search,

If you do not want the keyword for the first search, you can always press "n 」,

The desired keyword will be searched later.


:「? Keyword 」

Enter a colon, and then press 「?」 And then enter the characters you want to find,

If you do not want the keyword for the first search, you can always press "n 」

You can search for the keyword.


15.4 save the file
: "W" File Name

Enter the letter "w" and the file name after the colon to save the file.

 

: Q !」

Enter the Letter q! After the colon !」 Exit the vi editor and do not save




15.5 Leave vi
: Q 」

After the colon, press "q" to exit,

If you cannot leave vi, you can add "!" to "q 「!」 Force exit vi.
: "Qw 」

We recommend that you use "w" when you exit, so that you can save the files (written to the disk) When you exit ).


16. vi command list, some key functions in command mode:

H
Move the cursor one character left

L
Move the cursor one character to the right


K
Move the cursor up a row


J
Move the cursor down a row


^
Move the cursor to the beginning of the line


Number "0", move the cursor to the beginning of the article


G
Move cursor to the end of the article


$
Move the cursor to the end of the row


Ctrl + f
Forward screen flip


Ctrl + B
Flip back


Ctrl + d
Front Half Screen


Ctrl + u
Flip back half screen


I
Insert characters before the cursor position


A
Add the next character at the cursor position


O
Insert a new row and start from the beginning of the row.


ESC
Return from input to command status


X
Delete characters after the cursor


# X
# Characters After deleting the cursor


X
(Uppercase X), delete the character before the cursor


# X
Delete # characters before the cursor


Dd
Delete the row where the cursor is located


# Dd
Delete # rows from the number of rows where the cursor is located


Yw
Copy a word at the cursor position


# Yw
Copy the # characters at the cursor position


Yy
Copy a line at the cursor position


# Yy
Copy the number of rows from the cursor


P
Paste


U
Cancel operation





17. The following table lists some commands in last line mode. Before each command, enter a colon
: W filename
Save the file being edited as filename


: Wq filename
Save the file being edited as filename and exit vi


: Q!
Discard all modifications and exit vi


: Set nu
Show row number



: // Or?
Search, enter the content to search after/

N
And/or? If the search content is not the keyword, press n or backward (combined with/) or forward (
And? Continue searching until it is found.
 

 

 

Run the script command on the terminal.

Sh script file name

For example:

Decompress the downloaded cocos2d package,

 

Go to the cocos2d home directory and copy the path to the terminal.

 

Execute./install. sh to start installation (essentially copy to XCode directory)


Enable the Tab key auto-completion 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

 


 

View Detailed Help of commands
Man command name
For example, to view the detailed usage of the ls command, execute man ls


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

Date: displays the current date and time of the system.


Cal display calendar

Cal 9 2014

Time
Statistical Program Execution time

Time a. out

 


 

Network and communication operations

Telnet Remote Logon

Telnet IP port or telnet domain name Port

Ping a network host to send a response request

Ping www.baidu.com



History lists the commands and numbers that have been executed recently.


Alias defines aliases for a command
Alias cls = clear do not have spaces
Unalias undefines an alias

Unalias cls

 


 



Uname: displays information about the operating system.

Uname-

Clear screen or window content


Env displays all the currently set Environment Variables

Who lists all users currently logged on

Whoami displays the user name currently performing the operation


Du query disk usage

Du-k subdirectory

Du-k displays the number of blocks in 1024 bytes

Df important ~~ Displays the total space and available space of the file system.

Df sub-file path

Df/tmp

W displays the total information of the current system activity

 

 

The following is a unix Command Line for your reference.

Create a directory using mkdir
Mkdir dirname
Rmdir delete a directory
Rmdir dirname
Mvdir move or rename a directory
Mvdir dir1 dir2
Cd changes the current directory
Cd dirname
Pwd displays the path name of the current directory
Pwd
Ls displays the content of the current directory
Ls-la
Dircmp compares the contents of the two directories
Dircmp dir1 dir2
Cp copy file or directory
Cp file1 file2
Rm deletes a file or directory
Rm filename
Mv: Change the file name or directory
Mv file1 file2

Diff compares and displays the differences between the two files
Diff file1 file2

Grep searches by mode in the file
Grep "^ [a-zA-Z]" filename

Number of characters, words, and lines in the wc statistics File
Wc filename
Nl adds the row number to the file
Nl file1> Add the row number to file2 and write it to file 2.

Head: displays the first few lines of the file.
Head-20 filename
Tail displays the last few lines of the file
Tail-15 filename

 


Cat display or connection file
Cat filename

More split screen display file content
More filename
Pg paginated formatting of File Content
Pg filename

Od displays non-text file content
Od-c filename

Ln connection file
Ln-s file1 file2
Find
Find.-name "*. c"-print
File display file type
File filename


Cut: displays certain fields in each row of a file.
Cut-f1, 7-d:/etc/passwd
Colrm deletes several columns from standard input
Colrm 8 20 file2
Paste horizontal connection file
Paste file1 file2

Sed non-interactive stream Editor
Sed "s/red/green/g" filename

Awk
Find and process the mode in the file
Awk '{print $1 $1}' filename
Sort or merge files
Sort-d-f-u file1
Uniq removes duplicate rows from the file
Uniq file1 file2
Comm displays the public and non-public rows of two ordered files
Comm file1 file2


Passwd Change User Password
Passwd
Chmod changes the permissions of files or directories
Chmod ug + x filename
Umask defines the permission mask for creating files
Umask 027
Chown changes the owner of a file or directory
Chown newowner filename
Chgrp changes the group to which the file or directory belongs
Chgrp staff filename
Xlock locks the terminal
Xlock-remote


Make maintains the latest version of the executable program.
Make
Touch updates 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
 

 

Tty display terminal or Pseudo Terminal name

Stty display or reset control key definition
Stty-

Change the file owner
New user with chown parameter: user group file
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.


Get Permissions
To prevent misoperation and damage to the system, you must first obtain the root permission because you do not have the permission to operate important files in the system.
Sudo-s
Then enter the password. When you enter the password, there is no echo and no star number. Just press Enter. Get Permissions
To prevent misoperation and damage to the system, you must first obtain the root permission because you do not have the permission to operate important files in the system.
Sudo-s
Then enter the password. When you enter the password, there is no echo and no star number. Just press Enter.

 


 

Mail reading and sending emails
Write sends messages to another user
Write username pts/1
Mesg allows or rejects receiving packets
Mesg n
Rlogin remote Logon

Rlogin hostname-l username

Rsh executes 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 Copies files between the local host and remote host

Rcp file1 host1: file2

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.