How do I find ‘foo’ on an external USB drive?

by Greg   Last Updated October 12, 2019 04:01 AM

Somewhere on my USB drive is a lost file with the string foo. I want to recover this using terminal on my MacBook Pro. Using sudo as super user I am able to list expected directories with a few batch files, e.g.

MyMacBook-Pro-2:~ gs$ sudo -s ls -l /volumes/Seagate*
Password: xxxxx

total 2144
[email protected]  1 gs        wheel      20484 12 Oct 10:55 .DS_Store
d--x--x--x   6 root      wheel        272 12 Oct 10:40 .DocumentRevisions-V100
drwx------   4 _unknown  _unknown     170 20 Feb  2014 .Spotlight-V100
[email protected]  3 root      wheel        102 29 Aug  2014 .TemporaryItems
[email protected]  3 root      wheel        102 22 Aug 17:35 .Trashes
[email protected]  1 root      wheel     938428 28 Aug  2013 .VolumeIcon.icns
[email protected]  1 _unknown  _unknown       0 24 Nov  2015 .com.apple.timemachine.donotpresent
-rw-r--r--   1 root      wheel       1493 12 Oct 13:16 .disk_label
-rw-r--r--   1 root      wheel       5981 12 Oct 13:16 .disk_label_2x
drwx------   2 _unknown  _unknown    2686 12 Oct 13:15 .fseventsd
drwxrwxrwx   4 gs        wheel        170 20 Feb  2014 2013 10
drwxrwxrwx  13 gs        wheel        612 23 Aug  2014 2014 02
drwxr-xr-x   4 gs        wheel        170 28 May 08:34 2014 06
drwxr-xr-x  16 gs        wheel        612 22 Aug 17:35 2014 08
[email protected]  7 root      wheel        238  7 Jul  2018 Backups.backupdb
drwxr-xr-x   6 gs        wheel        374 13 Jun 08:15 DT 2019
drwxr-xr-x   5 _unknown  _unknown     306 28 May 08:29 Items Mac 2009
[email protected]  2 _unknown  _unknown     136 30 Jul  2016 Lame_Library_v3
[email protected]  1 root      wheel     115716 30 Sep  2013 tmbootpicker.efi

But when I try using grep to identify any file with the string foo, terminal complains then goes catatonic, e.g.

MyMacBook-Pro:~ gs$ sudo -s grep -R “foo” /volumes/Seagate*
grep: /volumes/Seagate Backup Plus Drive/.Spotlight-V100: Operation not permitted

It’s worth noting I recently upgraded to macOS Catalina 10.15. This answer might be relevant but this answer also makes me cautious.

So before I go down a rabbit hole or do something really stupid could someone please tell me what I am doing wrong?



Answers 1


Run locate foo from the Terminal

The locate command was designed for situations like this. It’s commonly used in Linux as well as macOS. Just type this from the command line:

locate foo

It will then return a list of files and full file paths with the word “foo” in it. You can also combine it with grep to narrow things down if you know the path you are looking for. So in your example do something like this:

locate foo | grep Seagate

And if you can’t seem to find it, just force update the locate database and try those commands again:

sudo /usr/libexec/locate.updatedb
JakeGould
JakeGould
October 12, 2019 03:53 AM

Related Questions


how to get the tip: man git | grep

Updated January 01, 2018 17:01 PM

cat and grep with a huge file - Broken pipe

Updated April 13, 2018 09:01 AM


grep -Ef saying 'invalid character range'. Again

Updated April 01, 2018 17:01 PM