py, we need to find that file.Īs we all know there are several methods to find the files, but in this tutorial, we will learn to find the files with certain extensions using the endswith() function, comprehension method, and the several methods present in the os module and glob module. But when we need to do certain operations on a file with a specific file extension like. Thanks.We know how to find files and do operations on that file using the file handling methods. If you liked this post, on how to search files on the Linux terminal, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. I hope you have now enough understanding of how to search a file in your Linux system using the terminal. In the above post, we explained how to search for a file using the find and locate command in Linux. If you want to count the number of search keywords is matched, use the -c option. The locate command is much faster than other tools because it uses a database file to perform the search instead of searching your local hard disks.įor example, to search a file named rc.local, run the following command: locate rc.local The locate is another command-line tool that allows you to search for a file in Linux. You can use the find command with the -perm option to search a file based on their permissions.įor example, to search all files inside the /etc directory with permissions of exactly 764, run the following command: find /etc -perm 764 Search Files Using the Locate Command find /home -name "*.php" -mtime +10 Search Files by Permissions You can use the + symbol if you want to find all files that have been modified more than 10 days. The find command can search a file based on its modification, access, and change time.įor example, to search PHP files inside /home directory that have been modified in the last 10 days, run the following command: find /home -name "*.php" -mtime 10 Use the following options to specify the size in KB, MB, GB, and more. You can also specify the size range during the file search.įor example, to search all files between 2 MB and 10 MB, run the following command: find /home -type f -size +2M -size 10M You can use the + symbol before the size if you want to search files greater than 2 MB: find /home -type f +size -2M You can search a file based on their size using the -size option followed by size criteria.įor example, to search all files less than 2 MB inside /home directory, run the following command: find /home -type f -size -2M This command will search all PNG files located inside /opt directory. png in the /opt directory, run the following command: find /opt -type f -name '*.png' mp4, etc.įor example, to search all files with extensions. You can use the asterisk * symbol before any extension to find all files that end with specific extensions including. You can use the following option if you want to search for a specific file type: If you want to ignore the case during the file search, use the -i option as shown below: find /etc -type f -iname file1.txt You can use the find command with -name option followed by the file name that you want to search.įor example, to search a file named file1.txt in the /etc directory, run the following command: find /etc -type f -name file1.txt The find command allows you to search a specific file by its name. Once all the packages are up-to-date, restart your server to apply the configuration changes. Once you are logged in, you should update all of your packages to their latest available versions. Change IP_Address and Port_Number according to your server’s IP address and SSH port number. Remember to replace root with your username if you are not using the root user. You can do that by entering this command: ssh _Address -p Port_Number A Linux VPS with root access enabled, or a user with sudo privileges.įirst, we’re going to need to log into our server using SSH.In this post, we will show you how to search files on the Linux terminal using the find and locate commands. This way you can search files and directories based on their size, date, type, and ownership. The find command allows you to search for files and directories based on an expression. The find and locate are the most popular command-line tool used to search files and directories in Linux. The simple and easiest way is to use the Linux terminal to search or locate files. There are several ways to search files and directories in Linux. Especially if you are working on the server operating system without a Desktop interface. Finding files and directories in Linux is a very difficult task compared to Windows operating system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |