locate
and its variants tend to be a fast method.
# updatedb # run as root, possibly using sudo, e.g. sudo -b updatedb. If file is on the system for more than a day it should already be in the index and this can be skipped
$ locate -i book1
If locate is not available, you can use find
instead. It tend to be much slower, but also much more precise.
If you have a single partition: (run as root if your user might not have access to the file)
$ find / -xdev -iname 'book1*' -print # If the iname extension to find is available
$ find / -xdev -print | grep -F -i /book1 # if iname is not available
If you do not include -xdev
find
searches things on other partitions, like /proc
and /sys
, which tend to flood your screen with errors, especially if you are not root. (Errors can be hidden by appending 2> /dev/null
at the end of the find command (the comment should be removed))
If you have multiple partitions and you don't know on which one the file is on, you can get a list with lsblk
(on Linux-based OSes, parsing df
output is an option otherwise) and feed that into find: (root again if you don't know if you can access the file)
$ find $(lsblk -O MOUNTPOINT -n | grep -F /) -xdev -iname 'book1*' -print # GNU-based OSes
$ find $(df -P|awk '$1 ~ /^\/dev/ {print $NF}') -xdev | grep -F -i book1 # Non-GNU based OSes.
(This is a bit fragile if any of your mountpoints have spaces in) (df
parameters might need tuning. -P makes GNU df
give standard POSIX output. Other versions might have other parameters or need it left out. Read your man page)
The grep -F
excludes other things returned, like swap partitions.
In the non-GNU version, awk find devices with a mount starting with /dev
to get real file systems and then print the last field (the mountpoint) from the df
output.
This also assumes a bourne-like shell (ksh
and bash
should work. If you are using a csh
variant, start up a scriptable shell before you try this)
Book1
, and it is in a directory you can read, thenfind / -iname book1
will find it. Are you sure it is actuallyBook1
, and notBook1.xyz
?find
andlocate
.locate
is generous, and will find anything which matches, as long as it is in its database, which is normally updated daily.find
, in this case, is looking for a file glob, the sort of pattern you would use inls
. You probably meaniname '*book1*'
. Note that the pattern must be inside quotes to stop the shell from expanding it beforefind
gets to see it. Also notice thatfind
, like many *nix commands, is frustratingly silent when it is unsuccessful.