The fourth session of the 2021 training course (commands, pipe symbols, redirections and environment variables that novices must master)

2.7 File directory management commands
1. The touch command creates a new version of a file (similar to Notepad). The
touch command is used to create a blank file or set the time of the file. The format is "touch [option] [file]".

Difficult operations are mainly reflected in setting the modification time (mtime) of the file content, the modification time (ctime) of the file permissions or attributes, and the file reading time (atime). Parameters of
touch command and their functions Parameters of touch command and their functions
The fourth session of the 2021 training course (commands, pipe symbols, redirections and environment variables that novices must master)The fourth session of the 2021 training course (commands, pipe symbols, redirections and environment variables that novices must master)

2. mkdir command
mkdir command is used to create a blank directory, the format is "mkdir [option] directory".
-p parameter to recursively create a file directory with nested stacking relationship.
[root@linuxprobe linuxprobe]# mkdir -pa/b/c/d/e
[root@linuxprobe linuxprobe]# cd a
[root@linuxprobe a]# cd b [root@linuxprobe b]#

3. cp command The
cp command is used to copy files or directories, the format is "cp [option] source file target file". Everyone should be familiar with the file copy operation. In Linux systems, the copy operation is divided into 3 situations:
if the target file is a directory, the source file will be copied to the directory;
if the target file is also a normal file, it will ask Do you want to overwrite it;
if the target file does not exist, perform a normal copy operation.

4. mv command cut or rename
mv command is used to cut or rename a file, the format is "mv [option] source file [target path|target file name]".
The cut operation is different from the copy operation because it deletes the source file by default and only keeps the cut file. If you cut a file in the same directory, you actually rename it:

5. The rm command is
used to delete a file or directory, and the format is "rm [option] file".
-f parameter to force deletion, no need to remind again
-r parameter to delete a directory

6. dd command The
dd command is used to copy files or convert files according to the specified size and number of data blocks, the format is "dd [parameter]".

7. The file command is
used to view the type of the file, and the format is "file filename".

2.8 Package compression and search commands

1. The tar command
tar command is used to pack or decompress files, the format is "tar [option] [file]".

Parameters
role
-c
create a compressed file
-x
Extract the files
-t
to see which files are compressed within the package
-z
with Gzip compression or decompression
-j
with bzip2 compression or decompression
-v
process display compression or decompression of the
-f
target file name
- p
retain the original permissions and attributes
-P
use absolute path to compress
-C
specify the directory to decompress to

(Packaging operation) Common collocation: czvf czv can change position, f is not changeable
tar czvf compressed package name.tar.gz name to be packaged
c packaged
z gzip format.tar.gz
j bzip2 format.tar.bz2
v display process
f file Name
exam original question:
tar czvf backup.tar.gz /etc
(decompression operation) Common collocation: xzvf xczv can change the position, f is not changeable
tar xzvf compressed package name.tar.gz -C parameter (specify which directory to decompress to)
Exam original questions:
tar xzvf backup.tar.gz -C /root/etc

2. The grep command The
grep command is used to perform keyword search in the text and display the matching results, the format is "grep [option] [file]"
cut is to extract information by column
grep is to extract information by line

grep keyword file name one of the exam content
grep oo initial-setup-ks.cfg (extract the line where oo is the keyword)

3. Find command Full search
find command is used to find files according to specified conditions, the format is "find [search path] Find condition operation".

Exam original questions
find /-user linuxprobe search for the attributor
find / -mtime 1 Files modified within 1 day

Chapter 3 pipe character, redirection and environment variables. 3.1 Input and output redirection
Standard input redirection (STDIN, file descriptor is 0): Input from the keyboard by default, or input from other files or commands.
Standard output redirection (STDOUT, file descriptor is 1): The default output is to the screen.
Error output redirection (STDERR, file descriptor 2): The default output is to the screen.

Input redirection is to import the content of the file as standard input information into the command.

3.2 Pipeline command symbol

Redirection command and file
pipe character Command and command
pipe character: use the result of the previous command as the standard input of the next command for secondary processing.
View the current system has several users can log server
grep / bin / bash / etc / passwd
Number Number
grep / bin / bash / etc / passed | wc -l

3.3 The wildcard character * in the command line means to match a null value or an infinite number of values
? Represents matching a value (must be followed by a digit)
[az] lowercase letters
[AZ] uppercase letters
[0-9] numbers
[1,3,5] specify numbers (use a comma to be more rigorous)
[a,c,e] specify letter

{1,3,5} An error will be reported
if the value is not matched [1,3,5] If the value is not matched, the value will not be displayed
3.4 Commonly used escape characters
Backslash (\): Make a variable after the backslash Become a simple string.
Single quotation mark (''): escape all variables in it as simple strings.
Double quotation marks (""): Keep the variable attributes in it, without escaping.
Backquote (``): Return the result after executing the command.

3.5 Important environment variables 1. Direct execution in path form
2. Alias ​​form to execute alias
3. Internal commands
4. External commands

Environment variable PATH The
PATH variable is the little assistant of the bash interpreter, telling us where the commands outside the system are stored

Linux system, the most important of the 10 environment variable
variable name
action
HOME
user's home directory (ie home directory)
SHELL
Shell interpreter name of the user in the use of
HISTSIZE
history command output number of records
HISTFILESIZE
saved command number of records
MAIL
Mail Save the path
LANG
system language, language family name
RANDOM
Generate a random number
PS1
Bash interpreter prompt
PATH
defines the path that the interpreter searches for the user to execute the command
EDITOR The
user’s default text editor

Guess you like

Origin blog.51cto.com/15082285/2603098