[Linux] Basic instructions for getting started with Linux

1: ls command

Syntax : ls [options] [directory or file]
Function : For a directory, this command lists all subdirectories and files in the directory. For files, the file name is listed along with other information.

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

language : pwd
Function : Display the directory where the user is currently located

Three: cd command

language : cd name
Function : Change the working directory. Change the current working directory to the specified directory.
Options:
cd .. : Return to the upper directory
cd /home/user/linux/ : Connection path
cd ../day02/ : Sagami road diameter
cd ~ : Enter the user’s home directory
cd - : Return to the recently visited directory
Replenish:
In the Linux system, the files and directories on the disk are organized into a directory tree. Each node is a directory or file, so adding, deleting, checking, and modifying files is actually a Modification of multi-tree
  • Absolute path: Start from the root directory to the specified location 
        For example: /etc/rc.d/rc5.d is an absolute path, which locates the rc.5 file
  • Relative path: use the current directory as the reference point for positioning
        For example: the current location is var, ./ftp/etc is a relative path, and etc is located.
  • 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

language : touch [selection]... text...
Function : Create a file that does not exist.

Five: mkdir command

language mkdir [ selection ] dirname.. .
Function : Create a directory named “dirname” in the current directory
Options:
   mkdir -p
Function: Create multiple directories recursively
A directory a is created. Directory a contains directory b, and directory b contains directory c.
          

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]

When the subdirectory is deleted, if the parent directory also becomes an empty directory, the parent directory will be deleted together.

Seven: rm command

The rm command can delete files or directories at the same time
language rm [-f-i-r-v][dirName/dir]
Available : All users
Function : Delete files or directories
When using rm to delete a file, you will be prompted whether you want to delete the file, y means agree, n means disagree.
Options:

(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

The Linux command has many parameters. It is impossible for us to remember them all. We can get help by checking the online manual
If this is the first time to use the man command, you should install it first,Installation command: yum install -y man-pages a>
language : man [selection] command
Enter man ls, and the ls information will be displayed.
You can browse through the manual with the up and down keys, and press q to close the manual.
If you use the man command to search for the man command
You can find that the man manual is divided into eight chapters
1 is a normal command
2 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,fread
4 This is a special sentence case , This is also /dev Following various types of text items
5 refers to the format of the file , such as passwd , will explain the meaning of each field in this file
6 is reserved for games , is defined by each game
7 is an attachment and has some variables , such as environ This kind of global variable is explained here
8 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

Syntax : cp [options] source file or directory target file or directory
Function : Copy files or directories
Explanation : The cp command is used to copy files or directories. If two or more files or directories are specified at the same time, and the final destination If it is an existing directory, it will copy all the files or directories specified previously to this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear
Common selection :
-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 chain
If 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

 The mv command is the abbreviation of move , which can be used to move files or rename files (< /span> system. Often used to back up files or directories. Linux) is a commonly used command under move (rename) files
Syntax : mv [options] Source file or directory Target file or directory

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

language cat [selection][text]
Function : View the contents of the target file

Common selection:

-b Non-empty output line number
-n Number all lines of output
-s Do not output multiple blank lines
Supplement 1: How to quickly write a piece of code in a file
Cat can view the content of the file, so how can you quickly write a piece of code in the file? ------- nano command
Before using nano, you need to install it: Open it on the command line yum install -y nano
Demo:
First create a source file of test.c, then you can write code in the nano source file.
After writing the code, press ctrl+x and then y to exit.
After writing the code, you can use the cat command to view it.
Expansion: How to run the code after writing it? (Just understand it)
Step one: gcc source file (compile)
After compilation is completed, an a.out file will be generated.
Part 2: ./a.out (equivalent to execution)
Supplement 2: Output redirection
Linux has a philosophy:  Everything is a file
When we enter echo+string, we will find that the string is printed to the monitor. The process of printing on the monitor is actually equivalent to writing content in the monitor file.
But when we added a greater than sign and the file name at the end, we found that the string was not printed on the monitor, but instead there was an extra file called log.txt.
When we use cat to check the contents of this file, we will find that the string that should be printed on the screen is saved in the file. This is output redirection, but every time it is redirected, the contents of the file will be cleared first and then written (equivalent to Open the file in 'w' mode in C language)
You can even create an empty file directly by > file name. If you change the file to have content, you can also achieve the effect of clearing the file.

 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.

language more [selection][text]
Function : more command, the function is similar to cat, Can view file contents

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.

Language: less [number] sentence item
Supernatural ability :
less is similar to more , but uses less< /span> The entire file will not be loaded before viewing. less can only move forward, but not backward, andmore can browse files at will, but

Fourteen:head command

head  and  tail  is as easy to understand as its name, it is used Displays a certain number of text blocks at the beginning or end, head  is used to display the beginning of the file to the standard output, and tail  Of course I just read the end of the file.  
Syntax: head [parameter]... [file]... 
Supernatural ability :
head  is used to display the beginning of the file to the standard output. The default head command prints its corresponding The beginning of the file 10 lines.  
Selection: -n< Number of lines Showing number of lines

Fifteen: tail command

Syntax: tail[required parameters][select parameters][file] 
Function: Used to display the content at the end of the specified file
Options:

-n<Number of linesNumber 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

Users can set the format to be displayed. The format is set to a plus sign followed by several marks. The commonly used marks are listed below.
%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

Command format : cal [parameter][month][year]
Function : Used to view calendar and other time information. If there is only one parameter, it represents the year (1-9999) , if there are two parameters, it represents the month and year
Common selection :
-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

语法: find pathname -options
Function: is used to search for files in the file tree and perform corresponding processing (possibly accessing the disk)
Common options:
-name   Search for files by file name

Nineteen: grep command

Syntax: grep [options] Search string files

Function: Search for a string in the file and print out the found lines
Common options:
- 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 

Syntax: zip compressed file.zip directory or file
Function: Compress directories or files into zip format
Common options:
          -r recursively processes all files and subdirectories in the specified directory (use -r to compress the directory)
Example:
Suppose there are the following files in the dir directory , and you want to decompress them all (if you only want to compress certain files, just replace * with their names)
Compression:
        It can be seen that a .zip file will be generated directly under the current path.
Unzip:
        -d + path can decompress to the specified path, otherwise decompress directly to the current directory

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)

Common options:
  • -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:

Decompression:  -C can decompress to the specified path

Guess you like

Origin blog.csdn.net/m0_74910646/article/details/134666993