This is the fifth day of my participation in the First Challenge 2022


Linux commands are programs that run on the command line (CLI). The command line is the interface that accepts lines of text and processes them into computer instructions. Any graphical user interface (GUI) is an abstraction from a command-line program. Multi-step tasks through the GUI can sometimes be completed in a matter of seconds by typing commands on the command line. Learning the basic command line helps increase productivity.

I believe many friends will use Mac for development, because the Mac system is based on Unix, so some Mac terminal commands and Linux common. Most of the commands listed below can be used on a Mac.

First, document management

1. cat

The cat command is used to connect files and print them to the standard output device.

cat index.html
Copy the code

Use cat > filename c to create a new file:

cat > style.css
Copy the code

Use cat Filename1 filename2 >> Filename3 to connect two files (1 and 2) and store their output in a new file 3.

cat filename1 filename2 >> filename3 
Copy the code

2. rmdir

The rmdir command is used to delete an empty directory.

3. rm

The rm command is used to delete a file or directory.

We can also use the rm -rf command to quickly delete folders/directories and their contents.

Note: Use this command with great care and carefully check the directory you are in. This action deletes everything and cannot be undone.

4. touch

The touch command is used to modify the time properties of a file or directory, including the access time and change time. If the file does not exist, the system creates a new file.

If no parameters are added, the file modification time is changed to the current system time.

5. cp

The cp command is used to copy files or directories. When using this directive to copy directories, you must use arguments -r or -r.

Here we copy the test directory and rename it test1, which also contains all the contents of the test directory.

6. mv

Using the mv command, you can rename a file or directory (if the directory name does not exist) or move the file or directory to another location.

Here you move the test1 file into the test file.

7. locate

The locate command is used to locate documents that match the template style criteria by going to the database that holds the document and directory names. Generally, you only need to enter locate file_name to locate a specified file.

2. Disk management

1. cd

The CD command is used to switch the current working directory. This command must be used together with the file/directory name.

The directory/file name here can be an absolute path or a relative path. If the directory name is omitted, it is converted to the user’s home directory (the same directory where you first logged in). In addition, ~ represents the home directory,. Represents the current directory,.. Represents the directory level above the current directory location.

2. mkdir

Using the mkdir command, you can create a folder in the current location (current directory). Simply use this command to add the name of the folder you want to create:

mkdir test
Copy the code

Here is the result. Using the ls command, you can see the newly created folder named test:

We can also create multiple folders at the same time by adding Spaces between them. If a folder name contains Spaces, use double quotation marks to write the folder name:

3. pwd

Using the PWD command, you can view the absolute path of the current file (folder) in the file system.

PWD /Users/ MAC /Desktop/ Functional programmingCopy the code

4. ls

Using the ls command, you can display the contents in the specified working directory. The files and subdirectories in the current working directory are listed.

# ls

FZLanTYJ_Bold.OTF	FZLanTYJ_Heavy.OTF	FZLanTYJ_Medium.OTF
FZLanTYJ_DemiBold.OTF	FZLanTYJ_Light.OTF	FZLanTYJ_Regular.ttf
Copy the code

We can also add arguments to the ls command, for example:

  • ls -l
  • ls -a

The ls -l command outputs all files in a long list. When using this command, the terminal displays more information about all files, such as permissions, file owners, file sizes, and dates:

The ls -a command will list all files in the folder/directory, including hidden files:

We can also use the two arguments together, and the output will be the effect of the two arguments executed separately and:

As you can see, the output contains additional information about regular and hidden files.

Three, system Settings

1. clear

The clear command is used to clear the screen.

2. uptime

On Linux, the uptime command displays how long our system has been running, the number of users currently logged in, and the average operating system load over the past 1, 5, and 15 minutes.

Uptime 22:52 UP 10 days, 8:57, 2 users, load Averages: 4.63 4.15 3.13Copy the code

We can use uptime to determine whether there is a server or network problem. For example, if the network application is running, run uptime to see if the system load is high. If the load is not high, the problem is most likely due to the network rather than the server.

You can use the w command instead of uptime. W also provides information about the current system logged-in user and the work performed by the user.

3. users

Using the users command, you can view the current login users.

users

mac
Copy the code

4. lsof

The lsof command is used to check port usage.

lsof -i:3000
Copy the code

5. df

The df command is used to display the file system disk usage statistics on Linux.

6. passwd

Using the passwd command, you can change the password. You need to enter the old password once and the new password twice as prompted.

7. cal

The CAL command is used to view the calendar. By default, only the current month is displayed:

You can use the cal-y 2022 command to display the calendar for a particular year:

4. System management

1. date

The date command is used to view the date and time of the current system. We can also format the current time:

2. kill

The kill command is used to delete a running program or work. Kill sends the specified information to the program. The default message is SIGTERM(15), which terminates the specified program. If you still cannot terminate the program, you can use the SIGKILL(9) message to try to forcibly remove the program.

kill -9 3000
Copy the code

3. ps

The ps command is used to display the status of the current process, similar to the task manager on Windows.

4. top

The top command is used to display the process dynamic information in real time.

5. who

The who command returns the user name, host information, date, and time.

# who

mac      console  Jan 15 13:55
mac      ttys004  Jan 25 22:52
Copy the code

6. sudo

The sudo command executes commands as a system administrator, meaning that commands executed by sudo are executed as if they were executed by root himself.

7. history

Using the history command, you can view historical records. It shows the history of all commands executed in the terminal.

8. exit

The exit command is used to exit the shell. The exit command causes the shell to exit with the specified status value. If the status value parameter is not set, the shell exits with the default value. The status value 0 indicates that the execution succeeded, and other values indicate that the execution failed. Exit can also be used in script to leave the script being executed and return to the shell.

Five, the other

1. ssh

The SSH command is used to connect to a Linux-based remote host. To connect to a remote host as user root, use the following command:

SSH [email protected]Copy the code

The above command will not support GUI. If you want to use GUI to connect to a remote host, you need to use the following command:

SSH - XY [email protected]Copy the code

2. tar

The tar command is used to back up files. Tar is a tool for creating and restoring backup files, adding and unpacking backup files.

Compressed file:

Tar -czvf test.tar.gz a.c // Compress the A.c file to test.tar.gz a.cCopy the code

Unzip files:

#tar -xzvf test.tar.gz a.c
Copy the code

3. grep

The grep command is used to search for qualified strings in a file. If the contents of a file are found to match the specified template style, the default grep command will display the column containing the template style. If no file name is specified, or if the file name given is -, the grep command reads data from the standard input device.

We can use the -c argument to count the number of repetitions:

4. ping

The ping command is used to check hosts. After the ping command is executed, ICMP is used to send a message requesting a response. If the remote host is running properly, the remote host responds to the message.

5. man

Using the man command, you can view the user manual of the Linux command. For example, run the man clear command:

6. wc

The wc command is used to count words. Using the WC directive, we can count the Byte count, word count, or column count of a file. If the file name is not specified, or the given file name is “-“, the WC directive reads data from the standard input device.