![]() The locate command is incredibly fast compared to the find command.The two main advantages of using the locate command over using find command are as follows: The desired file is in the /etc/netplan directory. To do so, I will execute the following command: $ locate 50-cloud-init.yamlĪs expected, I got the result. Let us assume I wish to know the location of the 50-cloud-init.yaml file on my filesystem. The syntax is given below: locate FILE_NAME Once a database is generated, use the locate command by providing only a filename. The syntax 0 * * * * means to run the updatedb command every hour, every day. Then, add the following lines to the text file that opened. To edit the cron file for root, use the sudo crontab -e command. Since it gets tiresome manually generating the file database, you can create a cron job for root user to update the database hourly. When the files are constantly being created, modified, moved and moved, the database must also be updated. You must generate a database before the initial use of the locate command.Ī database is created and updated using the updatedb command, like so: sudo updatedb The locate command depends on a frequently updated database of your filesystem. The locate command can be installed by running the following apt command in your terminal: sudo apt install locate In cases like this, the locate command will surely come in handy when you do not know where a file is. Sometimes, when following a tutorial for "Installing and configuring XYZ on CentOS" will show a different location for the config files. The locate command is one of the handiest commands when you do not remember the location of a file. name "*.png"Įasy regex and a quick find! Finding files with locate command I will do so with the following command: $ find. Let us assume I wish to find all the png files. The -name and -iname options accept regular expression strings as inputs. $ du -sh ~/Downloads/mt_file_1ybi ~/Pictures/you_can-t_see_me ~/.config/nvim/mt_file_wun2 ~/Documents/work/learn-ubuntu/mt_file_2qxurĠ /home/pratham/Pictures/you_can-t_see_meĠ /home/pratham/.config/nvim/mt_file_wun2Ġ /home/pratham/Documents/work/learn-ubuntu/mt_file_2qxur Finding files with a particular extension This can be confirmed that they are empty using the du command. ![]() home/pratham/Documents/work/learn-ubuntu/mt_file_2qxurĪs you can see, the find command listed all matching results. Note that the -name (or -iname) option is not compulsory. To find those empty files, I will use the -empty flag and specify the type to be a file. I made a mistake in my bash script, and now it has created empty files all over my home directory. ) to search only in the current working directory. You may also substitute the tilde symbol ( ~) (for home directory) with the period symbol (. Here's the output: $ find ~ -name headshot.pngĪh! It was in the ~/Pictures/self directory. To find the photo, I would modify the find command's parameters as follows: find ~ -name headshot.png Let us assume I have a photo named 'headshot.png' located somewhere in my home directory. But, it does not even cover all the available options for the find command!įor better understanding, let us look at a few common examples of the find command. That is quite a list of available options.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |