收集、整理日常系统管理或维护当中的,常用到的一些关于文件操作的命令或需求,后续会慢慢补充、完善!
· 查看、生成指定目录的目录树结构
[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 是改变时间