![]() Linux find file name containing string manual#For a full list it is recommended to check the manual pages by typing man grep.Īn example of using grep to find a certain text can be found below: grep "database" configuration.php Grep is a very powerful tool and accepts various command line arguments. The command you should be using, in this case, is grep. You can also search for a given text in the content of the files as well. Or if you want to filter only files modified in the last 2 days, you would need to use: find. If you would like to list only directories and leave all files out of the result: find. If you are uncertain about the file name or would like to match a part of the name, you can use a wildcard pattern: find. Find is a very powerful tool and accepts various arguments allowing you to specify the exact search term (i.e search by name, by type or even by modified time).įor example, to search for a file called myFile.txt under the current folder (and all subfolders), you would need to use the following command: find. In order to search for a file location, you can use the find command. SSH provides two different commands, which can be used to accomplish this. temp from the /var/log/, you would use: find /var/log/ -name `*.In some cases, you would need to find the location of a given file or to search for a certain text in all files under a directory. It is always a good idea to print the matched files before using the -delete option.įor example, to delete all files ending with. To delete all matching files, append the -delete option to the end of the match expression.Įnsure you are using this option only when you are confident that the result matches the files you want to delete. The common example would be to recursively change the website file permissions to 644 and directory permissions to 755 using the chmodĬommand: find /var/www/my_website -type d -exec chmod 0755 \ Find and Delete Files # To search for files based on their type, use the -type option and one of the following descriptors to specify the file type:įor instance, to find all directories in the current working directory Sometimes you might need to search for specific file types such as regular files, directories, or symlinks. For example, to find all files that don’t end in *.log.gz you would use: find /var/log/nginx -type f -not -name '*.log.gz' Find Files by Type # To find all files that don’t match the regex *.log.gz you can use the -not option. It is important to mention that you must either quote the pattern or escape the asterisk * symbol with backslash \ so that it doesn’t get interpreted by the shell when you use the wildcard character. log.gz inside the /var/log/nginx directory, you would type: find /var/log/nginx -type f -name '*.log.gz' For example, to find all files ending with. Searching for files by extension is the same as searching for files by name. The command above will match “Document.pdf”, “DOCUMENT.pdf”. To run a case-insensitive search, change the -name option with -iname: find /home/linuxize -type f -iname document.pdf ![]() To find a file by its name, use the -name option followed by the name of the file you are searching for.įor example, to search for a file named document.pdf in the /home/linuxize directory, you would use the following command: find /home/linuxize -type f -name document.pdf ![]() js (JavaScript files).įinding files by name is probably the most common use of the find command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |