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
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.
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.
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 {} \;
orfind ~ -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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With