loading...

Find all files with a specific name and show their file size

miku86 profile image miku86 ・1 min read

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:

  1. Find every file that has a specific pattern in its file name.
  2. 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).

result of search and file size

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 by:

miku86 profile

miku86

@miku86

Mentor & Educator & Senior Web Developer - I help people to reach their (career) goals. => https://miku86.com/mentoring

Discussion

markdown guide