[Linux] Common Commands (3)

1.head instruction

Head and tail are as easy to understand as their names, it is 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 supposed 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 the corresponding file.

Options:

  • -f loop read
  • -n<number of lines> Display the number of lines

Note: The tail command is used in the same way

Question: How to read a section of content in the middle of a file?

Assuming there are 10,000 lines in the test.txt file, how do we read lines 200 to 210?
Solution: First use the head command to read the first 210 lines in the test.txt file and store them in the temporary file tmp.txt, and then print out the last 10 lines of the tmp.txt file.

head -210 test.txt > tmp.txt 
tail -10 tmp.txt

> ( output redirection ) redirects the content output that should be output to the screen to the tmp.txt file.

It is relatively simple to use the command line pipeline . The pipeline is represented by "|" in the instruction. The left side of the pipeline receives the generated data, and the right side reads the data.

head -210 test.txt | tail -10

2.date display

date Specify the format to display the time: date +%Y:%m:%d
date Usage: date [OPTION]... [+FORMAT]

 1. In terms of display, the user 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 as follows:

        1.) %H : hours (00..23)
        2.) %M : minutes (00..59)
        3.) %S : seconds (00..61)
        4.) %X : equivalent to %H: %M:%S
        5.) %d : day (01..31)
        6.) %m : month (01..12)
        7.) %Y : full year (0000..9999)
        8.) %F : equivalent to %Y-%m-%d

2. In terms of setting time:

  1.) date -s //Set the current time, only root privileges can set it, others can only be viewed.
  2.) date -s 20080523 //Set to 20080523, which will set the specific time to empty 00:00:00
  3.) date -s 01:01:01 //Set the specific time, and will not change the date
  4 .) date -s "01:01:01 2008-05-23″ // this sets the full time
  5.) date -s "01:01:01 20080523" // this sets the full time
  6.) date - s "2008-05-23 01:01:01" //This can set the full time
  7.) date -s "20080523 01:01:01" //This can set the full 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 from January 1, 1970 (UTC/ The number of seconds elapsed since midnight GMT), ignoring leap seconds.


3. cal instruction

The cal command can be used to display the Gregorian (Gregorian) calendar. The Gregorian calendar is the current international calendar, also known as the Gregorian calendar, commonly known as the solar calendar. "Gregorian calendar", also known as "solar calendar", is based on the fact that the earth revolves around the sun for one year, which is commonly used by Western countries, so it is also known as "Western calendar".

Command format: cal [parameter][month][year]
Function: used to view time information such as the calendar, if there is only one parameter, it means the year (1-9999), if there are two parameters, it means the month and year

Common options:

  1. )-3 Display the calendar of the previous month, the current month and the next month of the system
  2. )-j displays the number of days in the current year (the date of the year is counted in days, starting from January 1, the default displays the number of days in the year in the current month)
  3. )-y displays the calendar for the current year


3. find command: (important)

  1. The find command in Linux searches for files in the directory structure and executes the specified operation.
  2. The find command under Linux provides quite a few search conditions and is very powerful. Since find is powerful, it has many options, most of which are worth taking the time to explore.
  3. Even if the system contains a Network File System (NFS), the find command is also valid on that file system, as long as you have the appropriate permissions.
  4. When running a very resource-intensive find command, many people tend to execute it in the background, because traversing a large filesystem can take a long time (here, a filesystem with more than 30G bytes).

Syntax: find pathname -options
Function: used to find files in the file tree, and make corresponding processing (possibly access disk)
Common options:

        -name Find files by file name.


4. which command

Each instruction in Linux is actually an executable program written in a computer language. These programs are stored in files. We can view the path of the program file of a certain instruction through the which instruction.

Syntax:  which command
function:  used to find the path of the program file of a command.

 

 When we execute an instruction, we actually call its executable program, so we can also call the instruction through the path of its program file.


5.alias instruction

Syntax:  alias Alias='original name'
Function:  Can be used to alias the instruction.

E.g: 


6. grep command

grep (global search regular expression(RE) and print out the line, comprehensively search for regular expressions and print out the line) is a powerful text search tool that uses regular expressions to search text and print out the matching lines come out.

The Unix grep family includes grep, egrep, and fgrep. The egrep and fgrep commands differ only slightly from grep. egrep is an extension of grep that supports more re metacharacters, fgrep is fixed grep or fast grep, they treat all letters as words, that is, the metacharacters in regular expressions represent their own literal meanings , no longer special. linux uses the GNU version of grep. It is more powerful and can use the functions of egrep and fgrep through the -G, -E, -F command line options.

Syntax: grep [options] Search string files.
Function: Search for strings in a file and print out the lines found.

Common options:

  1. -i : ignore the difference in case, so the case is treated as the same
  2. -n : output line number by the way
  3. -v : reverse selection, i.e. show the line without the 'search string' content

7 .zip/unzip directives

Syntax: zip compressed file .zip directory or file
function: compress a directory or file into zip format

 Common options:

        -r Recursive processing, processing all files and subdirectories in the specified directory together

The unzip command is used to unzip files.

Syntax:  unzip compressed file.zip option Directory
function:  extract the compressed file to the specified directory.

 

 Note:  If the -d option and the target directory are not used when decompressing the file, it will be decompressed to the current directory by default.


 8.tar command (important)

The tar command can also be used to package compressed and decompressed files, and can also perform operations such as directly viewing the contents without unzipping the compressed package, and only packaging without compression.

Syntax:  tar option Compressed file …
Function:  Pack/unpack, without unpacking, check the contents directly.

Common options:
1) -c parameter command to create a compressed file (create meaning).
2) -x Unpack the parameter command of a compressed file.
3) -t View the files in the tarfile.
4) Does -z have the gzip attribute at the same time? i.e. does it need to be compressed with gzip?
5) Does -j also have the bzip2 attribute? i.e. does it need to be compressed with bzip2?
6) -v Display files during compression (commonly used).
7) -f uses the file name, please note that the file name should be added immediately after f, and no parameters should be added.
8) -C Extract to the specified directory.
 

example:

 Do not unzip the compressed package, directly view the contents inside:


9.file instruction

Syntax:  file File
function:  View more attribute information of the file.

 


10. bc command

Calculator under Linux.


 11. uname command

Syntax: uname [options]
Function: uname is used to obtain information about the computer and operating system.
Supplementary note: uname can display basic information such as the version of the operating system used by the linux host, the name of the hardware, etc.

 

Common options:

        -a or –all output all information in detail, followed by kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name

 


12. Several important hotkeys [Tab], [ctrl]-c, [ctrl]-d

[Tab] key---with the functions of "command completion" and "file completion"
[Ctrl]-c key---make the current program "stop"
[Ctrl]-d key---usually means : "Keyboard input end (End Of File, EOF or End OfInput)"; in addition, it can also be used to replace exit


The following command as an extension:

◆ Installation and login commands: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last;
◆ File processing commands: file, mkdir, grep, dd, find, mv, ls, diff, cat, ln ;
◆ System management related commands: df, top, free, quota, at, lp, adduser, groupadd, kill, crontab;
◆ Network operation commands: ifconfig, ip, ping, netstat, telnet, ftp, route, rlogin, rcp, finger, mail, nslookup;
◆ System security related commands: passwd, su, umask, chgrp, chmod, chown, chattr, sudo ps, who;
◆ Other commands: tar, unzip, gunzip, unarj, mtools, man, unendcode, uudecode .

Guess you like

Origin blog.csdn.net/m0_51866180/article/details/123060412