Linux文件操作常用命令整理

发表于:2016-7-26 10:37

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:潇湘隐者    来源:51Testing软件测试网采编

#
Linux
分享:
  收集、整理日常系统管理或维护当中的,常用到的一些关于文件操作的命令或需求,后续会慢慢补充、完善!
  · 查看、生成指定目录的目录树结构
  [root@DB-Server ~]#tree   #当前目录
  [root@DB-Server ~]#tree  /home/oracle/kerry
  · 查看当前目录或指定目录的大小?
  [root@DB-Server ~]#du -sh /u01
  [root@DB-Server ~]#du -sh
  · 查看各个文件或子文件夹大小
  [root@DB-Server ~]#du -sh *
  · 查找相关文件并打印输出?
  [root@DB-Server ~] find /home/oracle -name "awr*" -print
  · 计算当前目录下的文件和文件夹数?
  [root@DB-Server ~]# ls -lrt | grep -v 'total' | wc -l
  · 计算当前目录下的文件数(不包含子目录)?
  [root@DB-Server ~]#ls -l | grep "^-" | wc -l
  · 计算当前目录下的文件数(包含子目录)?
  [root@DB-Server ~]#ls -l * | grep "^-" | wc –l
  · 只查看或列出当前文件夹下的子目录?
  [root@DB-Server ~]# ls -l | grep "^d" | wc -l
  · 只列出目录下面的子目录?
  [root@DB-Server ~]# ls -F | grep /$ #注意:此命令不能统计子目录的子目录。
  · 查看文件的某一列内容
  [root@DB-Server ~]# cat /etc/passwd | awk -F ":" '{print $1}'
  · 查看文件的前N行内容
  [root@DB-Server ~]# head -5 /etc/passwd
  · 查看文件的后N行内容
  [root@DB-Server ~]# tail -5 /etc/passwd
  · 查看文件中的某几行内容
  [root@DB-Server ~]# sed -n '5,10p' /etc/passwd
  · 查看文件的创建时间、修改时间、访问时间 创建时间、访问时间、修改时间和改变时间
[root@DB-Server ~]# touch test
[root@DB-Server ~]# stat test
File: `test'
Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 4196044     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-07-25 15:53:07.000000000 +0800
Modify: 2016-07-25 15:53:07.000000000 +0800
Change: 2016-07-25 15:53:07.000000000 +0800
[root@DB-Server ~]#
  Access 是访问时间
  Modify 是修改时间
  Change 是改变时间
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号