You are viewing the article How to Find Files in Linux at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.
This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.
The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.
This article has been viewed 2,478 times.
Without knowing how, finding files in Linux can be quite difficult. Here, the best practice is to use several different terminal commands. They are much more powerful than the simple search feature found on other operating systems, and when used well, you gain complete control over your files.
Steps
Use the “find” command
find -iname "filename"
- Use -iname instead of -name to ignore uppercase and lowercase elements in your query. The -name command takes this into account.
find / -iname "filename"
- You can start a search in a specific directory by replacing the / sign with a path, such as /home/pat .
- You can use . instead of / to perform a search only on the current directory and its subdirectories.
find /home/pat -iname "*.conf"
- The above command will return all .conf files in Pat’s user directory (and subdirectories).
- You can also use it to find all files that contain part of a filename. For example, in case there are a lot of wikiHow-related documents, you can find them all by typing "*wiki*" .
find /home/pat -iname "*.conf" | less
find / -type f -iname "filename"
find / -size +50M -iname "filename"
- The above command will return files of 50 MB or more. You can use the + or - characters to find files that are larger or smaller. When these characters are not used, the search will return a file that is exactly the same size as the requested size
- You can filter by bytes ( c ), kilobytes ( k ), megabytes ( M ), gigabytes ( G ), or 512-byte blocks ( b ). Note that this section is case sensitive.
find /image_travel_type -type f -size +200k -not -iname "*2015*"
- The above command will look for files located in the “travel_pictures” folder that are larger than 200 kilobytes and have a name that doesn’t contain “2015”.
find / -user pat -iname "filename"
find / -group users -iname "filename"
find / -perm 777 -iname "filename"
- The above examples query with certain users, groups, and access rights in turn. You can also omit the filename to get any files of the type stated. Such as find / -perm 777 will return every file with 777 (unlimited) access. [3] X Research Sources
find . -type f -perm 777 -exec chmod 755 {} ;
- The above command combination will find all files with 777 access in the current directory (and subdirectories) and then use the chmod command to change that access to 755.
Use the “locate” command
- Type sudo apt-get update and press ↵ Enter .
- You can install on Debian and Ubuntu by: Type sudo apt-get install mlocate and press ↵ Enter . If locate is already installed, the following message will appear: mlocate is already the newest version .
- In Linux Arch, use the pacman package manager: pacman -Syu mlocate
- With Gentoo, use emerge: emerge mlocate
- Type sudo updatedb and press ↵ Enter .
locate -i "*.jpg"
- The above command looks for .jpg files on the entire system. The wildcard * plays the same role as in the find command.
- Like the find command, -i does not consider uppercase and lowercase elements in your query.
locate -n 20 -i "*.jpg"
- Only the first 20 search results that match the query will be displayed.
- You can also use | send results to less for easier browsing.
Find files containing certain text
grep -r -i "search query" /path/to/directory/
- -r sets a “recursive” search, which means that any files containing the keyword in the current directory and all its subdirectories will be searched.
- -i indicates that the above query is case insensitive. If you want to be case sensitive, omit the -i operator.
grep -r -i "search query" /path/to/directory/ | cut -d: -f1
grep -r -i "search query" /path/to/directory/ 2 >/dev/null
This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.
The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.
This article has been viewed 2,478 times.
Without knowing how, finding files in Linux can be quite difficult. Here, the best practice is to use several different terminal commands. They are much more powerful than the simple search feature found on other operating systems, and when used well, you gain complete control over your files.
Thank you for reading this post How to Find Files in Linux at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.
Related Search: