Modification Time: The last time the contents of the file were modified.Ĭhange Time: The last time the file’s inode metadata was changed. To find files in the /usr directory that are more than 700 Megabytes, you could use this command:įor every file on the system, Linux stores time data about access times, modification times, and change times.Īccess Time: The last time a file was read or written to. To find files that are less than 50 bytes, you can use this syntax instead: ![]() To illustrate, the following command will find every file in the /usr directory that is exactly 50 bytes: Here are some commonly used size suffixes: To do this, you must add a special suffix to the end of a numerical size value to indicate whether you’re counting the size in terms of bytes, megabytes, gigabytes, or another size. You can filter files by their size using the -size parameter. Filtering by Time and Sizeįind gives you a variety of ways to filter results by size and time. ![]() This example will find any files whose names match either query_1 or query_2. You can also return results that satisfy either expression by separating them with the -or option: You can combine expressions like this by separating them with the -and option, but as this example shows the -and is implied any time you include two expressions. For any file to be returned, it must satisfy both of these expressions. Note: The previous example combines two find query expressions namely, -type f and -name "*.conf". This command specifically only searches for devices within the /dev directory, the directory where device files are typically mounted in Linux systems: Here are some of the descriptors you can use to specify the type of file:įor instance, if you wanted to find all of the character devices on your system, you could issue this command: You can specify the type of files you want to find with the -type parameter. Note that if you use !, you must escape the character with a backslash ( \) so that the shell does not try to interpret it before find can act. If you want to find all files that don’t adhere to a specific pattern, you can invert the search with -not:Īlternatively, you can invert the search using an exclamation point ( !), like this: To find a file by name but ignore the case of the query, use the -iname option: This will be case sensitive, meaning a search for query is different from a search for Query. To find a file by name with the find command, you would use the following syntax: The most obvious way of searching for files is by their name. However, these example commands should still work and be useful for understanding how these programs work. This is to be expected, since you’re searching for files within directories that regular users typically don’t have access to. Because of this, if you’re logged into the terminal as a non- root user, some of the example commands may include Permission denied in their output. ![]() Note: To illustrate how the find and locate commands work, the example commands in this guide search for files stored under /, or the root directory. ![]() Doing so will set you up with a secure server environment - including a non- root user with sudo privileges and a firewall configured with UFW - which you can use to build your Linux skills. If you plan to use a remote server to follow this guide, we encourage you to first complete our Initial Server Setup guide. Note that this tutorial was validated using a Linux server running Ubuntu 20.04, but the examples given should work on a computer running any version of any Linux distribution. This can either be a virtual private server which you’ve connected to with SSH or your local machine. To follow along with this guide, you will need access to a computer running a Linux-based operating system. It will also briefly cover the locate command, which can be used to search for files in a different way. This will help you search for files on your system using a variety of filters and parameters. This guide will cover how to use the aptly named find command. One problem users run into when first learning how to work with Linux is how to find the files they are looking for.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |