preface

  • Are you still manually opening folders?
  • Are you still turning it off manually?
  • Local service can’t get up. Are you still suspicious of the code?

There are many terminal commands provided by the Mac. Here’s a look at some common ones.

First, we need to open the MAC terminal. The shortcut key I set here is Opt + Cmd + T. Students who have not set it can set it by themselves, or go to the docking station to manually open it.

MAC Terminal Commands

man cd

Man Displays how to use a command.

1. File system

To operate a file system, we first need to understand some file directories:

  • / root directory
  • ~ User root directory
  • ./ The current directory
  • . / Upper-level directory

How do I enter a folder 🍉

cd ~

The user root directory is displayed. For example, mine is xdq@xdqdeMacBook-Pro. Open the terminal by default is the user directory.

cd ~/monga/

Go to the monga directory under the root directory.

cd Users cd /Users

Go to the User folder in the current directory.

cd .. cd .. /

Jump to a higher directory. You can also CD.. /.. / Jump to the upper directory.

For example 🌰: we jump back and forth between folders.

How do I view the 🍉 folder

pwd

Viewing the current directory

ls

View all files in the current directory

ls -l

View all files in the current directory and display their details, including the creator, creation date, etc.

ls -a

Displays all files in the current directory, including hidden folders, including. , “..” “, “.git “, etc.

ls -la

This command is a combination of ls -a and ls -l.

For example 🌰: let’s go into the monga folder and do some viewing.

How to create a folder for folders 🍉

mkdir testA

Create folder A by creating multiple mkdir testA testB folders.

How do I create the file 🍉

touch index.html

Create the index. HTML file. You can create multiple touch a.tb B.TB.

For example 🌰: we create a folder on the desktop called testCmd and two subfolders called testA and testB. Create the file index.html in the testA folder.

How do I move the file 🍉

mv index.html testB

Move the index. HTML file to testB.

For example 🌰: Continue with the example above and move the index. HTML file to testB.

How do I rename the file 🍉

mv a.txt c.txt

Name the file a.tb c.tb.

For example 🌰: let’s create two more files in testA: a.tb and B.TB. Then we rename a.t_t to C.t_t.

As we can see, not writing the file suffix is not successful.

How do I copy files and folders 🍉

cp b.txt d.txt cp -a b.txt d.txt

Copy B. TB to D. TB. This cp method copies folders. To preserve file permissions, add -a.

cp -r testA testC

cp -ra testA testC

cp -rav testA testC

TsetA is copied to testC. Different properties can be added to the replication process:

  • -r copies folders, requiring recursive files
  • -a Reserves all permissions
  • -v Displays the replication progress

These properties can be used in combination with each other.

For example 🌰: we copy B. TXT to d. TXT and tsetA to testC. Copy tsetA to testC and show progress.

How do I delete a file or folder 🍉

rm b.txt rm -r testD rm -r testD rm -r /*

The deletion operation was performed using RM. Procedure It has several properties to choose from:

  • -r deletes folders and recursively deletes subfiles and folders

Here’s an example 🌰:

Note: rm -r /* use!!!!! with caution

Other less common but potentially useful ways to manipulate files 🍉

cat b.txt

When git fails and the public key is reconfigured, it will use cat ~/.ssh/id_rsa.pub to display the public key contents.

file b.txt

Displays the file type.

diff b.txt c.txt

Compare the differences between the two files.

wc b.txt

Count the number of characters, words, and bytes in a file.

Here’s an example 🌰:

2. Network management

How do I view the local IP address 🍉

Are you still turning on network Settings when we need to debug local code on the phone?

ifconfig

You can view the IP address of the host.

ifconfig en0

Take the IP out of the machine directly.

How do I check the network status 🍉

There’s no Internet. Are you still scolding the webmaster?

ping

You can view the network status. For example, 🌰: let’s ping the domain name of Baidu.

How do I check whether the port number occupied by 🍉

Local service can’t get up. Are you still suspicious of the code?

lsof -i:8080

Check who is occupying port 8080.

kill 28305

Kill the process.

The lsof command has many more properties that I won’t cover here.

For example, 🌰: we start a local service on port 5050, then check for port occupancy and kill the corresponding process.

3. System management

Shutdown 🍉

Are you still turning it off manually?

halt

The system shuts down.

halt -d

Turn it off and leave no record. For those of you who need administrator privileges, use Sudo HALT.

Restart 🍉

reboot reboot -f

Restart the system. -f indicates forcibly restart the system.

4. Disk management

MAC does not need anti-virus software, “360”, “Tencent Butler” and so on. So how do we clean and maintain the disks?

sudo periodic daily

sudo periodic weekly

sudo periodic monthly

sudo periodic daily weekly monthly

Clean daily. Clean weekly. Clean up every month. He is a scheduled task. After configuration, we can periodically clean and maintain our disks.

5, other

clear

Clear the command line.

open ./

Open the folder on the file system.

conclusion

We’ve covered some common MAC command-line operations:

  • File system operations
  • Network management
  • System management
  • Disk management

So much for the MAC command line, there are many less commonly used but very valuable command lines that you can research and accumulate on your own.

Familiar with the use of Linux command line should be a programmer’s necessary skills, and you encourage!

This article is shallow, please don’t hesitate your comments and likes ~ note: this article is the author’s painstaking work, reprint must declare