linux how to find a file by name?

Published on Aug. 22, 2023, 12:14 p.m.

To find a file by name in Linux

To find a file by name in Linux, you can use the find command with the -name option followed by the name of the file you are searching for . For example, to search for a file named “example.txt” in the current directory and its subdirectories, you could use the following command:

find . -name example.txt

This will return a list of all files with the name “example.txt” that are located under the current directory. If you want to limit the search to a specific directory, you can replace the “.” with the path to that directory.

linux how to find a file by size

To find a file by size in Linux, you can use the find command with the -size option followed by the size of the file you are searching for . For example, to search for a file that is exactly 1MB in size in the current directory and its subdirectories, you could use the following command:

find . -size 1M

Note that the size should be specified in blocks, where 1K is 1024 bytes, 1M is 1024K, and so on. You can also use operators such as + and - to find files that are larger or smaller than a certain size. For example, to find all files that are larger than 10MB, you could use the following command:

find . -size +10M

This will return a list of all files that are larger than 10MB in size located under the current directory. If you want to limit the search to a specific directory, you can replace the “.” with the path to that directory.

linux how to find a file by type

To find files by type in Linux, you can use the find command with the -type option followed by the type of the file you are searching for. Here are some examples:

To find all text files with the .txt extension in the current directory and its subdirectories, you can use the following command:

find . -type f -name “*.txt”

2 . To find all PDF files with the .pdf extension in the /home directory and its subdirectories, you can use the following command:

find /home -type f -name “*.pdf”

3 . To find all executable files in the current directory and its subdirectories, you can use the following command:

find . -type f -executable

NOTE: A file’s type is not determined by its extension, but by its content. However, some of the examples above are based on the assumption that files with certain extensions belong to certain categories. It is also possible to use the file command to determine the type of a file, as it identifies the file type based on its content rather than extension.

Tags:

related content