1/7/2024 0 Comments Linux find file![]() Here’s the command to find file greater than 10Mb in /home folder $ find /home -size +10MB You can easily search file by size in Linux using -size option. Here’s the command to find all directories in /home $ find /home -type d Here’s the command to list all symbolic links in /home folder $ find /home -type l Here’s the command to list all empty files in /home directory using -empty option $ find /home -type f -empty Here’s the command to find regular files in /home directory $ find /home -type f Since there are different file types in Linux, you can use -type option to find files by their type. For example, here’s the find command to search all pdf files in /home directory $ find /home -name *.pdfīonus Read : How to Install Zip File in Linux We can use the above-mentioned pattern matching to find files by extension. So it will match 123unix.txt, unix.pdf and also UNIX.TXT. The above command will do a case sensitive match for “unix” pattern. If we use -iname option instead of -name option, it will do a case insensitive match. So it will match 123unix.txt, unix.pdf but not UNIX.TXT You can use wildcard characters like * to specify search patterns. The following command searches for any file that contains the string unix in its filename. Here’s the command to find files by name, using wildcard characters. The above command will match unix.txt, UNIX.TXT but not 123unix.txt. The following command searches for unix.txt file at /home folder $ find /home -iname unix.txt Here’s the command to find files by name, with a case-insensitive exact match, using -iname option. The above command will match only linux.txt and no other filename The following command searches exactly for linux.txt file at /home folder $ find /home -name linux.txt Here’s the command to find files by name, with a case-sensitive exact match, using -name option. We will look at some commonly used examples for find command. So it won’t match files like “DOCUMENT.TXT” or “word-document.txt”īonus Read : How to Create Zip File in Linux Please note, find command is case-sensitive and does an exact match by default. If you don’t specify the starting path, find command will start searching in your present working directory.įor example, here’s the command to find “document.txt” file in /home/ubuntu folder $ find /home/ubuntu/ -name document.txt In the above command, you need to specify the starting path where find command needs to start searching file, options as per your requirement, and the search expression to look for in file attributes. $ find starting_path options search_expression We will use the find command to search a file in Linux. Here are the steps to search a file in Linux. You can use it to search a file in Ubuntu, CentOS, Redhat, Fedora, and other Linux systems. Note that you can also use another file for a reference timestamp instead of explicitly specifying the timestamp, in which case the ‘t’ from the argument can be skipped.Many times, you may need to search a file in Unix or to find a file in directory in Linux. We have learned how to use the '-newerXY' the argument of command find to search for files based on timestamp. Verify with ‘stat’ if the timestamps of both files are indeed greater than the specified time. Let’s try this on a folder with few files and only two files having accessed, modified and status changed after a specified time. Here, the format of the timestamp should be: ‘YYYY-MM-DD HH:MM:SS’. To generalize, the command to be run looks like this: find -newert ‘’ creation time of a file is not maintained in Unix based file systems Thus in the argument '-newerXY', we can have X as a, c, or m, respectively for last access, last status change, and last modification times, and Y as t, so that we can have the next argument to be a timestamp string. Now, to find files based on the timestamp, we use the argument '-newerXY' of find from the man page. For example for a file with the name ‘ stat‘, run: $ stat tmpįind Stat Timestamps Find Files Based on Timestamp Find File Timestamps in Linuxįirst of all, we can run the ‘ stat‘ command in Linux to get all these timestamps for a file. Let’s see how to use find to search for files based on each of these timestamps. ![]() Last Status Change Time (i.e., when metadata of the file like permissions are changed).In Linux (and all Unix based file systems) there are 3 timestamps maintained for every file: One such parameter is the timestamp of the file. ![]() These parameters can be the filename, size, type of file, etc. The find command in Linux is used to search for files and folders based on different parameters.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |