![]() Lastly, always remain connected to Tecmint. In the same way as before, do not forget to send us your feedback or questions via the comment section below. For 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. $ man findĪs a last remark, the find command is more reliable and efficient for searching files ( or directories) in a Linux system when weighed against the locate command. To find a file by its name, use the -name option followed by the name of the file you are searching for. which finds all files that have in their path (regardless of case thats what -i means) 'debug' and 'log' (In case you dont know, the. I often have scenarios like this and so I do searches like: locate -i 'debug' grep -i 'log'. To find more interesting and advanced usage information, read the man pages of find and locate. will check a database that lists all the files indexed on your PC. Next, the option -iname will enable a case insensitive search: $ sudo find. type d -name "pkg"įurthermore, if you wish to list the directory in a long listing format, employ the action switch -ls: $ sudo find. You can prevent find from searching for other file types except directories by using -type flag to specify the type of file (in the command below d means directory) as follows: $ sudo find. ![]() If you encounter “ Permission denied” errors, use sudo command like so: $ sudo find. To search for the same directory (pkg) above, within the current working directory, run the following command, where the -name flag reads the expression which in this case is the directory basename. Therefore, to deal with this issue, use find by following the simplified syntax below: $ find starting-point options $ locate -basename '\pkg'Īs you can see from the command output above, locate will search beginning from the root (/) directory, that is why other directories with the same name are matched. Where \ is a globbing character, it disables the implicit replacement of pkg by *pkg*. Note: In the command below, the option -basename or -b tells locate to only match the file (directory) basename (which is exactly pkg) but not the path ( /path/to/pkg). To demonstrate the disadvantage of locate, let us assume we are searching for a directory named pkg in the current working directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |