Linux如何查找大文件或目录总结及在全部目录中查找
在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件夹的方法。
1: 如何查找大文件?
其实很多时候,你需要了解当前系统下有哪些大文件,比如文件大小超过100M或1G(阀值视具体情况而定)。那么如何把这些大文件搜索出来呢?例如我要搜索当前目录下,超过800M大小的文件
[root@getlnx01 u03]# pwd
/u03
[root@getlnx01 u03]# find . -type f -size +800M
./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
./oradata/epps/invsubmat_d08.dbf
./oradata/epps/gmtinv_d08.dbf
./oradata/epps/gmtinv_x01.dbf
./oradata/epps/undotbs02.dbf
./oradata/epps/gmtinv_d07.dbf
./oradata/epps/undotbs01.dbf
./oradata/epps/gmtinv_x02.dbf

如上命令所示,我们仅仅能看到超过800M大小的文件的文件名称,但是对文件的信息(例如,文件大小、文件属性)一无所知,那么能否更详细显示一些文件属性或信息呢,当然可以,如下所示
[root@getlnx01 u03]# find . -type f -size +800M -print0 | xargs -0 ls -l
-rw-r----- 1 oracle oinstall 2782846976 Mar 6 11:51 ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
-rw-r----- 1 oracle oinstall 1878433792 Mar 6 11:53 ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
-rw-r----- 1 oracle oinstall 1378492416 Mar 6 11:54 ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
-rw-r----- 1 oracle oinstall 1641381888 Mar 6 11:56 ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
-rw-r----- 1 oracle oinstall 1564065792 Mar 6 11:58 ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
-rw-r----- 1 oracle oinstall 1663492096 Mar 6 12:00 ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
-rw-r----- 1 oracle oinstall 1368244224 Mar 6 12:02 ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
-rw-r----- 1 oracle oinstall 1629069312 Mar 6 12:04 ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
-rw-r----- 1 oracle oinstall 1629954048 Mar 6 12:06 ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
-rw-r----- 1 oracle oinstall 1202192384 Mar 6 12:07 ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
-rw-r----- 1 oracle oinstall 1189388288 Mar 6 12:10 ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
-rw-r----- 1 oracle oinstall 1089257472 Mar 6 12:11 ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
-rw-r----- 1 oracle oinstall 1097687040 Mar 6 12:12 ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
-rw-r----- 1 oracle oinstall 1051009024 Mar 6 12:13 ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:07 ./oradata/epps/gmtinv_d07.dbf
-rw-r----- 1 oracle oinstall 4194312192 Apr 1 22:36 ./oradata/epps/gmtinv_d08.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:54 ./oradata/epps/gmtinv_x01.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:57 ./oradata/epps/gmtinv_x02.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 1 22:35 ./oradata/epps/invsubmat_d08.dbf
-rw-r----- 1 oracle oinstall 8589942784 Apr 4 09:55 ./oradata/epps/undotbs01.dbf
-rw-r----- 1 oracle oinstall 8589942784 Apr 4 09:15 ./oradata/epps/undotbs02.dbf

当我们只需要查找超过800M大小文件,并显示查找出来文件的具体大小,可以使用下面命令
[root@getlnx01 u03]# find . -type f -size +800M -print0 | xargs -0 du -h
1.3G ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
1.5G ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
1.3G ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
1004M ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
2.6G ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
1.8G ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
4.1G ./oradata/epps/invsubmat_d08.dbf
4.0G ./oradata/epps/gmtinv_d08.dbf
4.1G ./oradata/epps/gmtinv_x01.dbf
8.1G ./oradata/epps/undotbs02.dbf
4.1G ./oradata/epps/gmtinv_d07.dbf
8.1G ./oradata/epps/undotbs01.dbf
4.1G ./oradata/epps/gmtinv_x02.dbf

如果你还需要对查找结果按照文件大小做一个排序,那么可以使用下面命令
[root@getlnx01 u03]# find . -type f -size +800M -print0 | xargs -0 du -h | sort -nr
1004M ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
8.1G ./oradata/epps/undotbs02.dbf
8.1G ./oradata/epps/undotbs01.dbf
4.1G ./oradata/epps/invsubmat_d08.dbf
4.1G ./oradata/epps/gmtinv_x02.dbf
4.1G ./oradata/epps/gmtinv_x01.dbf
4.1G ./oradata/epps/gmtinv_d07.dbf
4.0G ./oradata/epps/gmtinv_d08.dbf
2.6G ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
1.8G ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
1.5G ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
1.3G ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
1.3G ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1

不过如上截图所示,有时候排列的顺序并不完全是按大小一致,这个是因为du命令的参数h所致,你可以统一使用使用MB来显示,这样就能解决这个问题。到这里,这个在Linux系统查找大文件的命令已经非常完美了,当然如果你还有很多的需求,那么可以在这个命令上做修改、调整.

2: 如何查找Linux下的大目录
譬如有时候磁盘空间告警了,而你平时又疏于管理、监控文件的增长,那么我需要快速的了解哪些目录变得比较大,那么此时我们可以借助du命令来帮我们解决这个问题。
[root@getlnx01 u03]# du -h --max-depth=1
16K ./lost+found
33G ./flash_recovery_area
37G ./oradata
70G .
如果你想知道flash_recovery_area目录下面有哪些大文件夹,那么可以将参数max-depth=2 ,如果你想对搜索出来的结果进行排序,那么可以借助于sort命令。如下所示
[root@getlnx01 u03]# du -h --max-depth=2 | sort -n
3.5G ./flash_recovery_area/EPPS
16K ./lost+found
29G ./flash_recovery_area/backup
33G ./flash_recovery_area
37G ./oradata
37G ./oradata/epps
70G .
[root@getlnx01 u03]# du -hm --max-depth=2 | sort -n
1 ./lost+found
3527 ./flash_recovery_area/EPPS
29544 ./flash_recovery_area/backup
33070 ./flash_recovery_area
37705 ./oradata
37705 ./oradata/epps
70775 .

[root@getlnx01 u03]# cd /
[root@getlnx01 /]# du -hm --max-depth=2 | sort -n
有时候搜索出来的结果太多了(譬如,我从根目录开始搜索),一直在刷屏,如果我只想查出最大的12个文件夹,怎么办呢?此时就要借助head命令来显示了
[root@getlnx01 /]# du -hm --max-depth=2 | sort -nr | head -12
407480 .
167880 ./u04
158685 ./u02/oradata
158685 ./u02
152118 ./u04/oradata
70775 ./u03
37705 ./u03/oradata
33070 ./u03/flash_recovery_area
5995 ./u01/app
5995 ./u01
3551 ./usr
1558 ./usr/share
[root@getlnx01 /]#

参考资料:
http://linuxandfriends.com/how-to-find-large-files-in-linux-using-command-line/
http://www.docin.com/p-563963500.html
当Linux 进行查找时,对某些目录的访问可能没有权限而无法进行访问,打印出很多错误消息
1、root目录文件内容
-bash-3.2$ ls
anaconda-ks.cfg bea Desktop lib wls1036_generic.jar
2、查找.log结尾的文件,
-bash-3.2$ find . -name "*.log"
find: ./.gconfd: æƒé™ä¸å¤Ÿ
find: ./.gnome2: æƒé™ä¸å¤Ÿ
find: ./.gnome2_private: æƒé™ä¸å¤Ÿ
find: ./.Trash: æƒé™ä¸å¤Ÿ
find: ./.java: æƒé™ä¸å¤Ÿ
find: ./.tuscany: æƒé™ä¸å¤Ÿ
find: ./.eggcups: æƒé™ä¸å¤Ÿ
find: ./.chewing: æƒé™ä¸å¤Ÿ
find: ./.mozilla/firefox: æƒé™ä¸å¤Ÿ
find: ./.scim: æƒé™ä¸å¤Ÿ
find: ./.metacity: æƒé™ä¸å¤Ÿ
find: ./.gconf: æƒé™ä¸å¤Ÿ
find: ./.nautilus/metafiles: æƒé™ä¸å¤Ÿ
这时系统语言使用中文反而有问题,很奇怪
-bash-3.2$ echo $LANG
zh_CN.UTF-8
临时改为英文
-bash-3.2$ export LANG="en_US.UTF-8"
-bash-3.2$ echo $LANG
en_US.UTF-8
然后再查找
-bash-3.2$ find . -name "*.log"
find: ./.gconfd: Permission denied
find: ./.gnome2: Permission denied
find: ./.gnome2_private: Permission denied
find: ./.Trash: Permission denied
find: ./.java: Permission denied
find: ./.tuscany: Permission denied
find: ./.eggcups: Permission denied
find: ./.chewing: Permission denied
find: ./.mozilla/firefox: Permission denied
find: ./.scim: Permission denied
find: ./.metacity: Permission denied
find: ./.gconf: Permission denied
find: ./.nautilus/metafiles: Permission denied
3、将错误输出到/dev/null装置上,错误信息消失
-bash-3.2$ find . -name "*.log" 2>/dev/null
-bash-3.2$ find . -name "*.cfg" 2>/dev/null
./anaconda-ks.cfg
http://blog.csdn.net/hongweigg/article/details/37818697
直接利用grep可以在当前目录及其所有子目录中查找文件吗:
# cd /root
# grep -rl "work" *
EXAMPLES
find /tmp -name core -type f -print | xargs /bin/rm -f Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines, single or double
quotes, or spaces. find /tmp -name core -type f -print0 | xargs - /bin/rm -f Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing single or double quotes,
spaces or newlines are correctly handled. The -name test comes before the -type test in order to avoid having to call stat() on every file. find . -type f -exec file '{}' \; Runs ‘file’ on every file in or below the current directory. Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script
punctuation. The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also. find / \( -perm - -fprintf /root/suid.txt '%#m %u %p\n' \) , \
\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \) Traverse the filesystem just once, listing setuid files and directories into /root/suid.txt and large files into /root/big.txt. find $HOME -mtime Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modi-
fied is divided by hours and any remainder is discarded. That means that to match -mtime , a file will have to have a modification in the past which is less than
hours ago. find /sbin /usr/sbin -executable \! -readable -print Search for files which are executable but not readable. find . -perm Search for files which have read and write permission for their owner, and group, but which other users can read but not write to. Files which meet these criteria but have
other permissions bits set (for example if someone can execute the file) will not be matched. find . -perm - Search for files which have read and write permission for their owner and group, and which other users can read, without regard to the presence of any extra permission bits
(for example the executable bit). This will match a file which has mode , for example. find . -perm / Search for files which are writable by somebody (their owner, or their group, or anybody else). find . -perm /
find . -perm /u+w,g+w
find . -perm /u=w,g=w All three of these commands do the same thing, but the first one uses the octal representation of the file mode, and the other two use the symbolic form. These commands all
search for files which are writable by either their owner or their group. The files don’t have to be writable by both the owner and group to be matched; either will do. find . -perm -
find . -perm -g+w,u+w Both these commands do the same thing; search for files which are writable by both their owner and their group. find . -perm - -perm / ! -perm /
find . -perm -a+r -perm /a+w ! -perm /a+x These two commands both search for files that are readable for everybody ( -perm - or -perm -a+r), have at least one write bit set ( -perm / or -perm /a+w) but are not
executable for anybody ( ! -perm / and ! -perm /a+x respectively). cd /source-dir
find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
cpio -pmd0 /dest-dir This command copies the contents of /source-dir to /dest-dir, but omits files and directories named .snapshot (and anything in them). It also omits files or directories
whose name ends in ~, but not their contents. The construct -prune -o \( ... -print0 \) is quite common. The idea here is that the expression before -prune matches things
which are to be pruned. However, the -prune action itself returns true, so the following -o ensures that the right hand side is evaluated only for those directories which
didn’t get pruned (the contents of the pruned directories are not even visited, so their contents are irrelevant). The expression on the right hand side of the -o is in
parentheses only for clarity. It emphasises that the -print0 action takes place only for things that didn’t have -prune applied to them. Because the default ‘and’ condi-
tion between tests binds more tightly than -o, this is the default anyway, but the parentheses help to show what is going on. find repo/ -exec test -d {}/.svn -o -d {}/.git -o -d {}/CVS ; \
-print -prune Given the following directory of projects and their associated SCM administrative directories, perform an efficient search for the projects’ roots: repo/project1/CVS
repo/gnu/project2/.svn
repo/gnu/project3/.svn
repo/gnu/project3/src/.svn
repo/project4/.git In this example, -prune prevents unnecessary descent into directories that have already been discovered (for example we do not search project3/src because we already found
project3/.svn), but ensures sibling directories (project2 and project3) are found. EXIT STATUS
find exits with status if all files are processed successfully, greater than if errors occur. This is deliberately a very broad description, but if the return value is
non-zero, you should not rely on the correctness of the results of find.
Linux如何查找大文件或目录总结及在全部目录中查找的更多相关文章
- Linux如何查找大文件或目录总结
在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件 ...
- Linux如何查找大文件或目录总结-1127
原帖地址:http://www.cnblogs.com/kerrycode/p/4391859.html 谢谢潇湘隐者,谢谢老大 在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在 ...
- Linux下查找大文件以及目录
转自:http://www.cnblogs.com/kerrycode/p/4391859.html 在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在 ...
- Linux 查看磁盘容量、查找大文件、查找大目录
Linux 查看磁盘容量.查找大文件.查找大目录 磁盘统计 查看磁盘使用情况 df -h 文件统计 查找/home 目录下大于800M的文件 find /home -type f -size +800 ...
- Linux下查找大文件,大目录的方法
查找大文件 //列举出当前目录所有大于800M的文件 find . -type f -size +800M 1 2 第一个方法只用到了一个命令find,它能够帮我们做一些文件查找的操作.它常用的参数有 ...
- 在linux/unix中查找大文件
在linux/unix中查找大文件,如查找大于100M文件的位置路径,查找等于10M文件的位置路径等等,下面就介绍几个实现快速查找的命令: 1. 查找指定目录下所有大于100M的文件,命令为 find ...
- Linux系统中如何查找大文件或文件夹的方法
在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件 ...
- centos 7下查找大文件、大目录和常见文件查找操作
根据园子 潇湘隐者的文章 <Linux如何查找大文件或目录总结>结合实际运维需要整理出常用命令 目标文件和目录查找主要使用 find 命令 结合 xargs (给命令传递参数的一个过滤器, ...
- LINUX下查找大文件及大的文件夹
原帖地址:https://www.cnblogs.com/iyoume2008/p/6105590.html 今天正好碰到这样的问题,在博客园中看到有以上地址的一篇文章,照着上面的操作解决了问题,但是 ...
随机推荐
- ExtJs4 笔记(13) Ext.menu.Menu 菜单、Ext.draw.Component 绘图、Ext.resizer.Resizer 大小变更
本篇讲解菜单.绘图.还有大小变更控件.菜单控件可以附加到各种其他控件中,比如按钮.工具栏等,甚至可以直接通过通过右键打开(模拟右键菜单):ext对绘图的支持可以让我们通过js来绘图:大小变更控件可以让 ...
- 中科同向备份软件Heartsone-backup(足足16个软件,可差异化备份虚拟机)
传统的备份方式我们应该尽量避免,除非他们支持和执行使用基于(API)的虚拟环境中的管理备份.中科同向备份软件Heartsone-backup V8.0(以下简称HBU)就是通过VADP提供的一系列管理 ...
- 从源代码角度分析ViewStub 疑问与原理
一.提出疑问 ViewStub比較简单.之前文章都提及到<Android 性能优化 三 布局优化ViewStub标签的使用>.可是在使用过程中有一个疑惑,究竟是ViewStub上设 ...
- Tokyo Tyrant(TTServer)系列(四)-tcrmgr远程管理与调试
Tokyo Tyrant(TTServer)系列-tcrmgr(远程管理与调试) tcrmgr是TokyoTyrant的管理工具,对ttserver进行管理与执行命令: 通过输入tcrmgr回车,能够 ...
- QT 4.2.2的安装(安装完还要再编译,注意设置Windows Path)
(安装篇)前奏: 提到C++的GUI Framework估计大多数人都会想到MFC.VCL,因为在十年前的COM时代,这两个大家伙几乎垄断了整个C++ windows平台上应用程序的开发市场, 但是最 ...
- 打印class文件的Java编译器内部的版本号
当改变了jdk版本时,在编译java时,会遇到Unsupported major.minor version错误.错误信息如下 : Unsupported major.minor version 50 ...
- Apache commons-net用法的一个示例
jar: commons-io-2.4.jarcommons-net-3.3.jar Code: import java.io.File; import java.io.FileInputStream ...
- 最短路知识点总结(Dijkstra,Floyd,SPFA,Bellman-Ford)
Dijkstra算法: 解决的问题: 带权重的有向图上单源最短路径问题.且权重都为非负值.如果采用的实现方法合适,Dijkstra运行时间要低于Bellman-Ford算法. 思路: 如果存在一条从i ...
- LCA 最近公共祖先 tarjan离线 总结 结合3个例题
在网上找了一些对tarjan算法解释较好的文章 并加入了自己的理解 LCA(Least Common Ancestor),顾名思义,是指在一棵树中,距离两个点最近的两者的公共节点.也就是说,在两个点通 ...
- U盘1G变8M解决的方法
本人曾有一个大小为1G的纽曼U盘,在一年前不幸中毒,格式化之后就仅仅剩8M了,然后再也无法正常格式化.尽管仅仅有8M,但总认为扔了可惜,于是乎,就一直束之高阁.昨天突然心血来潮,决定再试一试,纯粹是死 ...