Home Operation and Maintenance Mac OS Introduction to common terminal commands under mac

Introduction to common terminal commands under mac

Jan 26, 2021 am 10:03 AM
mac Order terminal

Introduction to common terminal commands under mac

First of all, let me introduce absolute paths and relative paths.

(Learning video sharing: Introduction to Programming)

Absolute path

As we all know, when we usually use computers, we need to find the files we need. The location of the file must be known, and the way to indicate the location of the file is the path. For example, as long as we see this path: c:/website/img/photo.jpg, we will know that the photo.jpg file is img in the website directory of the c drive. in the subdirectory. In this way, the path that completely describes the file location is an absolute path. We don't need to know any other information to determine the location of the file based on the absolute path. (It can also be considered that everything starting with "/" is an absolute path)

Relative path

The so-called relative path, as the name suggests, is relative to the target location. No matter where you put these files, as long as their relative relationship does not change, there will be no error.​ In addition, we use "../" to represent the upper-level directory, "../../" to represent the upper-level directory, and so on. (It can also be considered that all paths that do not start with "/" are relative paths)

Give a chestnut

Example 1
For example, there are two files in the ABC folder of your C drive 1 and 2 (they are both under the ABC file), if you want file 1 to tell the location of file 2
(that is, the path), then it has two representation methods:

1. Absolute path: C:\ABC\2
Because it indicates that file 2 is under the ABC file on drive C, starting from the largest directory on drive C.
2. Relative path: 2
Because file 1 and file 2 are both Under C:\ABC, so the "C:\ABC" in front of their paths are the same, so there is no need to show it.
Example 2
For example, the ABC folder on the C drive has 1 file and another DEF folder, and there are 2 files 1 and 2 under the DEF file. The file paths are:
(both absolute paths)
C:\ABC\1
C:\ABC\DEF\2
If file 1 is used to represent the path of file 2
* Absolute path: C:\ABC\DEF\2
* Relative path: DEF\2 (because C:\ABC in front of files 1 and 2 If this path is the same, there is no need to write it out).

Commonly used mac terminal operation command commands

1. Display the path of the current directory

Display the path of the current directory (allowing you to view the current path in real time)
pwd copy code

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

ls parameter directory name
Parameters: - w displays Chinese, -l details, -a includes hidden files,
If each line starts with "d", it is a folder, and if it starts with "-", it is a file.
LS Display all files or folders in the current directory
LS directory displayed in all files or folders in this directory
LS space -A display hidden file
LS spaces- l Display detailed information in the current directory
ls space -R Display subdirectory files in the current directory
ls space -w Display Chinese files in the current directory
ls space -la Display all files
Example: Take a look What is in the driver directory: ls /System/Library/Extensions

3. Switching paths (also called conversion directories) means going from one path to another path

cd directory name
cd . cd ../.. /. . Represents that returning the previous three -level directory
CD space The next directory indicates that it will enter the next directory from the current path
CD space ~ indicate from the current directory to the user root directory
CD space / indicate from the current directory from the current directory Enter the root directory
cd Space ./ means entering from the current directory to the current directory (a dot "." indicates the current)
Example: I want to take a walk in the driver directory: cd /System/Library/Extensions


4. Create a new directory (can also be understood as creating a folder)

mkdir directory name
mkdir space folder name means creating a folder
mkdir space absolute path means creating a folder with the same function as above,
except that the above is created through a relative path, below It is created through an absolute path.
Example: Create a backup directory backup under the driver directory: mkdir /System/Library/Extensions/backup

5. Delete the directory (can also be understood as deleting files Folder)

rmdir directory name
rmdir space folder name means deleting a folder
rmdir space absolute path means deleting a folder The function is the same as the above, except that the above is deleted through a relative path ,The following is deletion through absolute path
Example: Delete a file called new on the desktop MacBook-Air:Desktop admin$ rmdir new

6. Create a new file

touch File name
Example: Create a backup file backup in the current directory: touch backup.txt

7. Delete file

rm Parameter file parameter-rf Represents recursion and force , be sure to use it with caution, if you execute rm -rf /
your system will be gone
rm spaces file name and format means deleting a file
rm -r folder means forced deletion of the folder Folder containing files
(When the folder contains files, the folder cannot be deleted by using "rmdir space folder name". You can only force deletion by using "rm -f folder name")
rm -rf folder means forcibly deleting the folder containing files in the folder
(Same function as "rm -r folder name")
Note: rm can delete multiple files instead of just one file , but the paths of the two files must be separated by spaces.
Example: Want to delete the driver cache: rm -rf /System/Library/Extensions.kextcache rm -rf /System/Library/Extensions.mkext

8. Copy

cp parameter source file target file
Example: I want to copy the Natit.kext of the desktop to the driver directory cp -R /User/username/Desktop/Natit. kext /System/Library/Extensions
Parameter R indicates recursive operation on the directory. kext looks like a file in the graphical interface, but is actually a folder.
Back up all files in the driver directory to desktop backup: cp -R /System/Library/Extensions/
/User/username/Desktop/backup

9. Move files And rename the file

mv source file target file
mv the path to which the file or folder needs to be moved (the path here can be a relative path or an absolute
path);mv a.c space b.c means rename a.c to b.c
Example: want to move AppleHDA.Kext to the desktop:
mv /System/Library/Extensions/AppleHDA.kext /User/username/Desktop

10. Text editing

vim file name
vim file name indicates the content of the edited file
Example:
vim /System/Library/Extensions/Natit.kext/Info.plist
After editing, use Ctrl + O to save, Ctrl + ## * Input in "command mode":
:w Save the current file
:q Exit editing, if the file is not saved, you need to use force mode
:q! Force exit without saving changes
: wq combine commands, save and exit
* Move in "command mode":
h left
j down
k up
l right


11. Clear screen

clear

12. Open a file, folder or application


open

* If it is open, it will open the current command Directory, if you want to open the specified folder or file, the format is open and the path to be opened can be used. (Both absolute paths or relative paths are acceptable here)

* The open command can open applications in the terminal, and -n can be used to open multiple identical applications. For example, you can use the following command to open a new Safari window

open -n /Applications/Safari.app/



Related recommendations:
macos system

The above is the detailed content of Introduction to common terminal commands under mac. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if the Ubuntu terminal cannot be opened? How to fix the problem that Ubuntu cannot open the terminal What should I do if the Ubuntu terminal cannot be opened? How to fix the problem that Ubuntu cannot open the terminal Feb 29, 2024 pm 05:30 PM

It is a very common problem these days that Ubuntu does not allow its users to open the terminal. If you receive a similar issue and don’t know what to do next, learn about five fixes on how to resolve this “Ubuntu cannot open terminal” issue on your Linux device. Without further ado, let’s dive into what causes it and the solutions available to it. Why can't Ubuntu open the terminal on it? This mainly happens when you install some defective software or modify the terminal configuration. In addition to this, new applications or games that interact with locales and corrupt them can cause similar problems. Some users reported a fix for this issue when searching for Terminal in Ubuntu's activity menu. This shows that

3 tips to easily customize your Mac computer name, host name and Bonjour name 3 tips to easily customize your Mac computer name, host name and Bonjour name Mar 06, 2024 pm 12:20 PM

Many Mac users tend to keep the default name of their device and may never consider changing it. Many people choose to stick with the name from the initial setup, such as "Johnny's MacBook Air" or simply "iMac." Learning how to change the name of your Mac is a very useful skill, especially when you have multiple devices, as it can help you quickly distinguish and manage them. Next, we will teach you step by step how to change the computer name, host name and Bonjour name (local host name) in macOS system. Why should you change your Mac name? Changing the name of your Mac can not only show your personality, but also help improve the user experience: Personalize your Mac: The default name may not be to your taste, change it to a name you like.

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

pkg file to install on mac? pkg file to install on mac? Feb 20, 2024 pm 03:21 PM

Preface: Today, this site will share with you the relevant content about installing pkg files on Mac. If it can solve the problem you are facing now, don’t forget to follow this site and start now! The previous version of macos pkg cannot be installed to upgrade the operating system: If your laptop is using an older operating system version, it is recommended to upgrade to the latest operating system version. Because older versions may not support installation of the latest macOS system. Select "Erase" in Disk Utility, then select the Macos extension in the format, do not check the encryption option, and do not select the apfs format, and finally click the "Erase" button to solve the problem of being unable to complete the macOS installation. Drag the application's icon to the file starting with App

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

How to set up WeChat Mac to automatically convert voice messages into text - How to set up voice to text conversion How to set up WeChat Mac to automatically convert voice messages into text - How to set up voice to text conversion Mar 19, 2024 am 08:28 AM

Recently, some friends have consulted the editor about how to set up WeChat Mac to automatically convert voice messages into text. The following is a method for setting up WeChat Mac to automatically convert voice messages into text. Friends in need can come and learn more. Step 1: First, open the Mac version of WeChat. As shown in the picture: Step 2: Next, click "Settings". As shown in the picture: Step 3: Then, click "General". As shown in the picture: Step 4: Then check the option "Automatically convert voice messages in chat to text". As shown in the picture: Step 5: Finally, close the window. As shown in the picture:

Super practical! Sar commands that will make you a Linux master Super practical! Sar commands that will make you a Linux master Mar 01, 2024 am 08:01 AM

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

See all articles