Linux file management command: lsattr \ od \ paste \ stat \ tee

lsattr: display file attributes

  • Function: view the file attributes set by chattr.

  • Usage: lsattr [options] [file or directory]

  • The main options are as follows:

Order describe
-R Recursively list the attributes of a directory and its contents.
-V Displays the program version.
-a List all files in the directory, including the attributes of files starting with ".".
-d List the attributes of a directory in the same way as other files, without listing the contents under it.
-v Displays the file version.

case study

(1) View the properties of an sbin directory rather than its contents.

# lsattr -d /sbin 
----------I-- /sbin 

(2) Recursively list the attributes of the /home/cjh directory and its contents.

# lsattr -R /home/cjh 
------------- /home/cjh/1 
------------- /home/cjh/ch 
/home/cjh/ch: 

od: output file content

  • Function: The od command will read the content of the given file and present its content in octal code.
  • Usage: od [option]…[file]…
  • The main options are as follows:

Dump the specified file to standard output in octal form (default). If more than one file parameter is specified, the program will automatically combine the input content into a list and output it in the same form.

If no file is specified, or "-" is specified, the program will read data from standard input.

Arguments that are mandatory for long options are also mandatory when using short options.

Order describe
-A,--address-radix=初始偏移 Sets the initial offset of the file to display.
-j,--skip-bytes=字节数 Skip the specified number of bytes of input.
-N,--read-bytes=字节数 Limits the input bytes to dump to the specified number of bytes.
-S,--strings[=字节数] Outputs a string corresponding to characters containing at least the specified number of bytes.
-t,--format=类型 Choose the output format type.
-v,--output-duplicates Masked lines are not marked with the "*" character.
-w,--width[=字节数] Output only the specified number of bytes per line.
--traditional Accepts parameters submitted in the traditional form.
--help Display this help message and exit.
--version Display version information and exit.

Traditional format commands can be mixed, and different formats can be superimposed.

Order describe
-a That is -ta, use the named characters, ignoring high-order bits.
-b That is -to1, use octal single-byte characters.
-c That is -tc, use ASCII characters, or the backslash filename special character.
-d That is -tu2, use unsigned decimal double-byte characters.
-f Namely -tfF, specifies the control output format of floating-point numbers.
-i Namely -tdl, specifies the control output format of decimal integers.
-l Namely -tdL, specifies the control output format of the decimal long integer.
-o That is -to2, specify the output format of the double-byte unit octal number comparison.
-s Namely -td2, specifies the comparison output format of double-byte unit decimal numbers.
-x That is -tx2, specify the output format of the double-byte unit hexadecimal number.

If both call formats are applicable, the second is used if the last operand starts with "+" or a number (if there are two operands).

Offset refers to -j offset. The tag is the pseudo-address of the first byte, which is incremented as the accumulation progresses. If the offset and label are prefixed with "0x" or "0X", it means a hexadecimal number; the suffix "." means an octal number, and the suffix "b" means multiply by 512.

TYPE is composed of one or more of the following parameters:

parameter describe
a Redefine characters, ignoring high-order bytes.
c An ASCII character or a backslash string (such as \n).
d[size] Signed decimal numbers, each integer occupies bytes of the specified size.
f[size] Floating-point numbers, each integer occupies bytes of the specified size.
o[size] Octal numbers, each integer occupies bytes of the specified size.
u[size] Unsigned decimal numbers, each integer occupies bytes of the specified size.
x[size] Hexadecimal numbers, each integer occupies bytes of the specified size.

Size should be a number. For types such as doux, the applicable sizes are: C stands for sizeof(char), S stands for sizeof(short), I stands for sizeof(int), or L stands for sizeof(long); if the type is f, the applicable size There are: F for sizeof(float), D for sizeof(double), or L for sizeof(long double).

When RADIX is "d", it means decimal, when it is "o", it means octal, when it is "x", it means hexadecimal, and "n" means none.

BYTES is a hexadecimal number prefixed with 0x or 0X, and may have the following suffixes:

b 512, kB 1000, K 1024, MB 1000×1000, M 1024×1024, GB 1000´1000´1000, G 1024´1024´1024, same for T, P, E, Z, Y.

Adding a "z" suffix to any type will display displayable characters at the end of each output line.

The --string option without a number represents 3; the --width option without a number represents 32.

By default od uses -A o -t oS -w16 parameters

case study

Displays the octal code of a .txt file.

# od 1.txt 
0000000 072560 066142 061551 061440 060554 071563 044040 066145 
0000020 067554 075440 005012 072560 066142 061551 044040 066145 
0000040 067554 024450 075440 076412 005012 072560 066142 061551 
0000060 071440 060564 064564 020143 067566 062151 066440 064541 
0000160 062154 021041 035451 076412 005012 005175 
0000174

paste:合并文件的列

  • 作用:paste 命令会把每个文件以列对列的方式一列列地加以合并。
  • 用法:paste [选项]…[文件]…
  • 主要选项如下:
命令 描述
-d,--delimiters=列表 改用指定列表里的字符替代制表分隔符。
-s,--serial 不使用平行的行目输出模式,而是每个文件占用一行。
--help 显示此帮助信息并退出。
--version 显示版本信息并退出

案例练习

显示合并一个.txt 文件的列。

# paste 1.txt 
public class Hello {
    
     
public Hello() {
    
     
} 
public static void main(String[] args) {
    
     
System.out.println("Hello World! "); 
} 
}

stat:显示 inode 内容

  • 作用:stat 以文字的用法来显示 inode 的内容。
  • 用法:stat [文件或目录] stat [选项]…文件…
  • 显示文件或文件系统的状态。
命令 描述
-L,--dereference 跟随链接。
-f,--file-system 显示文件系统状态而非文件状态。
-c--format=格式 使用指定输出格式代替默认值,每用一次指定格式换一新行。
--printf=格式 类似–format,但是会解释反斜杠转义符,不使用换行作输出结尾。如果 仍希望使用换行,可以在格式中加入“\n”。
-t,--terse 使用简洁格式输出。
--help 显示此帮助信息并退出。
--version 显示版本信息并退出。

有效的文件格式序列(不使用–file-system)如下。

有效的文件格式序列(不使用–file-system)如下。
%a:八进制权限。
%A:用可读性较好的方式输出权限。
%b:计算已分配块数(参见%B)。
%B:以字节为单位输出%b 所报告的每个块的大小。
%C:SELinux 安全环境字符串。
%d:十进制设备编号。
%D:十六进制设备编号。
%f:十六进制原始模式。
%F:文件类型。
%g:文件的属组 ID
%G:文件的属组组名。
%h:硬链接数量。
%i:Inode 编号。
%m:挂载点。
%n 文件名。
%N:如果对象是一个符号链接,则显示引用到的其他文件名。
%o:I/O 块大小。
%s:总计大小,以字节为单位。
%t:十六进制主设备类型。
%T:十六进制子设备类型。
%u:文件的属主 ID。
%U:文件的属主用户名。
%w:文件创建时间,若未知则显示“-”。
%W:从 UNIX 元年起以秒计的文件创建时间,若未知则显示“-”。
%x:上次访问时间。
%X:从 UNIX 元年起以秒计的上次访问时间。
%y:上次修改时间。
%Y:从 UNIX 元年起以秒计的上次修改时间。
%z:上次更改时间。
%Z:从 UNIX 元年起以秒计的上次更改时间。有效的文件系统格式序列如下。
%a:非超级用户可用的剩余块数。
%b:文件系统的总数据块数。
%c:文件系统中文件节点总数。
%d:文件系统中空闲文件节点数。
%f:文件系统中空闲块数。
%i:十六进制文件系统 ID。
%I:允许的文件名最大长度。
%n:文件名。
%s:块大小(用于快速传输)。
%S:基本块大小(用于块计数)。
%t:十六进制类型描述。
%T:可读性较好的类型描述。

案例练习

查看.txt 文件的 inode 内容。

# stat 1.txt 
 File: “1.txt”
 Size: 0 Blocks: 0 IO Block: 4096 一般空文件
Device: fd00h/64768d Inode: 1182306 Links: 1 
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) 
Access: 2008-08-02 20:11:28.000000000 +0800 
Modify: 2008-08-02 20:11:27.000000000 +0800 
Change: 2008-08-02 20:11:27.000000000 +0800

说明 inode 译成中文就是索引节点。每个存储设备或存储设备的分区(存储设备是硬盘、 软盘、U 盘……)被用法化为文件系统后,应该有两部分,一部分是 inode,另一部分 是 Block。Block 是用来存储数据的。而 inode 用来存储这些数据的信息,包括文件大 小、属主、归属的用户组、读/写权限等。inode 为每个文件进行信息索引,所以就有 了 inode 的数值。操作系统根据命令,能通过 inode 值最快地找到相对应的文件。

tee:读取标准输入到标准输出并可保存为文件

  • 作用:读取标准输入的数据,并将其内容输出成文件。
  • 用法:tee [选项] [文件…]
  • 主要选项如下:
命令 描述
-a,--append 内容追加到给定的文件而非覆盖。
-i,--ignore-interrupts 忽略中断信号。
--help 显示此帮助信息并退出。
--version 显示版本信息并退出。

如果文件指定为“-”,则将输入内容复制到标准输出。

说明 tee 命令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成 文件

案例练习

(1)要同时查看和保存一个命令的输出。

#sort program.c | tee program.lint

它在工作站上显示命令 sort program.c 的标准输出,同时在文件 program.lint 中保存输出的 一个副本。如果 program.lint 文件早已存在,它将被删除并替换。

(2)要同时查看一个命令的输出并保存到一个现有文件。

# sort program.c | tee -a program.lint

它将在工作站上显示 sort program.c 命令的标准输出,同时在 program.lint 文件尾部添加输 出的一个副本。如果 program.lint 文件不存在,它将被创建。

Guess you like

Origin blog.csdn.net/u014096024/article/details/131646302