文件和目录管理命令

mv 剪切文件/目录

[root@localhost test]# mv yum yum_bak
[root@localhost test]# ls
yum_bak

rm 删除文件/目录

[root@localhost test]# rm -rf yum_bak

file 查看文件类型

[root@localhost test]# file /etc/yum.conf
/etc/yum.conf: ASCII text

cat 查看纯文本(小)文件内容

[root@localhost test]# cat -n /etc/yum.conf
     1  [main]
     2  cachedir=/var/cache/yum/$basearch/$releasever
     3  keepcache=0
     4  debuglevel=2
     5  logfile=/var/log/yum.log
     6  exactarch=1
     7  obsoletes=1
     8  gpgcheck=1
     9  plugins=1

more 查看纯文本(大)文件内容

[root@localhost test]# file /etc/yum.conf
/etc/yum.conf: ASCII text

head 查看纯文本文件的前N行

[root@localhost test]# head -n 5 /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log

tail 查看纯文本文件的后N行

[root@localhost test]# tail -n 5 /etc/yum.conf
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

持续刷新文件内容

[root@localhost test]# tail -f test.log
hello
world

tr 替换纯文本文件中字符

[root@localhost test]# cat test.log | tr o a
hella
warld

wc 统计文本行数、字数、字节数

[root@localhost test]# wc test.log
 2  2 12 test.log

stat 查看文件具体存储和时间

[root@localhost test]# stat test.log
  File: ‘test.log’
  Size: 12              Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 204957191   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-01-01 01:59:30.369866673 +0800
Modify: 2019-01-01 01:58:33.647755947 +0800
Change: 2019-01-01 01:58:33.647755947 +0800
 Birth: -

diff 对比文本文件差异

比较文件是否相同

[root@localhost test]# diff --brief test.log test2.log
Files test.log and test2.log differ

比较文件不同的内容

[root@localhost test]# diff -c test.log test2.log
*** test.log    2019-01-01 01:58:33.647755947 +0800
--- test2.log   2019-01-01 02:05:57.301110030 +0800
***************
*** 1,2 ****
! hello
! world
--- 1 ----
! hello world
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值