Share attentively and grow together

What’s more important than making a little progress every day

This article has been included on github:github.com/midou-tech/… , welcome to Star and Issues.

The preface

This article mainly explains some common Linux commands, mainly explains the mode is command introduction, command parameter format, command parameter, command common parameter example. Since there are many Linux commands, I have specially selected some commands that are frequently used in daily life to explain them, but it is still unavoidable that the article will be very long, so I suggest that you save them and don’t come back to them when you use them. Of course, the best way to learn Linux commands is to learn how to use the MAN manual of Linux. All Linux command specifications and usage rules are clearly explained in this manual. I also refer to this manual and daily use in writing.

If there are any other commands you would like to add, please leave a comment to me. I will update this article continuously, and it will also serve as a manual for my study and work.

Linux Primary instructions

The ls – the List

Ls is introduced

This was my first command to learn Linux, and I’m sure many people’s first command to learn Linux. Ls full name list.

List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort is specified.

Lists information about files (default: current directory). If -cftuvsux or — Sort is not specified, the Sort is alphabetical.

The official list makes it very clear that the current directory is listed by default, so you can list file information or directory information under other directories or paths.

Eg:

$ls /etc/hosts

/etc/hosts

Copy the code

Ls can also list files in a specified directory.

image-20191221161638964

Ls parameter format

ls [OPTION]... [FILE]...

Ls command parameters

-a Lists all files in the specified directory, including hidden files

-c The time when the file state was last changed for sorting (-t) or long printing (-l)

When using -h with the -L option, use the unit suffixes Byte, Kilobyte, mete, GB, TB, and Petabyte to reduce numbers to 3 or less using base 2 sizes

-l Long format list. (See below). If printed to a terminal, the sum of all file sizes is printed on the first line of the long list

-n displays user and group ids in numeric form, rather than being converted to user or group names in long (-l) output. This option turns on the -l option by default

-o is listed in long format, but omits the group ID

-s Displays the actual number of file system blocks used by each file, in 512 bytes, with some units rounded to the next integer value

-t Sorts operands by their modified time before sorting them in lexicographical order (most recently first)

-u sorts using the time of the last access, not the last modification of the file

Ls Usage examples:

$ ls

test  tmp

$ ls -a

. .bash_history .bash_logout .bash_profile .bashrctest  tmp

# you can see the files hidden in the current directory through ls -a. The files at the beginning are hidden files.

$ ls -l

total 4

-rw-r--r-- 1 test hero    0 Dec 21 19:54 test

drwxr-xr-x 2 test hero 4096 Dec 21 19:54 tmp

$ ls -lh

Total 4.0 K

-rw-r--r-- 1 test hero    0 Dec 21 19:54 test

drwxr-xr-x 2 testHero 4.0K Dec 21 19:54 TMP

$ ls -ll

total 4

-rw-r--r-- 1 test hero    0 Dec 21 19:54 test

drwxr-xr-x 2 test hero 4096 Dec 21 19:54 tmp

$ ls -alh

total 28K

drwx------   3 testHero 4.0K Dec 21 19:54.

Drwxr-xr-x. 19 root root 4.0K Aug 1 10:41..

-rw-------   1 test hero  226 Dec 21 19:54 .bash_history

-rw-r--r--   1 test hero   18 Aug  3  2016 .bash_logout

-rw-r--r--   1 test hero  193 Aug  3  2016 .bash_profile

-rw-r--r--   1 test hero  231 Aug  3  2016 .bashrc

-rw-r--r--   1 test hero    0 Dec 21 19:54 test

drwxr-xr-x   2 testHero 4.0K Dec 21 19:54 TMP

$ ls -o

total 4

-rw-r--r-- 1 test    0 Dec 21 19:54 test

drwxr-xr-x 2 test 4096 Dec 21 19:54 tmp

$ ls -oh

Total 4.0 K

-rw-r--r-- 1 test    0 Dec 21 19:54 test

drwxr-xr-x 2 test4.0K Dec 21 19:54 TMP

Copy the code

PWD — Print Working Directory

The PWD is introduced

Prints the full pathname of the current working directory. (print name of current/working directory)

Parameter format

pwd [OPTION]...

PWD usage demonstration

[test@Mfate171193 /home/test] 20:06

pwd

/home/test

Copy the code

touch (change file timestamps)

Touch is introduced

Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h is supplied.

Update the access and modification time for each file to the current time. The nonexistent FILE argument is created null unless -c or -h is provided.

Touch parameter format

touch [OPTION]... FILE...

Touch command parameters

-A or –time=atime or –time=access or –time=use changes only the access time.

-c or –no-create Creates no document.

-d Uses the specified date and time instead of the current time.

-f This parameter is ignored and only resolves compatibility problems with the BSD touch command.

-m or –time=mtime or –time=modify Only changes the change time.

-r Sets the date and time of the specified document or directory to the same as that of the reference document or directory.

-t Uses the specified date and time instead of the current time.

Usage examples

Create three files

$ touch test1 test2 test3

Do not create a document

$ touch -c test5  

$ ls

test1  test2  test3

Test1; test2; test3

$ touch -t 201911110000 test1

stat test*

Test1 = 201911110000; touch-t = 201911110000; test1 = 201911110000; This parameter is useful because you can change the time of your last visit to a very early time. Can do some fun things, haha.

File: "test1"

  Size: 0             Blocks: 0          IO Block: 4096   regular empty file

Device: fd01h/64769d    Inode: 360736      Links: 1

Access: (0644/-rw-r--r--)  Uid: (14060/   localhost)   Gid: ( 1001/    hero)

Access: 2019-11-11 00:00:00. 000000000 + 0800

The Modify: 2019-11-11 00:00:00. 000000000 + 0800

Change: the 2019-12-21 20:58:11. 290761038 + 0800

 Birth: -

File: 'test2'

  Size: 0             Blocks: 0          IO Block: 4096   regular empty file

Device: fd01h/64769d    Inode: 360738      Links: 1

Access: (0644/-rw-r--r--)  Uid: (14060/   localhost)   Gid: ( 1001/    hero)

Access: the 2019-12-21 20:56:34. 523761038 + 0800

The Modify: the 2019-12-21 20:56:34. 523761038 + 0800

Change: the 2019-12-21 20:56:34. 523761038 + 0800

 Birth: -

File: "test3"

  Size: 0             Blocks: 0          IO Block: 4096   regular empty file

Device: fd01h/64769d    Inode: 360740      Links: 1

Access: (0644/-rw-r--r--)  Uid: (14060/   localhost)   Gid: ( 1001/    hero)

Access: the 2019-12-21 20:56:34. 523761038 + 0800

The Modify: the 2019-12-21 20:56:34. 523761038 + 0800

Change: the 2019-12-21 20:56:34. 523761038 + 0800

 Birth: -

Copy the code

cat&tac (Concatenate FILE(s), or standard input, to standard output.)

The cat is introduced

Concatenate FILE(s), or standard input, to standard output.

Connect FILE or standard input to standard output.

Cat parameter format

cat [OPTION]... [FILE]...

Cat command parameters

-a, –show-all is equivalent to -vet

-b, –number-nonblank Specifies the number of the non-blank output line

-e is the same thing as -ve

-e, –show-ends is displayed at the end of each line

-n, –number Specifies the number of all output lines, starting from 1

-s, –squeeze-blank if there are more than two consecutive blank lines, it is replaced with one blank line

-t is equivalent to vT

-t, –show-tabs displays the TAB character as ^I

-u (ignored)

-v, –show-nonprinting uses ^ and M- references, except for LFD and TAB

Cat common parameter examples

$ cat test  Display file contents

-a, --show-all is equivalent to -vet

-b, --number-nonblank Specifies the number of the non-blank output line

-e is the same thing as -ve



$ cat -n test  Display the contents of the file and display the line number

1-a, --show-all is equivalent to -vet

2 -b, --number-nonblank Specifies the number of the non-blank output line

3 minus e is the same thing as minus vE

Copy the code

In contrast with the cat command, the TAC command cannot contain the line number.

$ tac test

-e is the same thing as -ve

-b, --number-nonblank Specifies the number of the non-blank output line

-a, --show-all is equivalent to -vet

Copy the code

The mkdir — Make Directory

The mkdir introduction

Create the DIRECTORY(ies), if they do not already exist.

If the directory does not exist, it is created.

Mkdir parameter format

mkdir [OPTION]... DIRECTORY...

Mkdir command parameter

-m, –mode= mode, set permission < mode > (like chmod), not RWXRWXRWX minus umask

-p, –parents can be a path name. If some directories in a path do not exist, the system automatically creates the directories that do not exist. That is, multiple directories can be created at a time.

-v, –verbose Displays information each time a new directory is created

–help displays this help information and exits

–version Displays the version information and exits

Mkdir Example of common parameters

Create directory file test

$ mkdir test

# serial create

$ mkdir -p test1/tmp

$ ls

test  test1

Create a directory with the top permission

# TMP directory has executable permissions, Linux file permissions will be covered in more detail in a later article, keep an eye on me

$ mkdir -pm 777 test2/tmp

$ ls -lh

total 12K

Drwxr-xr-x 2 Localhost Hero 4.0k Dec 21 21:39test

Drwxr-xr-x 3 Localhost Hero 4.0K Dec 21 21:40 test1

Drwxr-xr-x 3 Localhost Hero 4.0K Dec 21 21:40 test2

$ ls

test  test1  test2

The #-v argument determines whether the file already exists. If not, the file will be created and the following information will be displayed

$ mkdir -v test

Mkdir: cannot create directory 'test': the File exists



$ mkdir -v test7

The mkdir: created directory "test7"

Copy the code

CD – Change Directory

The CD is introduced

Switch the current directory to the specified directory

Common Parameter Examples

Print the current directory to standard output

pwd

/Users/localhost

Switch to directory /

$cd /

Copy the code

CD command has no parameter is to switch the directory to the specified path, relatively simple, but the use of high ratings.

Rm&rmdir – Remove the Directory

Rm is introduced

The rm utility attempts to remove the non-directory type files specified on the command line. If the permissions of the file do not permit writing, and the standard input device is a terminal, the user is prompted (on the standard error output) for confirmation.

The rm utility attempts to delete a non-directory type file specified on the command line. If the file’s permissions do not allow writing, and the standard input device is a terminal, the user is prompted (on standard error output) for confirmation.

The rm command or need to be aware of when using, he deleted restore more troublesome, some systems will bring – I parameters, type the command after another confirmation steps, some of them are directly deleted, is really deleted from the memory wipe out the (in fact, the underlying is to let the file pointer does not point to the memory block of the file, there are, in principle, the content of the memory However, recovery can be complicated, requiring the entire memory block to be scanned to retrieve the contents. Don’t delete important code you’ve written, HH.

Rm Parameter Format

rm [-dfiPRrvW] file ...

Rm Command Parameters

-f, –force Ignores non-existent files and never displays a prompt.

-i, –interactive Deletes the interface interactively

-r, -r, — instructing RM to recursively delete all directories and subdirectories listed in the argument.

-d, –dir Deletes an empty directory

Rm Common parameter example

Create three files

$ touch tmp.cc tmp.java tmp.py tmp.go

Create a directory file

$ mkdir -p linux/test

# check whether the file is created successfully

$ ls

linux    tmp.cc   tmp.go   tmp.java tmp.py

# Delete file and prompt

$ rm -i tmp.cc

remove tmp.cc? y

# force delete

$ rm  -f tmp.go

# delete directory

$ rm -f linux  Failed to delete a directory

rm: linux: is a directory

Delete all files in the directory

$ rm -rf linux  Delete directory successfully.

$ ls

tmp.java tmp.py  

Copy the code

Rmdir ==rm -d Deletes an empty directory

The mv — a Move

The mv is introduced

In its first form, the mv utility renames the file named by the source operand to the destination path named by the target operand. This form is assumed when the last operand does not name an already existing directory.

In its second form, mv moves each file named by a source operand to a destination file in the existing directory named by the directory operand. The destination path for each operand is the pathname produced by the concatenation of the last operand, a slash, and the final pathname component of the named file.

To summarize, move a directory or file to a top directory and rename it.

Mv parameter format

mv [-f | -i | -n] [-v] source target mv [-f | -i | -n] [-v] source ... directory

Mv Command parameters

-b: Back up files before overwriting them.

-f: force Indicates the force. If the target file already exists, the system overwrites the file directly.

-i: If the destination file already exists, the system asks whether to overwrite it

-n: Do not overwrite existing files. (The -n option will override any previous -f or -i options.)

-u: Update the source file if the source file already exists.

Mv Examples of common parameters

## Change the file name

$ touch tmp.cc



$ ls

tmp.cc



$ mv tmp.cc tmp.java



$ ls

tmp.java

Move files or directories

pwd

/Users/localhost/test

Move the file and rename it

$ mv /Users/localhost/logs/tmp.txt ./tmp.log 



$ ls /Users/localhost/logs/

discover-client metabase        tesla



$ ls ./

tmp.java tmp.log

Move the directory and rename it

$ mv /Users/localhost/logs/tesla  ./tesla.ba 



$ ls

tesla.ba tmp.java tmp.log

Copy the code

This command is handy when writing makefiles to move the compiled results to a specified directory and rename them.

Cp – Copy

Cp is introduced

In the first synopsis form, the cp utility copies the contents of the source_file to the target_file. In the second synopsis form, the contents of each named source_file is copied to the destination target_directory. The names of the files themselves are not changed. If cp detects an attempt to copy a file to itself, the copy will fail.

The cp utility copies the source_file contents to target_file. In the second outline format, the contents of each named source_FILE are copied to the target target_directory. The name of the file itself does not change. If CP detects an attempt to copy the file to itself, the replication will fail.

Cp parameter format

cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file . target_directory

The command parameter

-a, –archive 等于-dR –preserve=all

–backup[=CONTROL Creates a backup for each existing target file

-b Is similar to –backup but does not accept arguments

–copy-contents is used to copy special file contents in recursive processing

-d 等于–no-dereference –preserve=links

-f, –force If the target file cannot be opened, remove it and retry (when the -n option is selected)

Do not select this option if it exists.)

-i, –interactive ask before overwriting (invalidate previous -n option)

-h Follows the command line symbolic link in the source file

-l, –link Links files without copying them

-l, –dereference always follows symbolic links

-n, –no-clobber do not overwrite existing files (invalidate previous -i option)

-p, –no-dereference does not follow symbolic links in the source file

-p = –preserve= mode, ownership, timestamp

— Preserve [= Attribute list preserves the specified attribute (default: mode, ownership, timestamp), if

Additional attributes may be maintained: environment, links, Xattr, and so on

-r, -r, –recursive copies the directory and all items within it

Common Parameter Examples

$ cat tmp.cc

change world



# Copy the contents of the file

$ cp tmp.cc tmp.java



$ cat tmp.java

change world

Copy the code

echo

The echo is introduced

The echo utility writes any specified operands, separated by single blank (') characters and followed by a newline (\n’) character, to the standard output.

The echo utility writes any specified operands to standard output, separated by a single space () character followed by a newline (\ n’) character.

This command is usually used to print variables, text content, etc.

echo "change world"

change world



#s Prints the value of the PWD environment variable

echo $PWD

/Users/localhost/test

Copy the code

$PWD takes the current path and echo it to standard output. Normally echo \$name is used to view the value of an environment variable

head&tail

The head is introduced

This filter displays the first count lines or bytes of each of the specified files, or of the standard input if no files are specified. If count is omitted it defaults to 10.

This filter displays the first few lines or bytes of each specified file or standard input (if no file is specified).

If more than a single file is specified, each file is preceded by a header consisting of the string ==> XXX <=='' whereXXX” is the name of the file.

If count is omitted, the default is 10. If multiple files are specified, the header for each file consists of the string ==> XXX <== “, where XXX “is the filename file.

Head parameter format

head [-n count | -c bytes] [file ...]

Head Example of common parameters

-n Displays the first N lines

-c Displays the first N characters

Head Example of common parameters

$ cat -n test.txt # use the -n parameter of the cat command.

1 with

2 the heart

Three points

4,

5,

6 with

7 a

8 long.

     9

10 don't

There are 11

12 what

13?

14 than

15 you

16 per

17 days

18 into

Step 19

20 a

21 points

22 more

23 real

24 in

25 the

26.



$ head test.txt  Display 10 lines by default

with

heart

points

Enjoy,

A total of

with

into

Long.



no



$ head -n15 test.txt Show 15 lines

with

heart

points

Enjoy,

A total of

with

into

Long.



no

There are

what

?

than

you



$ head -c23 test.txt # display the first 23 characters, a Chinese character is not a character (UTF-8 encoding Chinese character length is variable)

with

heart

points

Enjoy,

A total of

Copy the code

The tail command is the complete opposite, displaying text from the tail, but it uses more arguments.

-f Indicates the reading cycle

-q Indicates that processing information is not displayed

-v Displays detailed processing information

-c< Number > Number of bytes to display

-n< number of rows > Number of rows to be displayed

–pid= Pid is used with -f to terminate the process after the process ID,PID, dies.

-q, –quiet, –silent never prints the header of the given filename

-s, –sleep-interval= s This parameter is used with -f to sleep for seconds at each repeated interval

The tail and head commands are often used to view logs, as I use them almost every day. My log files cannot be viewed using vim or cat (because I am responsible for tens of gigabytes of business logs every day), either by tail or more&less(as described below).

more&less

More introduction

Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.)

More time open the file but not all the file into memory read flow, not because the vi | vim oom caused a large file system.

One of the most important features of More&less is streaming reading, which supports page-turning. For example, the cat command reads all the output to standard output. If the file is too large, it will fill up the screen and become impossible to read.

More Parameter format

more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ]

More command parameters

+n displays from row n

-n Sets the screen size to N lines

+/ PATTERN searches for the pattern before each file display, and then displays the pattern starting after the first two lines of the string

-c Clear the screen from the top and display it

-d Press space to continue, ‘q’ to quit (Press the space key to continue, and Press the Q key to exit) is displayed to disable the ring tone function

-l Ignores the Ctrl+ L (page feed) character

-p repages a file by clearing the window rather than scrolling, similar to the -c option

-s Displays consecutive blank lines as one line

-u Deletes the underlined line in the file

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

wc

Wc is introduced

The wc utility displays the number of lines, words, and bytes contained in each input file, or standard input (if no file is specified) to the standard output. A line is defined as a string of characters delimited by a charac-ter. Characters beyond the final character will not be included in the line count.

The WC utility displays the number of lines, words, and bytes contained in each input file or standard input (if no file is specified). A line defined as a character delimited string. Characters after the last character are not included in the number of lines.

This command is profound for me, when I was just learning to program soon, I feel the code I wrote a lot of, at that time I very want to know how many lines of code I wrote, on a whim, to start, directly to write a program to statistics, after you’ve written also feel pretty bad, who knows after learning to the wc, Then I feel that I am still a little tender and still need to learn more.

Wc parameter format

wc [-clmw] [file ...]

Wc command parameters

-c Indicates the number of bytes.

-l Indicates the number of rows.

-m Indicates the number of characters. This flag cannot be used with the -c flag.

-w Indicates the number of words counted. A word is defined as a string separated by whitespace, tabs, or newline characters.

-l Prints the length of the longest line.

Common Parameter Examples

$ ls

test.txt



$ wc test.txt

      26      26     103 test.txt



$ wc -l test.txt  # count rows directly

      26 test.txt



$ wc -c test.txt

     103 test.txt

Copy the code

date & cal

The date is introduced

When invoked without arguments, the date utility displays the current date and time. Otherwise, depending on the options specified, date will set the date and time or print it in a user-defined way.

The date utility displays the date and time read from the kernel clock. When used to set the date and time, both the kernel clock and the hardware clock are updated.

Only the superuser may set the date, and if the system securelevel (see securelevel(7)) is greater than 1, the time may not be changed by more than 1 second.

When called without arguments, the date utility displays the current date and time. Otherwise, the date sets the date and time or prints the date and time in a user-defined manner, depending on the options specified.

The date utility displays the date and time read from the kernel clock. Both the kernel clock and the hardware clock are updated when used to set the date and time.

Only the superuser can set the date, and if the system security level (see SecureLevel (7)) is greater than 1, the time change must not exceed 1 second.

Date parameter format

date [-jRu] [-r seconds | filename] [-v [+|-]val[ymwdHMS]] ... [+output_fmt] date [-jnu] [[[mm]dd]HH]MM[[cc]yy][.ss] date [-jnRu] -f input_fmt new_date [+output_fmt] date [-d dst] [-t minutes_west]

Date Command parameters

%H Hours (expressed in 00-23).

%I hours (expressed in 01-12).

%K hours (expressed as 0-23).

% L hours (expressed as 0-12).

%M minutes (00-59).

%P AM or PM.

%r time (including hours, minutes and seconds, hours are expressed as 12 hours AM/PM).

%s Total number of seconds. The starting time is 1970-01-01 00:00:00 UTC.

%S seconds (in the local idiom).

%T time (including hours, minutes and seconds, and hours are expressed in the 24-hour system).

%X time (expressed in local idiom).

% Z city.

%a week.

%A Full name of the week.

%b Abbreviation of the month name.

%B Full English name of month.

%c Date and time. Typing the date directive alone will display the same result.

%d Date (01-31).

%D Date (including year, month and day).

%j The day of the year.

%m months (expressed as 01-12).

%U Number of weeks in the year.

%w Number of days in a week. 0 indicates Sunday, 1 indicates Monday, and so on.

%x date (expressed in local idiom).

%y The year (00-99).

%Y Year (represented by four digits).

%n Inserts a new line when displayed.

%t inserts TAB when displayed.

MM month (necessary)

DD date (required)

Hh hours (necessary)

Mm min (necessary)

Ss seconds (optional)

-d< string > Displays the date and time indicated in the string. The string must be surrounded by double quotation marks.

-s< string > Sets the date and time according to the string. The string must be surrounded by double quotation marks.

-u Displays GMT.

Common Parameter Examples

$ date

Sunday, 22 December 2019 21:28:29 CST



$ date '+%c'

12/22 21:28:33 2019



$  date '+%D'

12/22/19



$  date '+%T'

21:28:50



$ date '+%X'

21:29 minutes, 00 seconds

Copy the code

CAL is introduced

The CAL command can be used to display a Gregorian (solar) calendar.

CAL parameter format

cal [-3hjy] [-A number] [-B number] [[month] year] cal [-3hj] [-A number] [-B number] -m month [year] ncal [-3hjJpwy] [-A number] [-B number] [-s country_code] [[month] year] ncal [-3hJeo] [-A number] [-B number] [year] ncal [-CN] [-H yyyy-mm-dd] [-d yyyy-mm]

CAL Command parameters

-1 Displays the monthly calendar of a month

-3 Displays the calendar of the previous month, current month, and next month

-s Displays Sunday as the first day of a week. The default format is Sunday

-m Displays Monday as the first day of a week. -j Displays the number of days in a year (the date of a year is calculated by day. The default number of days in the current month is displayed after January 1.) -y Displays the calendar of the current year

CAL Example of common parameters

$ cal

In December 2019

Day one two three four five six

One, two, three, four, five, six, seven

8, 9, 10, 11, 12, 13, 14

15, 16, 17, 18, 19, 20, 21

22, 23, 24, 25, 26, 27, 28

29, 30, 31





$ ncal

In December 2019

One, 2, 9, 16, 23, 30

Two, three, ten, seventeen, twenty-four, thirty-one

Three, four, eleven, eighteen, twenty-five

Four, five, twelve, nineteen, twenty-six

Five, six, 13, 20, 27

Six seven, fourteen, twenty-one, twenty-eight

Day 1 8 15 22 29

Copy the code

which

Which introduce

The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.

The which command searches for the location of a system command in the PATH specified by the PATH variable and returns the first search result. That is, using the which command, you can see whether a system command exists and which location of the command was executed.

Format of which parameter

-n Specifies the length of the file name. The specified length must be longer than or equal to the longest file name in all files.

The -p parameter is the same as the -n parameter, but contains the file path.

-w Specifies the width of the output field.

Which is a common parameter example

which ls

alias ls='ls --color=auto'

    /bin/ls



which which

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

    /bin/alias

    /usr/bin/which

Copy the code

whereis

Whereis introduction

The whereis command can only be used to search for program names, and only binary files (parameter -b), man description files (parameter -m), and source code files (parameter -s) are searched. If the argument is omitted, all information is returned.

Whereis parameter format

whereis [program ...]

Whereis command parameter

-b Locates the executable file.

-m Locate help files.

-s Locates the source code file.

-u Searches for all files except executable files, source files, and help files in the default path.

-b Specifies the path to search for executable files.

-m Specifies the path to search for help files.

-s Specifies the path to search for source code files.

Examples of common parameters whereis

$ whereis ls

/bin/ls



$ whereis whereis

/usr/bin/whereis

Copy the code

nl

Nl is introduced

The nl command is used on Linux to calculate the line number in a file. Nl can automatically add line numbers to output file contents! The default result is a little different from cat-n. Nl can do a lot more with line numbers, including the number of digits and whether to auto-complete zeros and so on.

Nl parameter format

nl [-p] [-b type] [-d delim] [-f type] [-h type] [-i incr] [-l num] [-n format] [-s sep] [-v startnum] [-w width] [file]

Nl Command Parameters

-b: Specifies the line number in two ways:

-b a: lists the line numbers regardless of whether the line is empty (similar to cat-n).

-b t: If there are empty lines, do not list the line number of the empty line (default value).

-n: Lists the line numbers in the following three ways:

-n ln: The line number is displayed on the left of the screen.

-n rn: The row number is displayed to the right of its column without adding 0.

-n rz: The line number is displayed on the right of the column and 0 is added.

-w: indicates the number of digits occupied by the row number column.

-p does not restart the evaluation at the logical delimiter.

Nl Common parameter examples

$ nl test.txt

1 with

2 the heart

Three points

4,

5,

6 with

7 a

8 long.



9 no

There are 10

11 what

12?

13 than

14 you

15 per

16 days

17 into

18 step

19 a

20 points

21 more

22 real

23 in

24 the

25.

Copy the code

ps

Ps is introduced

The ps utility displays a header line, followed by lines containing information about all of your processes that have controlling terminals.

The PS utility displays a header line, followed by a line that contains information about all processes that have a control terminal.

Ps Parameter Format

ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]] [-g grp[,grp...]] [-u uid[,uid...]] [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]] ps [-L]

Ps Command Parameters

A Displays all processes

-a Displays all programs on the same terminal

-a Displays all processes

C Displays the process name

-n Indicates reverse selection

– e is equal to the “-a”

E Displays environment variables

F Displays relationships between programs

-h Displays the tree structure

R Displays the process of the current terminal

T Displays all programs on the current terminal

U Specifies all processes of the user

-au Displays detailed information

-aux displays all trips that include other users

-c < command > Lists the status of the specified command

–lines< lines > The number of lines displayed per page

–width< number of characters > Number of characters to display per page

Ps Common parameter examples

# View all processes

$ps -a

Check the relationship between process environment variables and programs

$ps -ef

Copy the code

kill&killall

Introduce the kill

The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.

The kill command sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal kills processes that do not capture it. For other procedures, you may need to use the KILL (9) signal because it cannot be caught.

Kill parameter format

kill [-s signal|-p] [-q sigval] [-a] [-] pid.

kill -l [signal]

Copy the code

Kill command parameters

-l signal, if no signal number parameter is added, the “-l” parameter will list all signal names

-a When processing the current process, the mapping between the command name and the process ID is not limited

-p Indicates that the kill command prints only the process ids of related processes but does not send any signal

-s Indicates sending signals

-u Specifies the user

Kill Example of common parameters

# Check the current system signal

kill -l

 1) SIGHUP     2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP

 6) SIGABRT     7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1

11) SIGSEGV    12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM

16) SIGSTKFLT    17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP

21) SIGTTIN    22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ

26) SIGVTALRM    27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR

31) SIGSYS    34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3

38) SIGRTMIN+4    39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8

43) SIGRTMIN+9    44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13

48) SIGRTMIN+14    49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12

53) SIGRTMAX-11    54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7

58) SIGRTMAX-6    59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2

63) SIGRTMAX-1    64) SIGRTMAX

Copy the code
explain

HUP 1 Terminating INT 2 Terminating (same as Ctrl + C) QUIT 3 terminating (same as Ctrl + \) TERM 15 Terminating KILL 9 forcibly terminating CONT 18 Continuing (opposite to STOP, Fg /bg command) STOP 19 Pause (same as Ctrl + Z)

Kill -9 is the most common signal we use, but it’s not elegant at all. Instead, use kill -15. Most programs will release their resources and then stop after receiving SIGTERM. However, it is possible for a program to receive the signal and do something else (if the program is waiting for the IO, it may not respond immediately and wait until the IO completes), that is, SIGTERM will most likely be blocked.

At this point, the basic Linux instructions are nearly enough to run on your server. But just for a quick look, see the advanced section for more instructions.


Due to the length requirement of digging gold, detailed explanation of advanced part of the article will be posted on wechat public account

To subscribe, search for DC952721 on wechat or scan the QR code.

qrcode_for_gh_c0c6a2272e93_258