![]() 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. -writable: Only files that the current user can write to. ![]() -readable: Only files that the current user can read.Use c, k, M and G for specifying units in bytes, kibibytes, mebibytes and gibibytes, respectively. Use d, f and l for a directory, file and a symbolic link, respectively. -mmin n: File was last modified n number of minutes ago.-amin n: File was last accessed n number of minutes ago.-iname: Same as -name, but case insensitive.-name: Specify a case-sensitive filename/regex for the file to search for.You can provide multiple options to the find command, so let us look at them. ![]() The find command is an amazing command line utility that searches for a given filename/regex pattern in a specified directory. There is more to the find command, so keep reading if you want to know more! find command The 'FILE_NAME' parameter can be replaced by the exact name of a file or by a regex.įor example, if I want to search for a file that is named 'resolution-for-year-2022.txt', only in my home directory, I would issue the following command: find ~ -name resolution-for-year-2022.txt Replace 'LOCATION' with a directory in which you wish to search. path '*/a_*/*.Ubuntu 18.04 Review of New Features find LOCATION -name FILE_NAME If the a_* directories can themselves be at any depth below the parent directory, you can either use find -path or **: find. Other shells such as plain sh don't have **. In zsh, this pattern is enabled by default. In bash, you need to enable this pattern with shopt -s globstar first. In ksh93, you need to enable this pattern with set -o globstar first. a_* -name '*.csv'Īlternatively, instead of using find, you can use the ** wildcard to search in subdirectories recursively. qux/a_foo/wibble.csv), then call find and tell it to search the a_* directories. If the files can be in subdirectories below the a_* directories (e.g./a_foo/wibble.csv or. If the files are in subdirectories of the parent directory (e.g./a_foo/wibble.csv), you don't need find: the find command is only useful to search directory trees recursively. ![]() This does not filter on the directories traversed to reach the file. name 'a_*.csv' matches files whose name starts with a_ and ends with. name 'a_*' -a -name '*.csv' or equivalently find. To match names that start with a_, use -name 'a_*'. The pattern * matches names that end with one of the characters. The pattern * matches names that start with either of the characters a or _.
0 Comments
Leave a Reply. |