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.
Find a lost file [Solved]
7 posts
- Posts: 48
- Joined: Fri May 25, 2012 8:48 pm
- 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
- Posts: 343
- Joined: Mon Nov 21, 2011 9:29 pm
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
Find all the jpgs anywhere in the home directory and below
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
Find all the files modified more than 6 days ago
Plus find can do a lot more - including running a command against each of these files.
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.
- Posts: 265
- Joined: Tue Jan 10, 2012 11:05 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... 
- Posts: 343
- Joined: Mon Nov 21, 2011 9:29 pm
Thanks for this - have found the lost cat picture thanks - daughter happy
- Posts: 48
- Joined: Fri May 25, 2012 8:48 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).
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).
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.
- Posts: 265
- Joined: Tue Jan 10, 2012 11:05 am