Find all files with a specific name and show their file size
miku86
Posted on February 28, 2020
Problem
I updated my books worth reading and didn't know, if I already made some notes for any of them.
Therefore I need a command to search for a specific file name on my device and have a look at their file size. No need to search in the file content.
Solution (Linux)
Thinking about the steps:
- Find every file that has a specific pattern in its file name.
- See the file's size.
find [location] -iname "[pattern]" -exec [command] {} \;
Result
I search in my home folder (/home/miku86
) for any files containing pragmatic
(because of Pragmatic Programmer
).
So there are two files, a pdf and a md.
Explanation
find
: use the find tool
/home/miku86
: search in this directory
-iname "*pragmatic*"
: search for pragmatic
, can have some characters in front or behind pragmatic
, case doesn't matter
-exec du -sh {} \;
: run the tool to estimate the file size usage for every found file and return a summary in a human-readable format
Further Reading
Posted on February 28, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.