1

Still a newbie. Using a clean machine, purchased from System 76 with Ubuntu 14.04 LTS installed. Got it mid-May of 2014.

Why can't I find files in the current and its subdirectories?

I've tried ls, find , locate, which, and whereis. Even tree | grep which will find them but won't tell me where they are.

Example: In my /home directory I have some *.t files. In some of my directories below home, I have some *.t files. I am having a hard time trying to find them all with one CLI command. Any ideas?

5
  • 2
    Is find . -type f -name "*.t" not giving the expected output?
    – g_p
    Jan 10, 2015 at 19:35
  • 2
    Can you add the actual commands you used and also show a list of a location where those files are with the given search argument! I'll expand the answer if needed ;)
    – Rinzwind
    Jan 10, 2015 at 19:50
  • 1
    which is used to see the absolute path to a program's executable. like which firefox or which bash Jan 10, 2015 at 21:35
  • Thank you g_p. I hadn't realized I needed 'find' with 'type' and 'name'. This does the trick. Thank you again!
    – ReyKev
    Jan 10, 2015 at 23:27
  • Thank you LittleByBlue. I see I still have a lot to learn. :)
    – ReyKev
    Jan 10, 2015 at 23:29

1 Answer 1

3

The problem with locate might be an outdated database. locate uses a database to show you result and that database is not updated real-time. So new files are not added to it when created. They will get added when the database is updated.

sudo updatedb

updates it for you manually but this is also done daily by cron on a default Ubuntu. locate is not real-time but very fast. locate accepts wildcards.

locate *.jpg 
/discworld/Downloads/Forbidden-Oasis.jpg
/discworld/Downloads/The-Exalted-Plains.jpg
/discworld/Downloads/The-Fallow-Mire.jpg
/discworld/Downloads/The-Hinterlands.jpg
/discworld/Downloads/The-Storm-Coast.jpg
/discworld/Downloads/The-Western-Approach.jpg

and

locate .t 

should give you results if the database is up to date and there are any files ending with ".t". You can filter the results by adding a | grep Western (the example I show above would show 1 result; the last one would be shown) if you get too many results.


find is real-time and as a result it is slower than locate. find will show an error if you search location you are not allowed to search. The command in comments by @g_p is correct and searches from the current location files ending in ".t".

find . -type f -name "*.t"

which is not intended to find files but to find commands so is the wrong tool. whereis is also not intended to find files but you can use to find the binary, source, and manual page files for a command.

3
  • Thank you Rinzwind! Locate .t gives me way too many results of all sorts. Locate ".t" gives me exactly what I was looking for. Thank you very much Rinzwind!
    – ReyKev
    Jan 10, 2015 at 23:28
  • 1
    @ReyKev you can filter with "| grep {filter}" ;)
    – Rinzwind
    Jan 11, 2015 at 7:39
  • Thank you again Rinzwind. I will work with that. Appreciated!
    – ReyKev
    Jan 11, 2015 at 17:39

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.