DavidMS
Posts: 132
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Find a lost file [Solved]

Mon Jun 04, 2012 7:53 am

Can some help me with an 'understandable' (for a very new Linux user) description of how to find a file I have put somewhere on my SD card.

I suspect I should be using the "find" command but to be frank having read the help text I a basically more confused than when I started. Essentially I just want to perform a search for '*.jpg' files across the whole SD card so I can locate the files location.

Thanks
Post edit Gert: changed the subject text so it is easier to find for others.
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

spurious
Posts: 343
Joined: Mon Nov 21, 2011 9:29 pm

Re: Lost file

Mon Jun 04, 2012 7:56 am

Code: Select all

apt-get install mlocate
once installed

Code: Select all

updatedb
then you can look for files

Code: Select all

locate myfile.jpg

andyl
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am

Re: Lost file

Mon Jun 04, 2012 9:00 am

The problem with locate is that you are likely to need to run updatedb every time. I guess most people aren't keeping their raspis on all day in a server fashion.

It is better to just use find.

Find all the jpgs anywhere on the system

Code: Select all

 find / -name *.jpg
Find all the jpgs anywhere in the home directory and below

Code: Select all

 find /home -name *.jpg
If you are one of those people who sometimes uses capitals then use -iname

Find all the files owned by the user andyl in /home and below

Code: Select all

find /home -user andyl
Find all the files modified more than 6 days ago

Code: Select all

 find / -mtime +6
Plus find can do a lot more - including running a command against each of these files.

spurious
Posts: 343
Joined: Mon Nov 21, 2011 9:29 pm

Re: Lost file

Mon Jun 04, 2012 9:03 am

I agree find is more powerful, but I use nether very often and can never remember the syntax for find.. plus I'm lazy... ;)

DavidMS
Posts: 132
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Lost file

Mon Jun 04, 2012 9:07 am

Thanks for this - have found the lost cat picture thanks - daughter happy
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

User avatar
Gert van Loo
Posts: 2409
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Lost file

Sun Jun 17, 2012 9:16 pm

I thought you always have to put quotes around the wild cards:
find / -name "*.jpg" -print
(I know , the -print is no longer required. It is an old left-over from my Unix days.
But I have typed that command soooo many time it just comes out automatically).

andyl
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am

Re: Lost file

Sun Jun 17, 2012 9:51 pm

Gert van Loo wrote:I thought you always have to put quotes around the wild cards:
find / -name "*.jpg" -print
(I know , the -print is no longer required. It is an old left-over from my Unix days.
But I have typed that command soooo many time it just comes out automatically).
Well to be absolutely correct then yes you are right - you will need to escape the glob pattern.

However if (and only if) the current directory doesn't contain anything matching the glob pattern then the entire pattern gets passed to find.

I guess I should really have added the quotes (or escaping) in my previous answer.

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 6 guests