Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux directory, view and compress commands (cat, more, etc.)

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is worth mentioning today is:

(1) Tree directory structure

(2) View the use of commands

(3) Compression and archiving commands

I. Digital directory structure

1. Root directory

The location starting point of all partitions, directories, files, etc.

In the entire tree directory structure, use a separate one

two。 Common subdirectory

/ root / bin / boot / dev / etc

/ home / var / usr / sbin

3. The functions of each subdirectory:

/ root: the host directory of the system administrator root

/ home: the host directory of an ordinary user

/ boot: system kernel, boot file

/ dev: device files (CD-ROM, disk)

/ etc: configuration file, where / passwd is the account information

/ bin: commands that all users can execute

/ sbin: administrative commands that the administrator can execute

/ usr: application

/ var: variable length files (log files, etc.)

/ proc: hardware information (memory, CPU)

/ tmp: temporary directory

/ opt: empty file

Lib, lib64: function libraries

Second, view commands

Cat command

Purpose: display the contents of the file

Format: Cat [option] file name.

Example:

Disadvantages: only display the last paragraph of the document, there is no page turning function, the previous content no matter how wonderful it can not be viewed. Don't panic, we have other check orders. Let's explore the next one.

More View Command

Purpose: full-screen paged display of the contents of the file

 more [options] file name.

Interactive operation method:

 Enter: scroll down line by line

 space: flip down one screen

 B: scroll up (back)

 Q: quit

Disadvantages: easy to automatically pop up to the last page, unable to view the contents of the last page. I can't look up. It seems that the more command cannot view all the text content, so is there really no way to view the final content? No, the editor reveals in advance that the next view command is more powerful.

Less command

1. Purpose: same as more command, but with more extended functions

 Less [options] file name.

two。 Interactive operation method

 Page Up: turn the page up

 Page Down: turn the page down

 press the "/" key to find the content: "n" next content, "N" last content

Other functions are basically similar to the more command

With the help of this command, we finally see all the contents of the text, which can be described as twists and turns.

Head command

Purpose: view part of the beginning of the file (default is 10 lines)

Tail command

Purpose: view a small portion of the end of the file (10 lines by default)

Tail-n file name. Or tail-f file name.

Wc command

Purpose: information such as the number of words in the statistics file (Word Count)

Wc [options]... Target file.

Common command options

-l: count rows

-w: count the number of words

-c: count bytes

-l: count rows (line)

-w: count words (word)

-c: count bytes (char)

Extension: enter only wc and only count the number of lines, words and bytes by default.

Grep command

Purpose: find and display the line containing the specified string in the file

Format: grep [options]... Find condition object file

 1. Common command options

I: ignore case when looking up

-V: reverses the lookup and outputs lines that do not match the lookup criteria

two。 Find condition settin

The string to be found is enclosed in double quotation marks

(1). ^. Denote with. The beginning

(2). ". $" is expressed as. End

 (3). "^ $" represents a blank line

Forward lookup (# is a comment, only for description, not function

):

Features: easy to find the same form of data

Reverse the lookup, output the lines that do not match the lookup criteria and import them into the 111text under the home directory:

Tip:

1. ">" redirect: copy all the output data to another file

two。 When you encounter content in the text you want to paste, the content overwrites the source content in the text.

3. You can capture the information displayed at the end of the screen and import it into a file to generate.

, will there be any surprises when we do a text test with the appending symbol "> >"?

summary: append the symbol "> >" to keep the content in the original text unchanged, and the pasted content will be added later.

thinks about what interesting things happen when you import the contents of a file into your own text.

 concluded that the operation failed because they shared a process and could not all be imported and exported from the same file.

Finally, add a knowledge point: the pipeline symbol "|", what can it do? Let's focus our eyes on below.

It turns out that its function is to execute the command before "|", and then send the result to the pipeline "|" and then use it to execute the command (like factory assembly line processing, step by step). This combination of commands is greatly convenient for us to further find the data we want, friends should keep in mind!

III. Compression and archiving commands

1.gzip command, bzip2 command

Purpose: make compressed files and unzip compressed files

gzip [- 9] filename...

bzip2 [- 9] filename...

gzip-d... compressed file in gz format

bzip2-d... compressed file in bz2 format

two。 Common command options and their functions

- 9: compress files

- d: extract files

Gzip compression and decompression:

Bzip2 compression and decompression:

It can be seen that when gzip and bzip2 compress and decompress the files, the source files will disappear. The source file will not disappear after unzipping the file in the windows system, so is there any way to make the source file the same as in the windows system, that is, it will not disappear? Let's take a look at the next tar command.

Tar command

Purpose: making and releasing archival documents

Tar [options]... Archive file name source file or directory

Or

Tar [options]... Archive file name [- C target directory]

1. Common command options:

-c,-x,-v,-f,-p,-t,-C,-z,-j

two。 Individual command option functions:

- c: create a compressed package

- x: decompression

- v: display details

- f: execute

- p: keep the original permissions

- t: view the contents of the package

- C: decompress the target path

- z:gzip format

- j:bzip2 format

Gzip compressed file:

Use the tar czvf 1111.txt.tar.gz command to compress the 1.txt and a.txt files, and the source files will not disappear.

Gzip decompresses the file:

If you unzip it to another directory, add "- C"; if there is no "- C", you will extract it to the current directory.

Bzip2 compresses and decompresses files:

It can be seen that the tar command is used to compress the file, and the source file always exists. The use of this command is very practical.

highlights today:

1. Remember the role of Linux common subdirectories

2. Proficient in and able to make rational use of various viewing commands

3. Proficient in the use of compression and decompression commands.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report