Linux - practical operation 2 - common instructions

1, Seven operating levels of linux

Operation level description:
0: shutdown
1: Single user [ retrieve lost password ]
2: There is no network service in multi-user state
3: Network service in multi-user state
4: The system is not used and reserved for users
5: Graphical interface
6: Restart
The common domains are 3 and 5. To modify the operation level of the system, you can:

2, Help instruction

2.1 man is used to obtain the help document of an instruction.

View ls's help documentation
man ls
Note: exit help documentation: q

2.2 help

Check out the cd's help documentation

help cd

3, File directory class

3.1 pwd view the absolute road strength of the current directory


3.2 ls [options] [directory or file]: View

## View file list
## View file list long directory
ls -l
## ## View the long directory of the file list and show hidden files
ls -la 

3.3 cd [option]: Open Directory

## Go back to your home directory
cd ~
cd enter
## Go back to the previous directory of the current directory
cd .. 
## Navigate to the directory in a relative manner
[root@localhost home]# cd ../etc
## Navigate to the directory in absolute mode
[root@localhost home]# cd /etcc'd

3.4 mkdir [options] name of folder to be created: create folder

## Create a directory under home
mkdir /home/video
## Create multi-level directory
mkdir -p /mnt/aaa/bbb/ccc

3.5 rmdir [options] empty directory to delete

[root@localhost ccc]# mkdir -p /mnt/aaa/ddd
## The directory to be deleted is empty
[root@localhost ccc]# rmdir /mnt/aaa/ddd
## rmdir can only delete empty directories
[root@localhost ccc]# rmdir /mnt/aaa
rmdir: delete "/mnt/aaa" fail: directory not empty
## Delete non empty directory
[root@localhost ccc]# rm -rf /mnt/aaa

3.6 touch file name: create an empty file

## Create an empty test.txt file
touch test.txt
## Create multiple empty files at once
touch ok1.txt ok2.txt ok3.txt

3.7 ★ copy [options] source dest: you can copy files or folders

Copy the source file or folder to dest.
Common options: - r recursively copy the entire folder

## Copy ok1.txt under aaa to bbb/ok5.txt. The relative path or absolute path used here can also be used
cp aaa/ok1.txt bbb/ok5.txt
## Copy aaa folder recursively into ccc. If there is a file with the same name in ccc, you will be prompted whether to overwrite it
cp -r aaa/ ccc/
## Forced copy. If there is a file with the same name in ccc, you will not be prompted to overwrite it, but directly overwrite it.
\cp -r aaa/ ccc/

★ 3.8 rm [options] file / folder: delete file or folder

Recursively removes the contents of the directory.
Ignore nonexistent files and never prompt the user.

## Delete file, prompt
rm ok1.txt
## Delete file, no prompt
rm -f ok2.txt
## Prompt for deleting files
rm -r /mnt/ccc
## Delete folder no prompt
rm -rf /mnt/ccc
## Delete multiple files plus
rm -rf /mnt/ccc mnt/aaa

3.9 mv source destination: move files or rename

## Move to bbb and rename it
[root@localhost bbb]# mv ../aaa/ ../bbb/
## Move to bbb, and the file name is still
[root@localhost bbb]# mv ../aaa/ ../bbb/

3.10 cat [options] file path: view the file. It is read-only and cannot be modified

It is usually used in combination with more and displayed page by page
Options: - n display line number

## -n displays the line number, and more displays it in pages 
cat -n | more

3.11 more: displays the contents of the file page by page in a full screen manner


Shortcut key for more
Space: page turning
enter: next line
q: Exit
ctrl+f: previous screen
ctrl+b: next screen
=: output the line number of the current line
: f output file name and current line number

3.12 ★ less: it is used for split screen display of file content, with high speed. It does not read the whole file, but read it in pages.

You can view large log files


Shortcut key
Space: page turning
enter: next page
q: Exit
/Character: search down [character]: n view the next; N view previous.
? Character: search up [character]: n view the previous; N view next.

3.13 > output redirection, > > append instruction

Basic syntax:
LS - L > file

## Overwrite the content obtained from ls -l into
[root@localhost mnt]# ls -l >
## Append the result of ls -al / to
[root@localhost mnt]# ls -al / >>
## Append the contents of the file to
[root@localhost mnt]# cat >>
## Overwrite the calendar into; cal gets the calendar
[root@localhost mnt]# cal >

3.14 use of echo, head, ★ tail.

echo: output content to the screen, which can be used to output environment variables
head: view the first 10 lines of information in the file.
tail: view the last 10 lines of information in the file. Can be used to view logs

## Output JAVA_HOME and PATH information
[root@localhost mnt]# echo $PATH -------------- $JAVA_HOME
/opt/anaconda3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/tiandy/.local/bin:/home/tiandy/bin:/usr/local/anaconda3/bin:/root/bin -------------- /opt/java/jdk-1.8
## View the first 5 lines of the file
[root@localhost mnt]# head -n5
## View the last 5 lines of the file, -n5 display the last 5 lines, -f update the newly added content in real time,
[root@localhost mnt]# tail -f -n5

3.15 in [option]: Create Shortcut

Options: - s: soft connection, software
in -s source file and / or directory soft connection name

## Establish soft connection
[root@localhost mnt]# ln -s /mnt/aaa linktoaaa
## When deleting the soft connection, the linktoaaa must not be followed by /, otherwise it cannot be deleted
[root@localhost mnt]# rm -rf linktoaaa

3.16 history: history command record

## Get command history
## 171 is the number before a command found in history. Execute this command
! 171

4, Date category directory

4.1 date: set the date and time, and display the time and date

Basic syntax:
date -s "2021-11-17 22:29:29"
date (display current time)
date + %Y
date + %m
date + %d
date + "%Y-%m-%d %H:%M:%S"

## Set the system time to 2021-11-17 22:29:29
[root@localhost bin]# date -s "2021-11-17 22:29:29"
2021 Wednesday, 17 November:29:29 CST
## Display year
[root@localhost bin]# date +%Y
## Show month
[root@localhost bin]# date +%m
## Display day
[root@localhost bin]# date +%d
## Year, day, hour, minute and second in a specific format
[root@localhost bin]# date "+%Y-%m-%d %H:%M:%S"
2021-11-17 22:26:25```

4.2 cal: display calendar

## Displays the day of the current month
## Displays the calendar for a full year
cal 2021

5, Search class

5.1 find [search scope] [options]: find files or folders

-Name finds the specified file name
-User finds the file under the specified user
-Size find according to the specified file size

## Find the file named note.txt in the directory (or subdirectory) of / opt/elasticsearch-7.11.2/ and find it accurately
find /opt/elasticsearch-7.11.2/ -name NOTICE.txt
## Find the file whose owner is tiandy in the / opt directory (or subdirectory)
find /opt -user tiandy
## Find files larger than 20M in the / opt directory (or subdirectory)
find /opt -size +20M
## Find files smaller than 20M in the / opt directory (or subdirectory)
find /opt -size -20M
## Find a file equal to 20M in the / opt directory (or subdirectory)
find /opt -size 20M
★ Find by wildcard
find /opt -name *.txt

5.2 locate file or folder: quickly find files

Before the first execution, first create the locate query database

## Before the first execution, first create the locate query database
## Fuzzy search for files or folders in elasticsearch
locate elasticsearch

★ 5.3 grep instructions and pipeline symbols|

grep [options] search content: indicates filter search
Options: - n display line number- i ignore case
|: the pipe symbol indicates that the processing result output of the previous command is passed to the subsequent command processing.

hold cat The content of is passed|Give it to the back grep Find instruction processing -n Display line number,-i Case insensitive ip content
[root@localhost opt]# cat | grep -ni ip

6, Compression and decompression class

6.1 gzip and gunzip: file compression / decompression instructions

gzip: compressed file. The source file is lost after compression
gunzip: unzip the file.

## Compressed the compressed source file is deleted
[root@localhost mnt]# gzip
## Unzip the file. After unzipping, is deleted
[root@localhost mnt]# gunzip 

6.2 zip and unzip: compression / decompression instructions

zip [options]: -r recursively compress folders
unzip [options]: the location where the - d file is unzipped

zip -r /mnt/aaa
unzip -d /mnt/bbb /mnt/

6.3 ★ tar: compression and decompression instructions

tar instruction is a packaging instruction. After packaging, the file suffix is:. tar.gz.
Basic syntax:
Tar [options] xxx.tar.gz
Option Description:
-c: Package create to generate tar file
-v: Display details
-f: Specifies the compressed file name
-z: Pack and compress
-x: Unzip the tar file

## Package ok1.Java and into a.tar.gz
[root@localhost aaa]# tar -zcvf a.tar.gz 
## Unzip a.tar.gz to the current directory x
[root@localhost aaa]# tar zxvf a.tar.gz 
## Unzip a.tar.gz to the specified folder / mnt/aaa/bbb. Note that - C (Change) is uppercase.
[root@localhost aaa]# tar -zxvf a.tar.gz -C /mnt/aaa/bbb

Tags: Linux server

Posted on Thu, 18 Nov 2021 19:48:29 -0500 by jharbin