[Linux] 32 instructions to help you play Linux!

Table of contents

1,whoami

2,who

3,pwd

4,ls

1,ls 

2, ls -l

3, them -a

4,ls -al

5, ls - d

 6,ls -ld

5,clear

6,cd

1,cd 

2,cd .

3,cd ..

4. cd /home/litao/linux/ absolute path

5. cd ../day02/ relative path

6,cd ~

7,cd -

7,tree

8,touch

9,mkdir

1,mkdir

2,mkdir -p

10,rmdir && rm

1, is rm

2,rm

3,rm -f

4,rm - r

5,rm -rf

6,rm -i

7,rm -rf *

11,man

12,nano 

13,cp

1,cp

2,cp -rf

3,cp -rf *

14,mv

15,echo

16,cat

1,cat 

2,cat -n

3,cat -b

4,cat -s

5,tac

6,cat <

17,more

18,less

1,less

2, / string

19,head

20,tail

21,date

22,Cal

23,find -name

24,which

25,whereis

26, grip

1, grip

2,grip -i

3,grip -n

4,grip -v

27,sort

1,sort

2,sort -r

28,uniq

1,uniq

2,uniq -u

3,uniq -d

4. sort & uniq to remove duplicates

5,sort | uc

Count the number of occurrences of each line

6,sort | uniq | wc -l

29,.zip / unzip

1,zip

2,zip -r

3,unzip -d

30, takes

1,tar - part

2,takes -xzf

3,tar -xzf -C

31. Several important hot keys [Tab], [ctrl]-c, [ctrl]-d

32. Shut down


1,whoami

 Check who the current account is

The current account is root; 

2,who

Who is currently logged into my machine

Currently, only root has logged in, and the login time is on the right;

3,pwd

Display the current directory of the user

4,ls

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

Common options:

-a  List all files in the directory, includinghidden files starting with . .

-d  Display the directory like a file, rather than displaying the files below it. For example: ls –d Specify directory

-i  output sentence item i point index information. as ls –ai specified sentence item

-k  to k Characteristic format expression Sentence size. ls –alk Specified sentence item

-l  Detailed information.

-n  Numerical UID,GID Alternative name. (intervention UID, GID)

-F  Append a character after each file name to indicate the type of file, “*” < a i=3> represents an executable ordinary file; “/”  represents a directory; “@” a> “=" . (Directory type identification) (sockets) represents sockets represents FIFOs; “|”  represents symbolic links;

-r  对目录oppositeexclusion.

-t  aftertimeexclusion.

-s  Outputs the size of the file after l the file name. (Size sorting, how to find the largest file in a directory)

-R  List files in all subdirectories. (recursive)

-1  Only output one file per line

1,ls 

Display the names of files in the current directory

There is only test in the current directory;

2, ls -l

Display attribute information of files in the current directory

ls -l can also be written as ll; 

This is a directory containinga file named "test" root. 20:46, the time is10 On the 7th of the month user group, and the creation date of the file is root user, the group to which the file belongs is also bytes, file owner is 0, file size is

3, them -a

List all files in the directory, including hidden files starting with . a>

We come to the bottom of the 886 directory to show you; 

The only file in the current directory is wxd.txt ;

ls -a can openall files, including files beginning with Implicit files starting with .;

4,ls -al

Similarly, ls -al can open the file attribute information including the implicit file< /span>;

ls -al can be written as ls -la can also be written as ls -a -l and ll -a  are both possible, the order is not important;

Various ways of writing are possible;

5, ls - d

Display information about the directory itself

 6,ls -ld

Display detailed information of the specified directory

5,clear

Clear screen-----Clear all content on the screen

 Press Enter to clear the screen

6,cd

In the Linux system, the files and directories on the disk are composed of a directory tree . Eachnode is a directory or file.

Language: cd 目录名

Function: Change the working directory,change the current working directory to the specified directory.

Example:

cd .. :                                 

cd /home/litao/linux/ :       Continuous road diameter

cd ../day02/ :                      

cd ~:                                 

cd -:                                  

1,cd 

This is our current directory; 

cd [directory] ------switch to the specified directory

Directly enter the file name

You can also enter the path

2,cd .

cd . represents the current path

3,cd ..

cd .. represents the superior path

This returns to the upper level path;

Like the hidden files here. represents the current path, .. represents the superior path;

4,cd /home/litao/linux/ 绝对路路

We start from the / directory and locate a leaf file, forming a path: absolute path

This is an absolute path, starting from the root directory [/];

Relative to the directory we are currently in as the reference point, we locate the path of a file: relative path

This is a relative path;

6,cd ~

Enter user home directory

Return directly to the home directory;

It doesn’t matter how far the path is;

7,cd -

Return to recently visited directory

Whether at the upper or lower level, the recently accessed directory is directly returned;

7,tree

Display the subdirectories and files of the current directory in a tree structure

[.] means the current directory, which is now the same as a tree;

8,touch

Syntax: touch [option]... file...

Function: touch The command parameters can change the date and time of a document or directory, including access time and change time, or create a new file that does not exist

Common options:

 -a :    or --time = atime or --time = access or --time = use Just update and save time

 -c :    or --no-create  fukentateinhebunsen

 -d:    Use the date and time specified by instead of the current time

  -f:    This parameter will be ignored and not processed, only responsible for solving BSD version touch compatibility issue

-m:    or --time = mtime or --time = modify  ​ Just change the change time.

  -r:    Set the date and time of the specified document or directory to be the same as the date and time of the reference document or directory

  -t:    Use the specified date and time instead of the current time

1,touch

Create a normal file

It’s that simple, just create it;

You can also create many files at once;

9,mkdir

Syntax: mkdir [options] dirname...

Function: Create a directory named "dirname" in the current directory

Common options:

-p, --parents  can be a path name, in this case if Somedirectories do not exist yet. After adding this option, the system will automatically createRemove those directories that do not yet exist,That is, multiple directories can be created at one time

1,mkdir

Create directory under current directory

Create a directory directly;

2,mkdir -p

Create a path in the current directory

Create a path directly and get it right with just one click;

10,rmdir && rm

rmdir is the counterpart to mkdir. mkdir is to create a directory, and rmdir is a delete command

Syntax: rmdir [ -p ] [ dirName ]

Applicable objects: All users with permission to operate the current directory

Function: Delete empty directories

Common options:

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

The rm command can delete files or directories at the same time

Syntax: rm [ -f -i -r -v ] [ dirName/dir ]

Applicable to: All users

Function: Delete files or directories

Common options:

-f: Even if the file attribute is read-only (i.e. write-protected), it will be deleted directly.

-i: Ask for confirmation one by one before deleting

-r: Delete the directory and all files under it

1, is rm

Delete ordinary files

In this way, you can delete it directly. Remember to delete only empty directories;

2,rm

When deleting ordinary files, there will be a confirmation option.

y stands for yes, n stands for no;

3,rm -f

Forcefully delete empty directories (no more questions)

4,rm - r

You can delete an entire directory (everything in the directory will not be spared)

But we have to confirm every time, y means yes, n means no;

5,rm -rf

Force recursive deletion without asking

Direct recursive forced deletion is very cool!

6,rm -i

In a normal home directory, there is no option to delete files, which can easily lead to mistaken deletion, so adding -i will pop up the option;

The two are evident in contrast;

Notice:

Under the root user, the option will pop up regardless of whether -i is added or not. -i is only for ordinary users;

7,rm -rf *

Delete all contents in the current directory, including directories and files (hidden files starting with . will not be deleted)

The ultimate invincibility, delete it directly with one click;

The system does not delete hidden files by default;

11,man

Linux commands have many parameters, and it is impossible for us to remember them all. We can get help by checking the online manual. The command to access the Linux man page is man

Syntax: man [options] command

Common options:

-k: Search online help based on keywords

        num is only found in chapter num

-a: Display all chapters, such as man printf. By default, it starts searching from the first chapter and stops when it is known. Use the a option. When pressing q to exit, it will continue to search until all chapters are searched. complete

There are 9 manual numbers below and all the instructions are in there;

Press q to exit

When we search for instructions, we default to searching from the first manual backward until we find it;

You can also specify a manual number to search in;

Writing this way has the same effect;

If it is not in the manual, it will prompt for instructions;

12,nano 

Write to the file, and automatically create the file if it does not exist;

 We write it first;

There are indicator icons below the screen, ^x means exit; 

 Just choose to save here;

We then use the [cat] command to check, this command will be discussed later; 

 If the file to be written does not exist in this directory, its file will be automatically generated;

13,cp

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 is an existing directory, it will copy all the files or directories previously specified to this directory . If multiple files or directories are specified at the same time, and the final destinationis not an existing directory, an error message will appear

Common options:

-f: or --force forcefully copies a file or directory, regardless of whether the destination file or directory already exists.

-i: or --interactive ask the user before overwriting the file

-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 link, it will be treated as an ordinary file.

-R: or --recursive recursive processing, processing files and subdirectories in the specified directory together

1,cp

Copy files

Here you can see that the file is automatically generated;

The contents of the files are the same, which means the copy was successful;

2,cp -rf

copy directory

cp dir1 -rf .. can also be written as cp -rf dir1 .. ; 

Obviously, the directory was copied successfully;

You can also specify a name to copy;

3,cp -rf *

Copy everything in the current directory

 This is the information in the first two directories;

After copying, all contents in the dira directory are copied to the code directory;

Another point is that whether it is copying or deleting, it does not involve hidden files, which is the system default;

14,mv

The mv command is the abbreviation of move. It can be used to move files or rename files (move (rename) files). It is a commonly used command under Linux systems and is often used to back up files or directories.

Syntax: mv [options] source file or directory target file or directory

Function:

1. Depending on the type of the second parameter in the mv command (whether it is a target file or a target directory), the mv command renames the file or moves it to a new directory.

2. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name). It will rename the given source file or directory to the given one. specified target file name.

3. When the second parameter is the name of an existing directory, there can be multiple source files or directory parameters, and the mv command will move all the source files specified by each parameter to the target directory.

Common options:

-f: force means force. If the target file already exists, it will be overwritten directly without asking.

-i: If the target file (destination) already exists, it will ask whether to overwrite it!

Move files (equivalent to cutting)

The file has been moved successfully;

You can also change the name of the moved file;

In this way, the file is moved and the name is changed;

15,echo

Directly printing the input string on the screen, or directly inputting it into a file, is more convenient than the nano command.

The input string is printed directly on the screen;

You can also use > to write to a file;

If the file name does not exist in the current directory, its file will be automatically generated;

When there is no content but points to a file that does not exist, the file will be generated in the current directory;

Moreover, the content of the original file is cleared before input, so > can also be used to clear the original file;

If >> is used, the contents of the original file will not be cleared, but will be superimposed;

【>】Also called output redirection

【>>】Also called append redirection

16,cat

Suitable for short files

Syntax: cat [options] [file]

Function: View the contents of the target file

Common options:

-b : Number non-empty output lines

-n : Number all lines of output

-s: Do not output multiple blank lines

1,cat 

Print the contents of the file

In fact, we have used this many times before, and everyone should be familiar with it;

Usage is very simple, just connect the file directly;

There is another usage of cat

Without the file name, whatever you enter will be printed.

2,cat -n

Number all lines of output

Number all lines of output

3,cat -b

Number non-empty output lines

For empty lines, the line number is not output;

4,cat -s

Do not output multiple blank lines

Multiple consecutive blank lines will be compressed;

5,tac

Reverse output of content

When the name is reversed, it is directly contrary to the will of heaven;

6,cat <

The function remains unchanged and is output directly, [<] is input redirection;

17,more

Syntax: more [option] [file]

Function: more command, similar to cat

Common options:

-n: Number all lines of output

 q: Exit more

 

There are a thousand lines of information in this file. If you use more, you can only use Enter to scroll down one by one;

18,less

Suitable for long files

The less tool is also a tool for paging display of files or other output. It should be said that it is an orthodox tool for viewing file contents in Linux, and it is extremely powerful.

The usage of less is more flexible than that of more. When it comes to more, we have no way to turn forward, we can only look back.

But if you use less, you can use the [pageup][pagedown] and other key functions to browse files forward and backward, which is easier to view the contents of a file!

In addition, you can have more search functions in less. You can not only search down, but also search up.

Syntax: less [parameter] file

Function:

less is similar to more, but with less you can browse the file at will, while more can only move forward, not backward, and less does not load the entire file before viewing.

Options:

-i: Ignore case when searching

-N: Display the line number of each line

/String: Function to search down for "string"

?String: Function to search up for "string"

n: Repeat the previous search (related to / or ?)

N: Repeat the previous search in reverse (related to / or ? )

q:              quit

1,less

It can be flipped up and down, very flexible (press q to exit)

2, / string

forward search

19,head

head and tail are as easy to understand as their names. They are used to display 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 is used to read the file. end.

Syntax: head [parameter] ... [file] ...

Function:

head is used to display the beginning of the file to the standard output. The default head command prints the first 10 lines of its corresponding file.

Options:

-n: Number of lines to display

Very convenient, just check the first few lines;

20,tail

The tail command writes the file to the standard output starting from the specified point. Use the -f option of the tail command to conveniently check the changing log file. tail - f filename will display the last content of filename on the screen, and not only refresh , allowing you to see the latest file content.

Syntax: tail [required parameters] [optional parameters] [file] 

Function: Used to display the content at the end of the specified file. When no file is specified, it will be processed as input information. Commonly viewed log files

Options:

-f: loop reading

-n: Display the number of lines

head is to print the first few lines, and tail is to print the last few lines. The usage is the same;

If we want to print the middle part, for example, print 800 -- 809;

or:

 

Just combine them;

21,date

date display

Date specifies the format to display time: date +m:%d;

1. In terms of display, users can set the format to be displayed. The format is set to a plus sign followed by several marks. The list of commonly used marks is as follows:

%H : hours (00..23)

%M: Minutes (00..59)

%S: Seconds (00..61)

%X: Equivalent to %H:%M:%S

%d: day (01..31)

%m : month (01..12)

%Y : Complete year (0000..9999)

%F: Equivalent to %Y-%m-%d

2. In terms of setting time

date -s //Set the current time, only root permissions can set it, others can only view it

date -s 20080523 //Set to 20080523, which will set the specific time to empty 00:00:00

date -s 01:01:01 //Set the specific time and the date will not be changed.

date -s “01:01:01 2008-05-23″ //This can set the entire time

date -s “01:01:01 20080523″ //This way you can set the entire time

date -s “2008-05-23 01:01:01″ //This can set the entire time

date -s “20080523 01:01:01″ //This way you can set the entire time

3. Timestamp

Time->Timestamp: date +%s

Timestamp->Time: date -d@1508749502

Unix timestamp (Unix epoch, Unix time, POSIX time or Unix timestamp in English) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), regardless of leap seconds

Dates are viewed the same way using y m d and f;

Same as above, and you can also use symbols to link them;

This thing is a timestamp, which is the number of seconds from January 1, 1970 to now;

You can also use -d @ to view the date corresponding to the timestamp;

22,Cal

The cal command can be used to display the Gregorian (Solar) calendar. The Gregorian calendar is the calendar currently used internationally, also known as the Gregorian calendar and commonly known as the Gregorian calendar. The "Gregorian Calendar", also known as the "Solar Calendar", is based on the earth's orbit around the sun being one year. It is common in Western countries, so it is also called the "Western Calendar".

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

-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 January 1st, and the number of days in the year of the current month is displayed by default)

y : Display the calendar of the current year

Just display the calendar directly;

It can also be followed by the year, then the calendar of that year will be output;

You can also -3 to see the calendar of last month, this month, and next month, but it is limited to -3 and -1;

23,find -name

The find command under Linux searches for files in the directory structure and performs the specified operation.

The find command under Linux provides quite a few search conditions and is very powerful. Because find has powerful functions, it also has many options, most of which are worth our time to understand.

Even if the system contains a Network File System (NFS), the find command is also valid in the file system, as long as you have the corresponding permissions.

When running a very resource-consuming find command, many people tend to execute it in the background, because traversing a large file system may take a long time (here refers to a file system of more than 30G bytes).

Syntax: find pathname -options

Function: Used to search for files in the file tree and process them accordingly (possibly accessing the disk)

Common options:

-name Search for files by file name.

Refers to the path under which to find this file, followed by the file name;

24,which

Only search instructions, faster than find;

You can check it directly, which is very convenient;

25,whereis

Find documentation, very comprehensive

Very convenient and comprehensive;

26, grip

Syntax: grep [options] Search string files

Function: Search for a string in a file and print out the found lines

Common options:

-i: Ignore the difference in case, so the cases are treated as the same

-n: Output the line number by the way

-v: reverse selection, that is, display the line without the content of the 'search string'

1, grip

Find lines containing strings and print them;

2,grip -i

Ignore differences in case, so case is treated as the same

3,grip -n

By the way, output the line number

You can also combine to ignore case;

4,grip -v

On the contrary, everything that does not contain this string is output;

27,sort

1,sort

Sort according to the ASII value of the first row of letters;

2,sort -r

Reverse output

28,uniq

1,uniq

Uniquely, compress adjacent and identical lines.

 

Adjacent and identical lines are compressed;

2,uniq -u

Keep only unique items

You see, no adjacent items are retained, only the unique item is retained;

3,uniq -d

Print a copy of the item that is not the only one

4. sort & uniq to remove duplicates

5,sort | uc

Count the number of occurrences of each line

6,sort | uniq | wc -l

Count the total number of unique rows;

29,.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.

1,zip

Let’s compress a file first and play around;

At this time, the red font is the decompression package of t1;

We first move the compressed package to code;

At this time, all the contents of the file are also there, which is also very OK;

Now let’s compress the directory and take a look;

First compress the directory to generate files;

After moving to the code directory;

Unzip it and look at the content again, and find that the content is empty;

However, the original directory has content, and the contents are not packed when the directory is packaged and compressed;

2,zip -r

Pack everything in the directory;

Compress first; 

Move to the code directory;

Unpack and print again;

That’s OK;

3,unzip -d

Unzip the file to the specified directory;

Or compress the file first; 

Then directly decompress and move to code and output;

30, takes

tar [-cxtzjvf] files and directories.... Parameters:

-c: Parameter command to create a compressed file (create means);

-x: Unlock the parameter command of a compressed file!

-t: View the files in tarfile!

-z: Does it also have the attributes 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

1,tar - part

Compressed file;

Just decompress it directly;

2,takes -xzf

Unzip the compressed package;

We first move the compressed package to code;

Then unzip;

After decompression, there is no problem with output and printing;

3,tar -xzf -C

Unzip to the specified file, which has the same function as unzip -d, so I won’t go into details;

31. Several important hot keys [Tab], [ctrl]-c, [ctrl]-d

[Tab] button---has the functions of "command completion" and "file completion"

[Ctrl] -c key---stop the current program

[Ctrl]-d key---usually means: "End Of File, EOF or End OfInput"; in addition, it can also be used to replace exit

By adding a character and clicking [tab] twice, you can search for instructions containing characters in the program;

When our program keeps running and cannot be stopped, we can use the [ctrl]c key to forcefully stop the program;

[ctrl]d can force you to exit the current account. Press it one more time to exit xshell directly;

32. Shut down

Syntax: shutdown [options] ** Common options: **

-h: After stopping the system service, shut down immediately.

-r: Restart the system after stopping the service

-tsec: Add seconds after -t, which means "shut down after a few seconds"

shotdown -t : Shut down after a few seconds

This causes the system to shut down after 99 seconds;

shotdown -h : shut down immediately

This is an immediate shutdown;

shotdown -r : Restart immediately

reboot: Restart immediately

Both of these are commands to restart the system;

Our Linux instructions are here first. You can easily get started with Linux by using these instructions at the beginning!

Guess you like

Origin blog.csdn.net/m0_71676870/article/details/133814033