Learn common Linux commands and keep updating...

1 Introduction

  This chapter continues Linux learning and records some commonly used Linux commands. It is mainly divided into the following parts: the first part includes basic commands for some commonly used commands, and the second part includes commands related to directory and file management. Continually updated…

2. Commonly used basic commands

2.1 Restart and shutdown commands

  Restarting and shutting down require system administrator user rights.
  1) Restart

init6 or reboot

  2) Shut down

init 0 or halt

  If you do not execute the shutdown command, forcibly power off or close the local virtual machine window, it may cause damage to the Linux system files, and in severe cases, the system may not work properly.

2.2 Clear screen

  Be clear about what's on the screen.

clear

2.3 Check the server IP address

ip addr

2.4 Copy and paste operation

  1) Copy

Ctrl+Insert

  2) Paste

Shift+Insert

  The copy and paste here also applies under Windows (generally commonly used under Windows, Ctrl+c/Ctrl+v). Under the Linux operating system, you can use Ctrl+c to terminate the command without deleting and retyping one by one. If you want to type the following command again, just press Ctrl+c.

2.5 Help document viewing command

XX --help XX is the command that needs to be viewed, so that you can view its usage and function. For example, ls --help
or use: man XX

3. Directory and file management

  The file system is like a tree, the trunk is the / (root) directory, the branches are subdirectories, there are branches after the branches (subdirectories and subdirectories), the branches are leaves at the end, and the files are at the end of the directory.

  The file name is composed of directory + file name . There are some agreed expressions for directories and files. Let’s take /usr/etc/reademe.txt as an example:

1) The full path file name includes the complete directory name and file name, that is, /usr/etc/reademe.txt. There is also another name for " absolute path file name ". reademe.txt is the file name and it is in the /usr/etc directory.
2) The absolute paths of directories and files are calculated from the root (/) and there will be no ambiguity at any time.
3) After logging in to Linux, you must be in a certain directory in the directory tree. This directory is called the current working directory, or the current directory for short . 4) The relative paths
of directories and files are calculated from the current working directory. If the current working directory is /usr, etc/readme/txt is equivalent to /usr/etc/reademe.txt; if the current working directory is /usr/etc, readme.txt is equivalent to /usr/etc/reademe.txt. 5) One dot represents the current working directory, and two dots represent the upper-level directory of the current working directory.

3.1 List directory ls (List Files)

  In Linux systems, the ls command may be the most commonly run, which means listing the file names in the current directory. Commonly used options and parameters are:

-a: All files, listed together with hidden files (files beginning with .) (commonly used)
-d: List only the directory itself, not the file data in the directory (commonly used)
-l: Long data string List, including file attributes, permissions and other data; (commonly used)
-la: List all files in the directory (including attributes and hidden files)

  In the above example, the first attribute of the example file in the last line is represented by d . d in Linux means that the file is a directory file. When the first character is - , it means a file, or it can also mean something else (linked file, interface device, etc.). The following characters are grouped into groups of three, and are all combinations of the three parameters of rwx . Among them, r means readable (read), w means writable (write), and x means executable (execute). It is worth noting that the location of these three permissions will not change, if there is no permission, it will appear - that's all. The first group is the owner permission (user owner), the second group is the group permission (users in the same group as the owner), and the third is the permission of other users to own the file.

3.2 Display the current directory pwd (Print Working Directory)

  pwd is the abbreviation of Print Working Directory, which is the command to display the current directory. Selection and parameters:

-p: Show actual work instead of using link paths

3.3 Create a new directory mkdir (Making Directory)

  mkdir (make directory) is the command to create a new directory. Selection and parameters:

-p: Create the required directory (including the upper-level directory) recursively.
-m: Permissions of the configuration file, otherwise configure according to the default permissions.

The above mkdir -m 711 test2 will give test2 drwx--x--x permissions (111 001 001 binary --> decimal is 711), if you do not use -m to force configuration attributes, the system will use default attributes, such as The permissions of the test directory.

3.4 Delete the specified empty directory rmdir (Remove Directory)

  rmdri deletes the specified empty directory. Common parameters: -p Starting from this directory, delete multiple levels of empty directories at one time.

3.5 Change directory cd (Change Directory)

  cd is the abbreviation of Change Directory, which is the command used to change the working directory.

cd . . means return to the directory one level above the current directory

3.6 Copy files or directories cp (Copy File)

  cp means copying files or directories.

Usage: cp [option] source file target file options include:
-r: recursively copy all contents in the directory and its subdirectories
-l: create a hard link link file instead of copying the file itself
-i: if the target file If it already exists, it will be asked first when overwriting

3.8 Remove files or directories rm (Remove)

  rm removes files or directories.

Usage: rm [options] file or directory
-f: Force delete, ignore files that do not exist, do not prompt for confirmation
-i: Prompt for confirmation before each deletion
-r: Recursively delete directories and their contents
-d: Delete empty directories

3.8 Move files or directories, or change the name mv (Move file)

  mv moves files or directories.

Usage: mv [options] source file target file
-f: force means to force, if the target file already exists, it will not be asked but directly overwritten
-i: if the target file already exists, it will be asked whether to overwrite
-u: only in The move operation is performed when the source file is newer than the target file, or the target file does not exist.

4. Text editing related

5.Others

reference

Copyright statement: This article is an original article of the blogger, following the CC 4.0 BY-SA copyright agreement, reference link:
  1. Explanation of experimental exercises of common Linux commands
  2. Rookie tutorial - Linux
  3. Common commands of Linux

Daily ancient poetry

Titled Capital City Nanzhuang
Tang Cui Hu
Last year, today, in this door, the faces of people and peach blossoms reflected each other's red.
The human face does not know where to go, and the peach blossoms are still smiling at the spring breeze.

——2023.04.03

Jiang Nanchun
Tang Du Mu
Thousands of miles away, the orioles are singing, the green is reflected in red, and the wine flags are blowing in the water, villages and mountains.
Four hundred and eighty temples in the Southern Dynasties, many towers in the mist and rain

——2023.04.06

Guess you like

Origin blog.csdn.net/Ratib/article/details/129758630