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

Example Analysis of Linux Directory and File Operation

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you the Linux directory and file operation example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

I. Linux directory structure

Tree directory structure

Root directory: all partitions, directories, files, etc., have the same starting point-the root directory. Throughout the tree directory structure, a separate "/" is used to represent the root directory.

Common subdirectory

Here's a brief introduction to the common subdirectories and their functions:

/ boot: system kernel, boot file

/ root: the host directory of the system administrator root

/ home: the host directory of an ordinary user

/ dev: device file

/ etc: configuration file

/ bin: all user executable commands

/ sbin: administrative commands that can be executed by the administrator

/ usr: application

/ var: log files, etc.

Expand!

/ proc: hardware information

/ tmp: temporary directory (no more after restart)

Lib and Lib64: function Library

/ Media: multimedia

2. View the contents of the file-- cat command cat command

The cat command is originally used to connect the contents of multiple files, but it is more often used to view the contents of files in practice. The basic usage format of the cat command is as follows:

Cat [option] file name. Note: when using this command, you only need to take the file path you want to view as a parameter.

The disadvantage of the cat command is that it is impossible to drag and view the content with the mouse in the character interface, and only the content at the end is displayed.

View the contents of the file in pages-more and less commands

Purpose: full-screen paged display of file contents

The basic format for using the more command is as follows: more [options] file name.

When you use the more command to view more than one screen of file content, it will be split up and the percentage of the current content in the entire file will be displayed in the lower left corner.

Turn the page up and press the b key

The disadvantage of the more command: automatically exits the more command less command when browsing to the end

The basic format for using the less command is as follows: less [options] file name.

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

View the beginning or end of the content-- head, tail commands

Head command

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

The format of the head command: head-n file name.

Tail command

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

Format of tail command: tail-n file name or: tail-f file name

Statistics and retrieval of file contents-- wc command wc command

The wc command is used to count the number of lines, words and bytes contained in the file content. Using the file name as a parameter, you can count multiple files at the same time.

Command format: wc [options] target file

Common command options

Retrieve and filter file contents-- grep command grep command

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

Command format: grep [options] to find conditional object files

Common command options

3. Backup and restore documents using compression and decompression tools-- gzip and gunzip commands

-9: create

-d: decompress

Disadvantages: compression will compress the source file directly into a zip package and do not retain the source file

Attachment: when making compressed files, use the "- 9" option to increase the compression ratio, and it will take more time when the single file is larger. Use the archiving and release tool-- tar command tar command

Purpose: making and releasing archival documents

Command format: tar [options]... Archive file name source file or directory

Or tar [options]... Archive file name [- C target directory]

Common command options

No-C just unzipped to the current directory

-c: create a compressed package

-x: decompression

-v: display details

-f: execute

-p: retain the original permissions

-t: view the contents of the package

-C: decompress the target path

-z:gzip format

-j:bzip2 format

Working mode of the VI editor text editing VI command

Three working modes of VI Editing

Expand!

A: insert content after the cursor

I: insert content before the cursor

O: the next line of the cursor position

O: the previous line of the cursor position

M: jump to the middle line of the screen

Basic operation of command mode

PS: found here that dd is actually cut! Shift+R replaces corresponding characters

This chapter summarizes:

Use the cat,more,less,head,tail command to view files

Use the wc,grep command to count and retrieve the contents of the file

Use the gzip,bzip2 command to make and release compressed files, use the tar command to make or release archive files, and use the "- z"- j" option to automatically invoke the compression tool.

Vi,vim is a full-screen file editor, including command mode, input mode and last-line mode.

The above is all the contents of the article "sample Analysis of Linux Directory and File Operation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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