# How To Find Files And Folders In Linux System

**URL:** <https://onehack.st/t/how-to-find-files-and-folders-in-linux-system/217501>\
**Category:** Tutorials & Methods\
**Tags:** tips-tricks, file-management\
**Created:** [March 28, 2022, 9:26am UTC](https://onehack.st/t/how-to-find-files-and-folders-in-linux-system/217501 "2022-03-28T09:26:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PlayBoy83](https://onehack.st/user_avatar/onehack.st/playboy83/32/164314_2.png) [@PlayBoy83](https://onehack.st/u/PlayBoy83)\
**Post date:** [March 28, 2022, 9:26am UTC](https://onehack.st/t/how-to-find-files-and-folders-in-linux-system/217501/1 "2022-03-28T09:26:02Z")

</div>

This command technically walks through directories tree on the file system. It can be used to find directory and file matched with RegEx patterns.

General syntax for `find` command:

`$ ` `find` `[OPTIONS] [PATH...] [EXPRESSION]`

##### Search for specific file in a directory

`find` `.` `/ExampleDir` `-name example.txt`

With the `-name` parameter, this command will attempt to search for a `example.txt` within the `ExampleDir` directory; and if found, will return path to the file.

 ![image](https://onehack.st/uploads/default/original/3X/b/5/b518bba286467e6a4491ca054be2f137693bbdec.jpeg)

##### Find and list files of same extension

`find` `.` `/dirname` `-name *.txt`

This command will search, within the `ExampleDir` directory, all files ending with the extension `.txt`. If found, each result will be returned in a new line.

 ![image](https://onehack.st/uploads/default/original/3X/1/5/15c9231d9b84dec44aca26b7fe0c6dbb76085d56.jpeg)

##### Find and list empty files and empty sub-directories

`find` `.` `/ExampleDir` `-empty`

This command, with the `-empty` parameter, will find and list all _empty files_ and _empty sub-folders_ inside the `ExampleDir` folder.

Definition of _empty file_ being 0 bytes filesize, and _empty folder_ being no files or files with 0 bytes.

 ![image](https://onehack.st/uploads/default/original/3X/8/7/87f795a2b213c5e68b16ae11d7a689c11fbb533e.jpeg)

##### Find and list files that contain specific text

`find` `.` `/ExampleDir` `-` `type` `f -name ` `"*.txt"` `-` `exec` `grep` `'Example'` `{} \;`

This command searches for the word/string “ **Example** ” inside files with the extension `.txt` inside `ExampleDir` directory.

 ![image](https://onehack.st/uploads/default/original/3X/a/0/a00811eed15e7c7019fac8d9ddaa2690eb8e7c6a.jpeg)

##### Find and list files and sub-directories own by specific user

`find` `.` `/ExampleDir` `-user ubuntu`

This command, with the `-user` parameter, will find files and sub-directories owned by `Ubuntu` user in `ExampleDir` directory. If found, the filename(s) will be returned.

In the following sample `ls -l` result:

`-rw-rw-r-- 1 newone ubuntu 20 Jan 27 06:24 example.txt`

`newone` represents **group** name, and `ubuntu` is the **user**.

 ![image](https://onehack.st/uploads/default/original/3X/5/1/514758ea598b48fb97fd16cde080c535a85fa3dc.jpeg)

##### Find and list files and sub-directories own by specific group

`find` `.` `/ExampleDir` `-group ubuntu`

This command, with the `-group` paramter, will find all files and sub-directories owned by `Ubuntu` group in `ExampleDir` directory. If found, the filename(s) will be returned.

 ![image](https://onehack.st/uploads/default/original/3X/c/0/c09d1da7ba0cb03b5545c7a8f905e7fa622a7d87.jpeg)

**Happy learning!**
