How Linux finds large files or directories summary-1127

Source: Internet
Author: User

Original address: http://www.cnblogs.com/kerrycode/p/4391859.html Thank you, Xiaoxiang hidden, thank you boss

In the Linux system, how to search for some relatively large files? Now I've sorted out how to find large files or folders on a Linux system.

1 How to find large files

In fact, there are times when you need to know what big data files are in the/u01/app/oracle/oradata/prod/, such as file sizes larger than 100M or 1G (thresholds vary depending on the case). So how do you search for these big files?

1.1 Search for files larger than the specified size in the specified directory

For example I want to search for files over 500M in size/u01/app/oracle/oradata/prod/

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m

/u01/app/oracle/oradata/prod/sysaux01.dbf

/u01/app/oracle/oradata/prod/system01.dbf

As shown in the command above, we can only see the file name of files over 500M, but the information about the file (for example, file size, file attributes) is unknown, can you show some of the file attributes or information in more detail, of course, you can

1.2 Search for files that exceed a specified size in the specified directory (show file user, Group)

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m-print0 | xargs-0 ls–l

-RW-R-----1 Oracle oinstall 545267712 11-19 23:20/u01/app/oracle/oradata/prod/sysaux01.dbf

-RW-R-----1 Oracle oinstall 744497152 11-19 23:20/u01/app/oracle/oradata/prod/system01.dbf

1.3 Search for files that exceed a specified size in the specified directory (show file details size)

When we only need to find files larger than 500M size and display the exact size of the found file, you can use the following command

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m-print0 | xargs-0 du–h

521m/u01/app/oracle/oradata/prod/sysaux01.dbf

711m/u01/app/oracle/oradata/prod/system01.dbf

1.4 Searches for files larger than the specified size in the specified directory (sorted by size, with discrepancies in results)

If you also need to sort the results by file size, you can use the following command

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m-print0 | xargs-0 Du-h | Sort-nr

711m/u01/app/oracle/oradata/prod/system01.dbf

521m/u01/app/oracle/oradata/prod/sysaux01.dbf

1.5 Search for files larger than the specified size in the specified directory (sort by size, strict)

However, as shown above, sometimes the order is not exactly the same size, this is due to the parameter H of the du command, you can use the unified use of MB to display, so that can solve the problem

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m-print0 | xargs-0 Du-hm | Sort–n

521/u01/app/oracle/oradata/prod/sysaux01.dbf

711/u01/app/oracle/oradata/prod/system01.dbf

1.6 Search for files that exceed a specified size in the specified directory (the owner, group, and file size (in m) of the file are displayed in detail.)

[Email protected] ~]$ find/u01/app/oracle/oradata/prod/-type f-size +500m-print0 | xargs-0 ls-lh | sort-nr< /c1>

RW-R-----1 Oracle oinstall 711M 11-20 09:06/u01/app/oracle/oradata/prod/system01.dbf
-RW-R-----1 Oracle oinstall 521M 11-20 09:06/u01/app/oracle/oradata/prod/sysaux01.dbf

2 How to find Linux under the large directory

For example, sometimes disk space alarm, and you usually neglect to manage, monitor the growth of files, then I need to quickly understand which directories become larger, then we can use du command to help us solve this problem

2.1 Find the large directory under the specified directory

[Email protected] ~]$ du-h/u01--max-depth=1

5.7g/u01/app

16k/u01/lost+found

5.7g/u01

[Email protected] ~]$ du-h/u01--max-depth=2

2.6m/u01/app/orainventory

5.7g/u01/app/oracle

5.7g/u01/app

16k/u01/lost+found

5.7g/u01

[Email protected] ~]$ du-h/u01--max-depth=3

16k/u01/app/orainventory/contentsxml

8.0k/u01/app/orainventory/oui

2.6m/u01/app/orainventory/logs

2.6m/u01/app/orainventory

1.7g/u01/app/oracle/oradata

4.0k/u01/app/oracle/checkpoints

4.0g/u01/app/oracle/product

716k/u01/app/oracle/admin

232k/u01/app/oracle/cfgtoollogs

6.8m/u01/app/oracle/diag

5.7g/u01/app/oracle

5.7g/u01/app

16k/u01/lost+found

5.7g/u01

If you want to know which large folders are under the/u01 directory, you can max-depth=2 the parameters, and if you want to sort the results of the search, you can use the sort command. As shown below

[Email protected] ~]$ du-h/u01--max-depth=2 |sort-n

2.6m/u01/app/orainventory

5.7g/u01

5.7g/u01/app

5.7g/u01/app/oracle

16k/u01/lost+found

[Email protected] ~]$ du-h/u01--max-depth=3 |sort-n

1.7g/u01/app/oracle/oradata

2.6m/u01/app/orainventory

2.6m/u01/app/orainventory/logs

4.0g/u01/app/oracle/product

4.0k/u01/app/oracle/checkpoints

5.7g/u01

5.7g/u01/app

5.7g/u01/app/oracle

6.8m/u01/app/oracle/diag

8.0k/u01/app/orainventory/oui

16k/u01/app/orainventory/contentsxml

16k/u01/lost+found

232k/u01/app/oracle/cfgtoollogs

716k/u01/app/oracle/admin

Sometimes search out too many results (for example, I start from the root directory search), has been in the brush screen, if I only want to find out the largest 5 folders, how to do? At this point, the Head command will be used to display

[Email protected] ~]$ du-hm/u01/app/oracle/--max-depth=2 | Sort-nr | Head-5

5741/u01/app/oracle/

4057/u01/app/oracle/product/11.2.0

4057/u01/app/oracle/product

1677/u01/app/oracle/oradata/prod

1677/u01/app/oracle/oradata

3. Self-organized (practical) 3.1 Find large directories in the system (from large to small sort, take top 5)

[Email protected] ~]# DU-HM/--max-depth=1 | Sort-nr | Head-5


9456/
5744/u01
2964/usr
260/dev
234/lib

3.2 Finding large files in the above table of contents (/U01)

[Email protected] ~]# find/u01/app/oracle/-type f-size +500m-print0 | xargs-0 LS-LH | Sort-nr

-RW-R-----1 Oracle oinstall 711M 11-20 09:41/u01/app/oracle/oradata/prod/system01.dbf
-RW-R-----1 Oracle oinstall 521M 11-20 09:36/u01/app/oracle/oradata/prod/sysaux01.dbf

Haha, quite practical.

How Linux finds large files or directories summary-1127

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.