#readwise # Linux Fundamentals - Find Files and Directories ![rw-book-cover](https://readwise-assets.s3.amazonaws.com/static/images/article2.74d541386bbf.png) ## Metadata - Author: [[Hack The Box]] - Full Title: Linux Fundamentals - URL: https://academy.hackthebox.com/module/18/section/81 ## Highlights ### Which One of the common tools is **`which`. This tool returns the path to the file or link that should be executed**. This allows us to determine if specific programs, like `cURL`, `netcat`, `wget`, `python`, `gcc`, are available on the operating system. --- ### Find **Another handy tool is find. Besides the function to find files and folders, this tool also contains the function to filter the results.** We can use filter parameters like the size of the file or the date. We can also specify if we only search for files or folders. --- Find filters: - `-type f` Hereby, we define the **type of the searched object**. In this case, 'f' stands for 'file'. - `-name *.conf` With `-name`, we indicate the **name of the file we are looking for**. The asterisk (`*`) stands for 'all' files with the '.conf' extension. - `-user root` This option filters all files whose **owner** is the root user. - `-size +20k` We can then filter all the located files and specify that we only want to see the **files that are larger than** 20 KiB. - `-newermt 2020-03-03` With this option, we set the date. Only files **newer than** the specified date will be presented. - `-exec ls -al {} \;` This option **executes the specified command**, using the curly brackets as placeholders **for each result**. The backslash escapes the next character from being interpreted by the shell because otherwise, the semicolon would terminate the command and not reach the redirection. - `2>/dev/null` This is a `STDERR` redirection to the 'null device', which we will come back to in the next section. This **redirection ensures that no errors are displayed** in the terminal. This redirection must not be an option of the 'find' command. --- ### Locate It will take much time to search through the whole system for our files and directories to perform many different searches. The command `locate` offers us a quicker way to search through the system. **In contrast to the `find` command, `locate` works with a local database** that contains all information about existing files and folders. We can update this database with the following command. `sudo updatedb` ---