Red Hat linux 6.5 学习使用笔记《三》linux常用文件管理命令

《三》linux常用文件管理命令

1.du命令详解

[root@localhost ~]# du --help

用法:du [选项]… [文件]…
 或:du [选项]… --files0-from=F
计算每个文件的磁盘用量,目录则取总用量。

长选项必须使用的参数对于短选项时也是必需使用的。

-a, --all 输出所有文件的磁盘用量,不仅仅是目录
–apparent-size 显示表面用量,而并非是磁盘用量;虽然表面用量通常会小一些,但有时它会因为稀疏文件间的"洞"、内部碎片、非直接引用的块等原因而变大。

[root@localhost ~]# du --apparent-size
4	./Public
378	./.gstreamer-0.10
4	./Videos
[root@localhost ~]# du --apparent-size
4	./Public
378	./.gstreamer-0.10
4	./Videos

-B, --block-size=大小 使用指定字节数的块

[root@localhost ~]# du -B 4
1024	./Public
97280	./.gstreamer-0.10
1024	./Videos
4096	./.gnupg

-b, --bytes 等于–apparent-size --block-size=1

[root@localhost ~]# du -b
4096	./Public
386241	./.gstreamer-0.10
4096	./Videos
11992	./.gnupg

-c, --total 显示总计信息

[root@localhost ~]# du -c
4	./Public
380	./.gstreamer-0.10
4	./Videos
.....................
.....................
.....................
4	./Downloads
1132	.
1132	total

-D, --dereference-args 解除命令行中列出的符号连接
–files0-from=F 计算文件F 中以NUL 结尾的文件名对应占用的磁盘空间如果F 的值是"-",则从标准输入读入文件名
-H 等于–dereference-args (-D)

-h, --human-readable 以可读性较好的方式显示尺寸(例如:1K 234M 2G)
–si 类似-h,但在计算时使用1000 为基底而非1024

[root@localhost ~]# du -h
4.0K	./Public
380K	./.gstreamer-0.10
4.0K	./Videos
16K	./.gnupg
4.0K	./Pictures
4.0K	./.gnome2/nautilus-scripts
4.0K	./.gnome2/panel2.d/default/launchers

-k 等于–block-size=1K
-l, --count-links 如果是硬连接,就多次计算其尺寸
-m 等于–block-size=1M

[root@localhost ~]# du -m
1	./Public
1	./.gstreamer-0.10

-L, --dereference 找出任何符号链接指示的真正目的地
-P, --no-dereference 不跟随任何符号链接(默认)
-0, --null 将每个空行视作0 字节而非换行符
-S, --separate-dirs 不包括子目录的占用量

[root@localhost ~]# du -S -s
132	.

-s, --summarize 只分别计算命令列中每个参数所占的总用量

[root@localhost ~]# du -s
1132	.

-x, --one-file-system 跳过处于不同文件系统之上的目录
-X, --exclude-from=文件 排除与指定文件中描述的模式相符的文件
–exclude=PATTERN 排除与PATTERN 中描述的模式相符的文件
–max-depth=N 显示目录总计(与–all 一起使用计算文件)当N 为指定数值时计算深度为N;
–max-depth=0 等于–summarize
–time 显示目录或该目录子目录下所有文件的最后修改时间
–time=WORD 显示WORD 时间,而非修改时间:atime,access,use,ctime 或status
–time-style=样式 按照指定样式显示时间(样式解释规则同"date"命令):full-iso,long-iso,iso,+FORMAT
–help 显示此帮助信息并退出
–version 显示版本信息并退出

2.read命令详解

[root@localhost ~]# type read
read is a shell builtin
[root@localhost ~]# help read

read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name …]
Read a line from the standard input and split it into fields.
【从标准输入读取一行,并把它分割为字段。】

描述:
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量,用 IFS(内部字段分隔符)变量中的字符作为分隔符。VariableName 参数指定 shell 变量的名称,shell 变量获取输入行一个字段的值。由VariableName 参数指定的第一个 shell 变量指定给每一个字段的值,由 VariableName 参数指定的第二个 shell 变量指定给第二个字段的值,以此类推,直到最后一个字段。如果标准输入行的字段比相应的由 VariableName 参数指定的 shell 变量的个数多,把全部余下的字段的值赋给指定的最后的 shell 变量。如果比 shell 变量的个数少,则剩余的 shell 变量被设置为空字符串。

Options:
-a 分配的单词读给顺序索引数组变量的数组,从0开始
-d 持续到第一个字符是阅读,而不是换行符

3.uname命令详解

[root@localhost ~]# uname --help

用法:uname [选项]…
输出一组系统信息。如果不跟随选项,则视为只附加-s 选项。

-a, --all 以如下次序输出所有信息。其中若-p 和
-i 的探测结果不可知则被省略:
-s, --kernel-name 输出内核名称
-n, --nodename 输出网络节点上的主机名
-r, --kernel-release 输出内核发行号
-v, --kernel-version 输出内核版本
-m, --machine 输出主机的硬件架构名称
-p, --processor 输出处理器类型或"unknown"
-i, --hardware-platform 输出硬件平台或"unknown"
-o, --operating-system 输出操作系统名称
–help 显示此帮助信息并退出
–version 显示版本信息并退出

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# uname -s
Linux
[root@localhost ~]# uname -n
localhost.localdomain
[root@localhost ~]# uname -r
2.6.32-431.el6.x86_64
[root@localhost ~]# uname -v
**重点内容**#1 SMP Sun Nov 10 22:19:54 EST 2013
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# uname -p
x86_64
[root@localhost ~]# uname -i
x86_64
[root@localhost ~]# uname -o
GNU/Linux

4.pwd命令详解

[root@localhost ~]# help pwd

pwd: pwd [-LP]
打印当前工作目录的名称

Options:
-L print the value of $PWD if it names the current working
directory
-P print the physical directory, without any symbolic links

By default, pwd' behaves as if-L’ were specified.

[root@localhost ~]# pwd L
/root
[root@localhost ~]# pwd P
/root

5.cat命令详解

[root@localhost ~]# cat --help

Usage: cat [OPTION]… [FILE]…
Concatenate FILE(s), or standard input, to standard output.
【连接文件或标准输入、标准输出。】

-A, --show-all equivalent to -vET 【等价于 -vET】
-b, --number-nonblank number nonempty output lines【 对非空输出行编号】
-e equivalent to -vE【等价于 -vE】
-E, --show-ends display $ at end of each line【在每行结束处显示 $】
-n, --number number all output lines【对输出的所有行编号,由1开始对所有输出的行数编号】
-s, --squeeze-blank suppress repeated empty output lines【有连续两行以上的空白行,就代换为一行的空白行 】
-t equivalent to -vT【与 -vT 等价】
-T, --show-tabs display TAB characters as ^I【将跳格字符显示为 ^I】
-u (ignored)【被忽略】
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB【使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外】
–help display this help and exit
–version output version information and exit

With no FILE, or when FILE is -, read standard input.【没有文件或文件时,读取标准输入。】

[root@localhost ~]# cat -A test1 
123456$
789456$
369258$
[root@localhost ~]# cat -b test1 
     1	123456
     2	789456
     3	369258
[root@localhost ~]# cat -e test1 
123456$
789456$
369258$
[root@localhost ~]# cat -E test1 
123456$
789456$
369258$
[root@localhost ~]# cat -n test1 
     1	123456
     2	789456
     3	369258
[root@localhost ~]# cat -s test1 
123456
789456
369258
[root@localhost ~]# cat -t test1 
123456
789456
369258
[root@localhost ~]# cat -T test1 
123456
789456
369258
[root@localhost ~]# cat -u test1 
123456
789456
369258
[root@localhost ~]# cat -v test1 
123456
789456
369258
[root@localhost ~]# 

6.more命令简介

[root@localhost ~]# man more

NAME
more - file perusal filter for crt viewing

SYNOPSIS
more [-dlfpcsu] [-num] [+/pattern] [+linenum] [file …]

DESCRIPTION
More is a filter for paging through text one screenful at a time. This ver- sion is especially primitive. Users should realize that less(1) provides more(1) emulation and extensive enhancements.
【more是一个将一整个萤幕的文本分页的过滤器。】
OPTIONS
Command line options are described below. Options are also taken from the environment variable MORE (make sure to precede them with a dash (‘‘-’’)) but command line options will override them.

-num 【这个选项指定一个整数的屏幕尺寸(行)。】

-d 【将提示用户信息”(按空格键继续,按q退出”,将显示“按h帮助。”而不是非法键被按下时响铃。】




http://www.cnblogs.com/peida/archive/2012/11/02/2750588.html

7.less命令简介

 [root@localhost ~]# man less

NAME
less - opposite of more

SYNOPSIS
less -?
less --help
less -V
less --version
less [-[+]aBcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,…] [-y lines] [-[z] lines]
[-# shift] [+[+]cmd] [–] [filename]…
(See the OPTIONS section for alternate option syntax with long option
names.)

DESCRIPTION
Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.) Commands are based on both more and vi. Commands may be preceded by a decimal number, called N in the descriptions below. The number is used by some commands, as indicated.
【功能类似于more】
http://www.cnblogs.com/peida/archive/2012/11/05/2754477.html

8.head命令详解

[root@localhost ~]# head --help

用法:head [选项]… [文件]…
将每个指定文件的头10 行显示到标准输出。
如果指定了多于一个文件,在每一段输出前会给出文件名作为文件头。
如果不指定文件,或者文件为"-",则从标准输入读取数据。

长选项必须使用的参数对于短选项时也是必需使用的。
-c, --bytes=[-]K 显示每个文件的前K 字节内容;
如果附加"-“参数,则除了每个文件的最后K字节数据外
显示剩余全部内容
-n, --lines=[-]K 显示每个文件的前K 行内容;
如果附加”-"参数,则除了每个文件的最后K 行外显示
剩余全部内容
-q, --quiet, --silent 不显示包含给定文件名的文件头
-v, --verbose 总是显示包含给定文件名的文件头
–help 显示此帮助信息并退出
–version 显示版本信息并退出

12345[root@localhost ~]# cat test1 
123456
789456
369258
[root@localhost ~]# head -c 5 test1 
12345[root@localhost ~]# 

[root@localhost ~]# cat test1 
123456
789456
369258
[root@localhost ~]# head -c -6 test1 
123456
789456
3[root@localhost ~]# 
[root@localhost ~]# head -q test1 
123456
789456
369258
[root@localhost ~]# 
[root@localhost ~]# head -v test1 
==> test1 <==
123456
789456
369258
[root@localhost ~]# 

9.tail命令详解

[root@localhost ~]# type tail
tail is /usr/bin/tail
[root@localhost ~]# tail --help

用法:tail [选项]… [文件]…
显示每个指定文件的最后10 行到标准输出。
若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头。
如果不指定文件或文件为"-" ,则从标准输入读取数据。

长选项必须使用的参数对于短选项时也是必需使用的。
-c, --bytes=K 输出最后K 字节;另外,使用-c +K 从每个文件的
第K 字节输出
-f, --follow[={name|descriptor}]
即时输出文件变化后追加的数据。
-f, --follow 等于–follow=descriptor
-F 即–follow=name --retry
–pid=PID 同 -f 一起使用,当 PID 所对应的进程死去后终止
-q, --quiet, --silent 不输出给出文件名的头
–retry 即使目标文件不可访问依然试图打开;在与参数
–follow=name 同时使用时常常有用。
-v, --verbose always output headers giving file names
–help 显示此帮助信息并退出
–version 显示版本信息并退出

[root@localhost ~]# tail -f test1 
123456
789456
369258

-n, --lines=K 输出最后k行而不是10行,或者说使用 -n +K 输出第k行开始的行

[root@localhost ~]# cat test1 
123456
789456
369258
[root@localhost ~]# tail -n 1 test1 
369258

-q, --quiet, --silent 【不在开头输出文件名】
-v, --verbose 【在开头输出文件名】

[root@localhost ~]# tail -n 1 -q test1 
369258
[root@localhost ~]# tail -n 1 -v test1 
==> test1 <==
369258

10.cut命令详解

[root@localhost ~]# cut --help

用法:cut [选项]… [文件]…
从每个文件中输出指定部分到标准输出。

长选项必须使用的参数对于短选项时也是必需使用的。
-b, --bytes=列表 只选中指定的这些字节
-c, --characters=列表 只选中指定的这些字符
-d, --delimiter=分界符 使用指定分界符代替制表符作为区域分界
-f, --fields=LIST select only these fields; also print any line
that contains no delimiter character, unless
the -s option is specified
-n with -b: don’t split multibyte characters
–complement 补全选中的字节、字符或域
-s, --only-delimited 不打印没有包含分界符的行
–output-delimiter=字符串 使用指定的字符串作为输出分界符,默认采用输入
的分界符
–help 显示此帮助信息并退出
–version 显示版本信息并退出

[root@localhost ~]# cat testfile2
123
456
789
[root@localhost ~]# cut -b 2 testfile2 
2
5
8
[root@localhost ~]# cut -c 2 testfile2 
2
5
8
[root@localhost etc]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost etc]# cut -d : -f 1-3  passwd
root:x:0
bin:x:1
daemon:x:2
adm:x:3
lp:x:4
sync:x:5

11.sort命令详解

[root@localhost etc]# sort --help

用法:sort [选项]… [文件]…
 或:sort [选项]… --files0-from=F
串联排序所有指定文件并将结果写到标准输出。

长选项必须使用的参数对于短选项时也是必需使用的。
排序选项:

-b, --ignore-leading-blanks 忽略前导的空白区域
-d, --dictionary-order 只考虑空白区域和字母字符
-f, --ignore-case 忽略字母大小写
-g, --general-numeric-sort 按照常规数值排序
-i, --ignore-nonprinting 只排序可打印字符
-M, --month-sort 比较 (未知) < “一月” < … < “十二月”
在LC_ALL=C 时为(unknown) < JAN' < ... <DEC’
-h, --human-numeric-sort 使用易读性数字(例如: 2K 1G)
-n, --numeric-sort 根据字符串数值比较
-R, --random-sort 根据随机hash 排序
–random-source=文件 从指定文件中获得随机字节
-r, --reverse 逆序输出排序结果
–sort=WORD 按照WORD 指定的格式排序:
一般数字-g,高可读性-h,月份-M,数字-n,
随机-R,版本-V
-V, --version-sort 在文本内进行自然版本排序

[root@localhost etc]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
..................
..................
..................
[root@localhost etc]# cut -d : -f 3 passwd | sort -n
0
1
2
3
4
5
6
7
8
10
11
12
13
14
27
..................
..................
..................
[root@localhost etc]# cut -d : -f 5 passwd | sort -d


adm
Anonymous NFS User
Apache
Avahi IPv4LL Stack
bin
daemon
FTP User
games
gopher
HAL daemon
halt
kevinhanser
lp
mail
MySQL Server
Nobody
operator
Privilege-separated SSH
PulseAudio System Daemon
..................
..................
..................

http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html
http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html

12.uniq命令详解

[root@localhost etc]# type uniq
uniq is /usr/bin/uniq
[root@localhost etc]# uniq --help

用法:uniq [选项]… [文件]
从输入文件或者标准输入中筛选相邻的匹配行并写入到输出文件或标准输出。不附加任何选项时匹配行将在首次出现处被合并。

长选项必须使用的参数对于短选项时也是必需使用的。
-c, --count 在每行前加上表示相应行目出现次数的前缀编号
-d, --repeated 只输出重复的行
-D, --all-repeated[=delimit-method 显示所有重复的行
delimit-method={none(default),prepend,separate}
以空行为界限
-f, --skip-fields=N 比较时跳过前N 列
-i, --ignore-case 在比较的时候不区分大小写
-s, --skip-chars=N 比较时跳过前N 个字符
-u, --unique 只显示唯一的行
-z, --zero-terminated 使用’\0’作为行结束符,而不是新换行
-w, --check-chars=N 对每行第N 个字符以后的内容不作对照
–help 显示此帮助信息并退出
–version 显示版本信息并退出

[root@localhost ~]# sort testfile2 | uniq -c
      5 123
      1 1231
      1 12456564543876
	  3 741
      1 741.
      3 789
      ..................
      ..................
      ..................
[root@localhost ~]# sort testfile2 | uniq -d
123
456
486
..................
..................
..................
[root@localhost ~]# sort testfile2 | uniq -D
123
123
123
123
123
456
456
456
456
..................
..................
..................

13.wc命令详解

[root@localhost ~]# wc --help

用法:wc [选项]… [文件]…
 或:wc [选项]… --files0-from=F
输出每个指定文件的行数、单词计数和字节数,如果指定了多于一个文件,继续给出所有相关数据的总计。如果没有指定文件,或者文件为"-",则从标准输入读取数据。
-c, --bytes 输出字节数统计
-m, --chars 输出字符数统计
-l, --lines 输出行数统计
–files0-from=文件 从指定文件读取以NUL 终止的名称,如果该文件被指定为"-"则从标准输入读文件名
-L, --max-line-length 显示最长行的长度
-w, --words 显示单词计数
–help 显示此帮助信息并退出
–version 显示版本信息并退出

[root@localhost ~]# uniq -D testfile2
[root@localhost ~]# wc testfile2 
 46  46 203 testfile2
[root@localhost ~]# wc -c testfile2 
203 testfile2
[root@localhost ~]# wc -m testfile2 
203 testfile2
[root@localhost ~]# wc -l testfile2 
46 testfile2
[root@localhost ~]# wc -w testfile2 
46 testfile2
[root@localhost ~]# wc -L testfile2 

14.tr命令详解

root@localhost ~]# tr --help

用法:tr [选项]… SET1 [SET2]
从标准输入中替换、缩减和/或删除字符,并将结果写到标准输出。
例如大写替换小写

-c, -C, --complement 首先补足SET1
-d, --delete 删除匹配SET1 的内容,并不作替换
-s, --squeeze-repeats 如果匹配于SET1 的字符在输入序列中存在连续的重复,在替换时会被统一缩为一个字符的长度
-t, --truncate-set1 先将SET1 的长度截为和SET2 相等
–help 显示此帮助信息并退出
–version 显示版本信息并退出

SET 是一组字符串,一般都可按照字面含义理解。解析序列如下:
\NNN 八进制值为NNN 的字符(1 至3 个数位)
\ 反斜杠
\a 终端鸣响
\b 退格
\f 换页
\n 换行
\r 回车
\t 水平制表符
\v 垂直制表符

字符1-字符2 从字符1 到字符2 的升序递增过程中经历的所有字符
[字符*] 在SET2 中适用,指定字符会被连续复制直到吻合设置1 的长度
[字符*次数] 对字符执行指定次数的复制,若次数以 0 开头则被视为八进制数
[:alnum:] 所有的字母和数字
[:alpha:] 所有的字母
[:blank:] 所有呈水平排列的空白字符
[:cntrl:] 所有的控制字符
[:digit:] 所有的数字
[:graph:] 所有的可打印字符,不包括空格
[:lower:] 所有的小写字母
[:print:] 所有的可打印字符,包括空格
[:punct:] 所有的标点字符
[:space:] 所有呈水平或垂直排列的空白字符
[:upper:] 所有的大写字母
[:xdigit:] 所有的十六进制数
[=字符=] 所有和指定字符相等的字符

[root@localhost ~]# tr ab AB
acsxb
AcsxB
aabbf
AABBf
abcab
ABcAB

[root@localhost ~]# cat testfile
12345687
96385214
I'm  a
I'm a student 
today is sunday
today is sunday
[root@localhost ~]# cat testfile | tr [[:digit:]] x
xxxxxxxx
xxxxxxxx
I'm  a
I'm a student 
today is sunday
today is sunday
[root@localhost ~]# cat testfile | tr [[:upper:]] O
12345687
96385214
O'm  a
O'm a student 
today is sunday
today is sunday
[root@localhost ~]# cat testfile | tr [[:upper:]] \\t
12345687
96385214
	;m
	'm  a
	'm a student 
today is sunday

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值