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

最常使用的显示档案内容的指令的:
. cat  由第一行开始显示档案内容

. tac  从最后一行开始显示

. nl  显示的时候,顺道输出行号

. more 一页一页的显示档案内容

. less 与more 类似,但是可以往前翻页

. head 只看头几行

. tail 只看尾巴几行

. od 以二进制的方式读取档案内容

 

2.1 直接检视档案内容

2.1.1 cat [-AbEnTv] 主要功能是将一个档案的内容连续的印出在屏幕上面

  选项与参数:

  -A: 相当于 -vET的整合选项,可列出一些特殊字符而不是空白而已;

  -b: 列出行号,仅针对非空白行做行号显示,空白行不标行号;

  -E: 将结尾的断行字符$显示出来;

  -n: 打印出行号,连同空白行也会有行号;

  -T: 将[Tab]按键以^I 显示出来;

  -v: 列出一些看不出来的特殊字符

2.1.2 tac(反向列示) 主要功能是将一个档案的内容由最后一行反向在屏幕上显示出来

2.1.3 nl(添加行号打印)

    nl [-bnw] 档案

    选项与参数:

    -b: 指定行号指定的方式,主要有两种:

        -b a: 表示不论是否为空行,也同样列出行号;

        -b t: 如果有空行,空的哪一行不要列出行号

    -n: 列出行号表示的方法,主要有三种:

       -n ln: 行号在屏幕的最左方显示;

       -n rn: 行号在自己字段的最右方显示,且不加0;

       -n rz: 行号在自己字段的最右方显示,且加0;

     -w: 行号字段的占用位数。

2.2 可翻页检视

2.2.1 more 一页一页翻动

     在more 这个程序的运作过程中,有几个按键是可以按的:

     - 空格键: 代表向下翻一页

     - Enter:代表向下翻一行

     - /字符串: 代表在这个显示的内容当中,向下搜索【字符串】这个关键字;

     - :f  :立刻显示文件名以及目前显示的行数;

     - q: 代表立刻离开more, 不再显示该档案内容

     -  b: 代表往回翻页,不过这动作只对档案有用,对管线无用

2.2.2 less 一页一页翻动

     在more 的时候,我们并没有办法向前面翻,只能往后看,若使用了less 时,就可以使用pageup,pagedown 等按键的功能来往前往后翻看文件。基本上可以输入的指令有:

    - 空格键: 向下翻动一页

    - pagedown : 向下翻动一页

    - pageup: 向上翻动一页

    - /字符串:向下搜索"字符串" 的功能

    - ?字符串: 向上搜索“字符串” 的功能

    - n : 重复搜索前一个搜寻

    - N: 反向的重复前一个搜寻

    - q: 离开less 这个程序

 

2.3 资料撷取

     2.3.1 head (取出前面几行)

     格式: head [-n number] 档案

     选项与参数:

     - n : 后面接数字,代表显示几行的意思

     2.3.2 tail(取出后面几行)

     格式: tail [-n number] 档案

     选项与参数:

     - n: 后面接数字, 代表显示几行的意思

 

3. 修改档案时间或建置新档

 在linux 底下都会有记录许多的时间参数,其实是有三个主要的变动时间:

- modification time(mtime): 该档案的内容数据变更时,就会更新这个时间

- status time(ctime):当该档案的“状态”改变时,就会更新这个时间,如属性与权限的被更改了,都会更新这个时间。

- access time(atime): 当该档案的内容被取用时,就会更新这个读取时间。举例来说,我们使用cat去读取/etc/man.config,就会更新该档案的atime了。

touch 这个指令最常被使用的情况是:

- 建立一个空的档案

- 将某个档案日期修订为目前(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, or 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 it 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 2.1 Directly view the file content 2.1.1 cat [-AbEnTv] The main function is to continuously print the content of a file on the screen 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 on the far left of the screen; -n rn: The line number is displayed on 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 digits 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 for the keyword [string]; - :f : Immediately display the file name and the number of lines currently displayed; - q: means to leave more immediately, and 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=326302283&siteId=291194637