Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find file in Linux then report the size of file searched [duplicate]

Tags:

linux

find

size

How can i search for file in Linux then report the size of those file i have found ?

For example, i want to search file named core.txt in my home directory in Linux, core.txt also appear on some sub-directory under my home dir. Then after found core.txt, the command should also show me file size of those files have founded.

Cheers

like image 244
Henry Vu Avatar asked Aug 19 '13 11:08

Henry Vu


People also ask

How would you find out if two files are exactly the same?

Probably the easiest way to compare two files is to use the diff command. The output will show you the differences between the two files. The < and > signs indicate whether the extra lines are in the first (<) or second (>) file provided as arguments.

How can you use the command ls to find out about the size of file?

If you strictly want ls command to show the file sizes in MB or KB you can use the '--block-size=SIZE' option. It scale file sizes by SIZE before printing them; e.g., --block-size=M prints sizes in units of 1,048,576 bytes.


1 Answers

We can use find command to find the file and du -sh to find out its size.

We will execute du -sh on found files. So final command would be

find ~ -name "core.txt" -exec du -sh {} \;
or
find ~ -name "core.txt" | xargs du -sh

In 2nd command xargs will not handle spaces in file name. So We can tell exact delimiter to xargs to handle spaces in file name.

find ~ -name "core.txt" | xargs -d '\n' du -sh

like image 110
Alok Avatar answered Sep 19 '22 22:09

Alok