1: ls command
ls without options displays subdirectories and files that exist in the current directory.
Common options:
(1). ls -l
Function: List detailed information of files.
Can be abbreviated as ll
Supplement: File = file content + file attributes
What is displayed before the name are some attributes of the file
(2). ls -a
Function: List all files in the directory, including hidden files starting with .
-The beginning indicates an ordinary file
Starting with d means directory
The beginning of . indicates a hidden file, so when we create a file, add . before the file name to indicate that a hidden file is created.
Replenish:
There are two hidden files in any directory in Linux, one is . The other is ..
- A dot represents the current path, which facilitates us to find the file (executable file) in the current directory
- Two dots represent the upper-level path, which is convenient for the path to go back. You can use it to go back to the previous level.
(3).ls -d
Function: -d Display the directory like a file instead of displaying the files under it. For example: ls –d specifies directory
(4). ls -1
Function: Only output one file per line
2: pwd command
Three: cd command
cd .. : Return to the upper directorycd /home/user/linux/ : Connection pathcd ../day02/ : Sagami road diametercd ~ : Enter the user’s home directorycd - : Return to the recently visited directory
- Absolute path: Start from the root directory to the specified location
- Relative path: use the current directory as the reference point for positioning
- Home Directory:
For the root account: the default home directory is /root root represents the super administrator account
For ordinary user accounts:/home/XXX XXX is the new user name
Four: touch command
Five: mkdir command
Six: rmdir command
rmdir is a command corresponding to mkdir. mkdir is to create a directory, and rmdir is a delete command.
Syntax: rmdir [directory name]
Function: Delete empty directories
Options:
rmdir -p [directory name]
Seven: rm command
(1). rm -f
f means force. Delete the file directly for me without asking.
(2). rm -r
-r means recursive deletion. When deleting a directory, you must add the -r option, otherwise it cannot be deleted, but you will still be asked whether it is really deleted.
So when you want to delete a directory directly:
rm -rf
Indicates forced recursive deletion. This command is also the most practical.
Eight: man command
1 is a normal command2 is a system call , such as open,write and the like ( Through this, you can at least easily find out what header files need to be added to call this function. )3 is a function , as printf,fread4 This is a special sentence case , This is also /dev Following various types of text items5 refers to the format of the file , such as passwd , will explain the meaning of each field in this file6 is reserved for games , is defined by each game7 is an attachment and has some variables , such as environ This kind of global variable is explained here8 This is a command for family management , This is just a trivial command< a i=4>root use,asifconfig
So how should these chapters be used?
For example, if I want to search for the printf function in C language in the man manual, I should look for it in Chapter 3.
Command: man 3 printf
ps. If you don’t add a chapter, it will search from the beginning to the beginning from the first chapter by default. However, the search will stop when it encounters a command called printf. What is searched is not necessarily the printf in Chapter 3.
Nine: cp command
-f or --force Forcibly copy a file or directory, regardless of whether the destination file or directory is Already exists-i or --interactive Previously read the cover text-r Recursive processing, processing files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to the directory or symbolic chainIf connected, it will be treated as an ordinary file.-R or --recursive recursively process the files and subdirectories in the specified directory Processed together
Example:
There is only one file called test.c in the current directory.
Copy a file and rename it to data
cp src dst
Both src and dst can be absolute paths or relative paths.
For example, I am currently in the /root directory and I want to copy the data files in its subdirectory mydir directory to the current directory.
cp ./mydir/data .
10: mv command
Supernatural ability:
(1).Rename mv file name to new name
(2) Move file mv file name to new path
Move the file to a new path
The specific function to be implemented depends on the second parameter. If it is a file name, it is renamed. If it is a directory or path, it is moved.
Options:
-f : force means force. If the target file already exists, it will not be asked. Direct coverage-i : If the target file (destination) already exists, it will ask whether to overwrite it. !
11:cat command
Common selection:
-b Non-empty output line number-n Number all lines of output-s Do not output multiple blank lines
Supplement 3: Additional redirection
Adding two greater than signs can continue to append content after the file content, which is equivalent to opening the file in the 'a' mode in the C language
Supplement 4: Input redirection
If nothing is added after the cat command, the default is to read the data from the keyboard and then display the data on the screen.
If you add a < file name, the data will be read from this file and displayed on the screen. This is called input redirection.
It can be found that this can also achieve the effect of cat file name, but the implementation methods of the two are completely different.
12: more command
Although the cat command can view the content of the file, if you use it to view a large file, it will be quickly displayed from the beginning to the end of the file, and you cannot browse through it. The more command is more user-friendly than the cat command. After more file, it will move the file from The screen will fill up when you open it. You can press Enter to read down line by line. The disadvantage is that you cannot read up to view.
Thirteen: less command
The less command is the most suitable command for flipping through large files. It can be flipped up and down using the up and down keys.
Fourteen:head command
Fifteen: tail command
-n<Number of lines> Number of explicit lines
Replenish:
You can view the content at the beginning of the file through head, and you can view the content at the end of the file through tail. How to view the content in the middle of the file?Here we will explain the pipeline: converting data Transportation from one end to the other
For example, if there is a large file with 10,000 lines, what should I do if I want to view the content from lines 9000 to 9010?
head -9010 Sentence subject | tail -10
Interpretation:
head -9010 file name filters out the first 9010 lines of the file, | is equivalent to a pipeline, tail -10, checks the last ten lines of the transported data
16: Time-related instructions
date
%H : 小时 (00..23)%M : minute (00..59)%S : 秒 (00..61)%X : equivalent %H:%M:%S%d : 日 (01..31)%m : 月份 (01..12)%Y : Complete Year (0000..9999)%F : equivalent %Y-%m-%d
Seventeen: cal instruction
-3 Display the system’s calendar of the previous month, current month, and next month-j displays the day of the year (dates in a year are calculated in days, starting from 1 Starting from month 1 , the number of days in the current month in the year is displayed by default)-y Display the calendar of the current year
18: Find command
Nineteen: grep command
Syntax: grep [options] Search string files
- i : Ignore the difference in case, so the case is considered the same-n :Delivery number-v : reverse selection, that is, no ' search characters are displayed String ' The line of content
The following information is stored in the test.txt file
Now I want to search for data except for bits and display the line number, which is not case sensitive.
Twenty.zip&&unzip
It can be seen that a .zip file will be generated directly under the current path.
21:tarDirective
Syntax: Newbies only need to remember the option combinations -czf for compression and -xzf for decompression
Function:Compression and decompression (same function as zip, but different compression algorithms)
- -c: Parameter command to create a compressed file (meaning create);
- -x: Parameter command to unpack a compressed file!
- -t: View the files in tarfile!
- -z: Does it also have the attribute of gzip? That is, do I need to use gzip compression?
- -j: Does it also have the attributes of bzip2? That is, do I need to use bzip2 compression?
- -v: Display files during compression! This is commonly used, but it is not recommended to be used in background execution processes!
- -f: Use the file name, please note that the file name must be followed immediately after f! Don't add any more parameters!
- -C: Extract to the specified directory
compression: