Skip to main content
deleted 6 characters in body
Source Link
Arkadiusz Drabczyk
  • 26.6k
  • 5
  • 56
  • 70

You could of course use find but also less frequently used updatedb and locate.

First, we need to use updatedb to create a database of existing files that subsequent locate commands will use. Go to /home/me/files and do:

updatedb --require-visibility 0 -o locate.db -U .

Now we're ready to use locate in conjunction with Bash {a..b} syntax to search for a list of files. For example:

$ locate -d ./locate.db file_{112..125}.txt
./files_11/file_112.txt
./files_11/file_113.txt
./files_12/file_124.txt
./files_12/file_125.txt
$ locate -d ./locate.db file_{100..105}.txt
./files_10/file_100.txt
./files_10/file_102.txt
./files_10/file_105.txt
$ locate -d ./locate.db file_{103..106}.txt
./files_10/file_105.txt
./files_10/file_106.txt

To show only a number of found files pipe locate output through wc -l.

The advantage of this solution is that locate works very fast.

The disadvantage is that you will have re-create the database manually each time new files are added or renamed (or maybe use inotify) and that locate cannot replace found filenames with NUL bytes which will cause wc -l to return incorrect count in case of files that have a new line in their names.

You could of course use find but also less frequently used updatedb and locate.

First, we need to use updatedb to create a database of existing files that subsequent locate commands will use. Go to /home/me/files and do:

updatedb --require-visibility 0 -o locate.db -U .

Now we're ready to use locate in conjunction with Bash {a..b} syntax to search for a list of files. For example:

$ locate -d ./locate.db file_{112..125}.txt
./files_11/file_112.txt
./files_11/file_113.txt
./files_12/file_124.txt
./files_12/file_125.txt
$ locate -d ./locate.db file_{100..105}.txt
./files_10/file_100.txt
./files_10/file_102.txt
./files_10/file_105.txt
$ locate -d ./locate.db file_{103..106}.txt
./files_10/file_105.txt
./files_10/file_106.txt

To show only a number of found files pipe locate output through wc -l.

The advantage of this solution is that locate works very fast.

The disadvantage is that you will have re-create the database manually each time new files are added or renamed (or maybe use inotify) and that locate cannot replace found filenames with NUL bytes which will cause wc -l to return incorrect count in case of files that have a new line in their names.

You could of course use find but also less frequently used updatedb and locate.

First, we need to use updatedb to create a database of existing files that subsequent locate commands will use. Go to /home/me/files and do:

updatedb --require-visibility 0 -o locate.db -U .

Now we're ready to use locate in conjunction with Bash {a..b} syntax to search for a list of files. For example:

$ locate -d ./locate.db file_{112..125}.txt
./files_11/file_112.txt
./files_11/file_113.txt
./files_12/file_124.txt
./files_12/file_125.txt
$ locate -d ./locate.db file_{100..105}.txt
./files_10/file_100.txt
./files_10/file_102.txt
./files_10/file_105.txt
$ locate -d ./locate.db file_{103..106}.txt
./files_10/file_105.txt
./files_10/file_106.txt

To show only a number of found files pipe locate output through wc -l.

The advantage of this solution is that locate works very fast.

The disadvantage is that you will have re-create the database manually each time new files are added or renamed (or maybe use inotify) and that locate cannot replace found filenames with NUL which will cause wc -l to return incorrect count in case of files that have a new line in their names.

Source Link
Arkadiusz Drabczyk
  • 26.6k
  • 5
  • 56
  • 70

You could of course use find but also less frequently used updatedb and locate.

First, we need to use updatedb to create a database of existing files that subsequent locate commands will use. Go to /home/me/files and do:

updatedb --require-visibility 0 -o locate.db -U .

Now we're ready to use locate in conjunction with Bash {a..b} syntax to search for a list of files. For example:

$ locate -d ./locate.db file_{112..125}.txt
./files_11/file_112.txt
./files_11/file_113.txt
./files_12/file_124.txt
./files_12/file_125.txt
$ locate -d ./locate.db file_{100..105}.txt
./files_10/file_100.txt
./files_10/file_102.txt
./files_10/file_105.txt
$ locate -d ./locate.db file_{103..106}.txt
./files_10/file_105.txt
./files_10/file_106.txt

To show only a number of found files pipe locate output through wc -l.

The advantage of this solution is that locate works very fast.

The disadvantage is that you will have re-create the database manually each time new files are added or renamed (or maybe use inotify) and that locate cannot replace found filenames with NUL bytes which will cause wc -l to return incorrect count in case of files that have a new line in their names.