1

I am fairly new to linux and I am currently trying to run the following command,

find ~ -name apt.no

I'm looking for apt.no within another directory listed as montrose-files.

There is no response from the shell and it just creates a new line. Could anyone please explain to me why this does not produce even a result?

bbcharlieca@myvm:~$ find ~ -name apt.no
bbcharlieca@myvm:~$ █

enter image description here

6
  • 1
    Why should it produce a result? Do you have a file named apt.no somewhere in your home directory?
    – muru
    Oct 27 at 8:08
  • This means apt.no is not found.
    – Stewart
    Oct 27 at 8:08
  • I'm looking for apt.no within another directory listed as "montrose-files" Oct 27 at 8:12
  • Welcome to the site. What do you mean if you say the directory is "listed as montrose-files". Do you mean there is a subdirectory inside your home directory called montrose-files where this file is to be found? If not, where is that directory?
    – AdminBee
    Oct 27 at 8:23
  • That is correct. montrose-files is a subdirectory and I need to find a file within this subdirectory with the name as apt. no. Oct 27 at 8:25
5

Your command find ~ -name apt.no looks for a file or directory* called apt.no in your $HOME directory and within any directories underneath it. (The ~ represents your own home directory.)

Unless montrose-files is within your own home directory it won't be searched, and the target file won't be found. For example, if montrose-files is under another path, you'd need to specify that path:

find /path/to/montrose-files -name 'apt.no' -print

Confusingly, if you have previously created a symbolic link to montrose-files in your home directory that also won't be searched, as find by default does not follow symbolic links. You can address that in one of two ways:

find ~ -follow -name 'apt.no' -print
find ~/montrose-files/ -name 'apt.no' -print

In the first approach we tell find to follow symbolic links. With some versions of find this can be a poor approach, because if a symbolic link points around in a loop you could end up traversing the structure several times.

In the second approach we force the symbolic link to resolve to a real directory target by appending a trailing slash.

Finally, notice that in all cases I've quoted the filename for which I'm searching. In your simple case it won't make any difference, but when you start using wildcards to match unknown parts of filenames (for example, apt.*) you should use the single quotes to ensure the wildcards are not processed by the shell before find can get hold of them). It's a good idea to get in the habit of quoting arguments.


* Technically, it will match any item at all, but you're unlikely to have pipes, sockets, or device nodes in your home directory

2
  • 1
    "any item at all, and not just files or directories" – By definition they are all files, it's just some are not regular files. Oct 27 at 15:03
  • @KamilMaciorowski I'll revert my edit
    – roaima
    Oct 27 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.