Linux Archive and Directory Management

1. Directory and file management

For directories, there are many instructions that can perform directory operations. First of all, you must know that there are some special commands:

. represents the current directory

.. represents the previous directory

- represents the previous working directory

~ represents the home directory where the current user identity is located

~account represents the home directory of the user account

a. cd (change directory)

b. pwd (display the directory)

c. mkdir (create a new directory)

    mkdir [-mp] directory name

    Options and parameters:

    -m: config file permissions

    -p: help you to directly build the required directory (including the upper directory) recursively

    Such as: mkdir -m 711 test2

d.rmdir (remove empty directories)

   rm -rf delete all files in the directory

f. ls (view the contents of files and directories)

   Commonly used:

   ls -al directory name

   ls -l (ll) directory name

   ls [--full-time] directory name

g. cp (copy file or directory)

    cp [-adfilprsu] source file object file

    Options and parameters:

    -a: equivalent to the meaning of -pdr

    -p: copy along with the properties of the file instead of using the default properties

    -d: If the source file is a property of the linked file, copy the properties of the linked file instead of the file itself

    -r: recursive persistent replication, for directory replication behavior

 h. rm (remove file or directory)

     Format: rm [-fir] file or directory

     Options and parameters:

     -f: means force, ignore files that do not exist, and no warning message will appear;

     -i: interactive mode, will ask the user for action before deleting

     -r: recursive deletion, most commonly used in directory deletion

i. mv (move files and directories, rename)

   Format: mv [-fiu] source destination

   Options and parameters:

   -f: force, if the target file already exists, overwrite without asking

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

   -u: If the target file already exists and the source is relatively new, it will be updated

 

2. Check the file content

The most commonly used command to display the contents of a file:
. cat displays the contents of the file starting from the first line

.tac starts from the last line

When .nl is displayed, output the line number along the way

. more Display file contents page by page

.less is similar to more, but can page forward

.head only looks at the first few lines

.tail only looks at the tail a few lines

.od reads the contents of the archive in binary

 

2.1 View file content directly

2.1.1 The main function of cat [-AbEnTv] is to continuously print the contents of a file on the screen

  Options and parameters:

  -A: Equivalent to the integration option of -vET, which can list some special characters instead of blanks;

  -b: List line numbers, display line numbers only for non-blank lines, blank lines are not marked with line numbers;

  -E: Display the trailing line break character $;

  -n: print the line number, along with the blank line will also have the line number;

  -T: Display the [Tab] key as ^I;

  -v: list some invisible special characters

2.1.2 tac (reverse listing) The main function is to display the contents of a file reversely from the last line on the screen

2.1.3 nl (add line number to print)

    nl [-bnw] file

    Options and parameters:

    -b: There are two main ways to specify the line number:

        -ba: Indicates that the line number is also listed regardless of whether it is an empty line or not;

        -bt: If there is an empty line, do not list the line number on the empty line

    -n: There are three main ways to list the line number representation:

       -n ln: The line number is displayed at the far left of the screen;

       -n rn: The line number is displayed at the far right of its own field without adding 0;

       -n rz: The line number is displayed at the far right of its own field, and 0 is added;

     -w: The number of bits occupied by the line number field.

2.2 Turnable page view

2.2.1 more Flip page by page

     During the operation of the more program, there are several keys that can be pressed:

     - Spacebar: Represents one page down

     - Enter: means scroll down one line

     - /String: Indicates that in the displayed content, search down the keyword [string];

     - :f : Immediately display the file name and the number of lines currently displayed;

     - q: means to leave more immediately, no longer display the content of the file

     - b: Represents page back, but this action is only useful for files, not for pipelines

2.2.2 less Flip page by page

     When more, we can't look forward, but look back. If less is used, we can use pageup, pagedown and other key functions to look back and forth in the file. Basically the commands that can be entered are:

    - Spacebar: Scroll down one page

    - pagedown : scroll down one page

    - pageup: flip up a page

    - /string: function to search down for "string"

    - ? String: Function to search up "string"

    - n : repeat search for previous search

    - N: Repeat the previous search in reverse

    - q: leave the less program

 

2.3 Data Capture

     2.3.1 head (take out the first few lines)

     Format: head [-n number] file

     Options and parameters:

     - n : followed by a number, which means to display several lines

     2.3.2 tail (take out the next few lines)

     Format: tail [-n number] file

     Options and parameters:

     - n: followed by a number, which means to display several lines

 

3. Modify the file time or create a new file

 There are many time parameters recorded under linux, but there are actually three main change times:

- modification time(mtime): When the content data of the file is changed, this time will be updated

- status time(ctime): When the "status" of the file changes, the time will be updated. If the attributes and permissions are changed, the time will be updated.

- access time(atime): The access time is updated when the contents of the file are accessed. For example, if we use cat to read /etc/man.config, it will update the atime of that file.

The most common use cases for the touch command are:

- create an empty file

- Revise a file date to the present (mtime & atime)

1. Directory and file management For directories, there are many commands that can be used to perform directory operations. First of all, you must know that there are some special commands: . Represents the current directory.. Represents the previous directory - represents the previous working directory~ Represents the current user identity The home directory ~account represents the home directory of the user account a. cd (change directory) b. pwd (display the directory) c. mkdir (create a new directory) mkdir [-mp] Directory name options and parameters: -m: Permissions of configuration files -p: help you to directly establish the required directories (including upper-level directories) recursively, such as: mkdir -m 711 test2 d.rmdir (delete empty directories) rm -rf delete all f.ls in the directory (View the contents of files and directories) Commonly used: ls -al directory name ls -l (ll) directory name ls [--full-time] directory name g. cp (copy file or directory) cp [-adfilprsu] source file destination File options and parameters: -a: equivalent to -pdr -p: copy along with the attributes of the file instead of using the default attributes -d: if the source file is the attribute of the linked file, copy the attributes of the linked file instead of the file itself -r: recursive continuous replication, used for directory replication h. rm (remove file or directory) format: rm [-fir] file or directory options and parameters: -f: means force, ignore non-existent file, no warning message will appear; -i: interactive mode, the user will be asked whether to act before deletion -r: recursive deletion, most commonly used in directory deletion i. mv (moving files and directories, renaming) format: mv [-fiu] source destination options and parameters: -f: force, if the target file already exists, it will overwrite without asking -i: if the target file already exists, it will ask whether to overwrite -u:If the target file already exists and the source is relatively new, it will be updated. 2. The most commonly used command to display the file content is to check the file content:
. cat starts to display the file content from the first line. tac starts to display from the last line. When nl is displayed, it outputs the line number along the way. more displays the file content page by page. less is similar to more, but can page forward. head only looks at the first few lines. tail only looks at the tail. od reads the file content in binary mode The above options and parameters: -A: It is equivalent to the integration option of -vET, which can list some special characters instead of blanks; -b: List line numbers, only display line numbers for non-blank lines, blank lines are not marked -E: Display the trailing line break character $; -n: Print the line number, along with blank lines; -T: Display the [Tab] key as ^I; -v: List some Special characters that cannot be seen Options and parameters: -b: There are two main ways to specify the line number: -ba: No matter whether it is an empty line, the line number is also listed; -bt: If there is an empty line, which line should not be listed Line number -n: There are three main ways to list the line number: -n ln: The line number is displayed at the far left of the screen; -n rn: The line number is displayed at the far right of its own field without adding 0; -n rz: The line number is displayed at the far right of its own field, and 0 is added; -w: The number of bits occupied by the line number field. 2.2 Page-turning view 2.2.1 more Turning page by page During the operation of the more program, there are several keys that can be pressed: - Spacebar: means to turn down a page - Enter: to turn down a line - /string: Indicates that in the displayed content, search down the keyword [string]; - :f : Immediately display the file name and the number of lines currently displayed; - q: means to leave more immediately, no longer display the content of the file - b: means to turn back the page, but this action is only useful for the file, not for the pipeline 2.2.2 less one When page-by-page flipping is in more, we can't flip forward, we can only look back. If less is used, we can use pageup, pagedown and other key functions to flip back and forth in the file. Basically the commands that can be entered are: - space bar: scroll down one page - pagedown: scroll down one page - pageup: scroll up one page - /string: function to search "string" down - ? string: function to search "string" upwards - n : repeat search previous search - N: repeat previous search in reverse - q: leave less this program 2.3 data extraction 2.3.1 head (remove first few lines) Format: head [-n number] File options and parameters: - n : followed by a number, which means to display a few lines 2.3.2 tail (take out the next few lines) Format: tail [-n number] File options and parameters: - n: followed by a number, which means to display several lines 3. Many time parameters will be recorded under linux when modifying the file time or creating a new file. In fact, there are three main change times: - modification time(mtime): the When the content data of the file is changed, this time will be updated - status time(ctime): When the "status" of the file is changed, this time will be updated. If the attributes and permissions are changed, this time will be updated. - access time(atime): The access time is updated when the contents of the file are accessed. For example, we use cat to read /etc/man. config, the atime of the file will be updated. The most common use cases for the touch command are: - to create an empty file - to revise a file's date to the present (mtime & atime)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326302204&siteId=291194637