An absolute path

As we all know, when we usually use the computer to find the file we need to know the location of the file, and the way to indicate the location of the file is the path, for example, as long as we see this path: Photo.jpg :/website/img/photo.jpg :/website/img/photo. JPG :/website/img/photo. JPG :/website/img/photo. The path that completely describes the location of the file is the absolute path. We don’t need to know anything else to figure out where the file is based on the absolute path. (You can also assume that all paths starting with “/” are absolute paths.)

Relative paths

The so-called relative path, as the name implies, is their relative to the target position. No matter where you place these files, you can’t go wrong as long as their relative relationship doesn’t change. In addition we use “.. / “to indicate the upper level directory,”.. /.. / “indicates the directory of the upper level, and so on. (Anything that does not start with a “/” is a relative path.)

Take a chestnut

For example, if you have two files 1 and 2 in the ABC folder on drive C (they are both located in the ABC file), if you want file 1 to tell you the location (i.e. path) of file 2, it can be expressed in two ways: 1. The absolute path: C:\ABC\2 because it indicates that the 2 file is under the ABC file on drive C, starting from the largest directory on drive C. 2. Relative path: 2 Since both files 1 and 2 are under C:\ABC, the path before "C:\ABC" is the same, so there is no need to express it. C:\ABC\1 C:\ABC\DEF\2 C:\ABC\1 C:\ABC\DEF\2 If file 1 is used to represent file 2 * absolute path: C:\ABC\DEF\2 * Relative path: DEF\2.Copy the code

Common MAC terminal operation commands

1. Display the current directory path

Displays the path to the current directory (allowing you to see where you are in real time) PWDCopy the code

2. View the contents of the current directory (allows you to view the contents of the current directory in real time)

-w Displays Chinese characters, -l details, and -a includes hidden files. If a line starts with D, it is a folder, and if a line starts with -, it is a file. Ls Display all files or folders in the current directory ls + directory Display all files or folders in the current directory ls + space + -a Display hidden files in the current directory ls + space + -l Display details in the current directory ls + space + -r According to the current directory following directory file ls + space + - w display the current directory files in Chinese ls + space + - la show all files Example: see what drive directory: ls/System/Library/ExtensionsCopy the code

3. Switching a path (also known as converting a directory) is to go from one path to another

CD Directory name CD. Indicates the current directory CD.. Indicates to return to the upper directory CD.. /.. Returns two levels of CD.. /.. /.. CD + space + next directory CD + space + ~ From the current directory to the root directory CD + space + / From the current directory to the root directory CD + space +./ Says from the current directory to the current directory (a point ", "said current) example: think of drive directory around a circle: CD/System/Library/ExtensionsCopy the code

4. Create a new directory.

Mkdir directory name mkdir + space + folder name to create a folder mkdir + space + absolute path to create a folder the same function as above, except that the above is created by relative path, the following is created by absolute path. Example: a backup directory under the drivers directory backup: mkdir/System/Library/Extensions/backupCopy the code

5. Delete a directory.

Rmdir Directory name rmdir + space + folder name Deleting a folder RMdir + space + Absolute path Deleting a folder The function of deleting a folder is the same as that of deleting a folder using a relative path. The following is an example of deleting a folder using an absolute path: Delete a file called new from the Desktop macbook-air :Desktop admin$RMdir newCopy the code

6. Create a new file

For example, create a backup file in the current directory: backup: touch backup.txtCopy the code

7. Delete files

Rm parameter file parameter -rf indicates recursion and coercion, be careful to use it. Rm + space + file name and format means to delete a file rm + -r + folder means to forcibly delete the folder containing the file in the folder. The rmdir + space + folder name command cannot be used to delete a folder. You can only run the rm + -f + folder name command to forcibly delete a folder. Rm + -rf + folder Indicates that the folder containing files in the folder is forcibly deleted. Note: RM can delete multiple files instead of just one, but the paths of the two files must be separated by Spaces. Example: would you like to delete the drive cache: rm - rf/System/Library/Extensions kextcache rm - rf/System/Library/Extensions mkextCopy the code

Copy 8.

Cp Source file Destination file example: Want to put the Desktop Natit. The kext copy to drive directory cp -r/User/User name/Desktop/Natit kext/System/Library/Extensions parameter R said to recursive directory operations, Kext looks like a file in the graphical interface, but is actually a folder. The driver backup all files in the directory to Desktop backup: cp - R/System/Library/Extensions / / User/User name/Desktop/backupCopy the code

9. Move and rename files

Mv Source file Destination file mv + File or folder to be moved + space + path to be moved (the path can be a relative or absolute path). Mv + a.c + space + biggest said it would a.c renamed biggest example: want to AppleHDA. Kext moved to the Desktop: mv/System/Library/Extensions/AppleHDA Kext/User/User name/DesktopCopy the code

10. Text editing

Vim vim + file name in the file name Said edit the file content: vim/System/Library/Extensions/Natit kext/Info. After completion of plist editor Use Ctrl + O save, Ctrl + X exit note: * Press I in default "command mode" to enter editing mode * Press ESC in non-command mode to return to command mode * Enter: :w in "Command Mode" to save the current file :q to exit editing, if the file needs to be saved in force mode: Q! Forced exit do not save modify :wq combination command, save and exit * move in "command mode" : h left, J down, K up, L rightCopy the code

11. The screen

    clear
Copy the code

Open a file, folder, or application

Open * If it is open. It opens the directory in the current command. If you want to open the specified folder or file, the format is open to open the path. * Run the open command to start an application on a terminal. Run the -n command to start multiple applications. For instance you can use the following command to open a new window open Safari - n/Applications/Safari. App /Copy the code