Author Topic: Locating a file [ RESOLVED ]  (Read 909 times)

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Locating a file [ RESOLVED ]
« on: January 19, 2011, 08:56:40 AM »
I have long accepted that to locate a file on a partition, that partition's file system must be mounted in the OS at some point or other.

Is it possible to locate the partition a file resides on, without mounting that partition?

Usually people want to know the application the question is supposed to address .....  well there isn't one ;D
This is just something that occurred to me today.
I do not know how to do this.

So I will try to imaging a reason for having this function .......  lets say .......

I have an external USB connected HDD with many partitions. I know I saved the file on one of them but do not recall which partition. I even remember the path to the file ......  but not the partition.

So can I search for   <any partition>/pclos/myfile.txt    with some tool in PCLOS without mounting each of the twenty or more partitions on that external HDD?

I suspect there is a way .....  I do not know what it is .......  

I await enlightenment  ;D


regards.
« Last Edit: April 09, 2011, 10:11:55 AM by Just19 »

Offline Joble

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6804
  • USA - Mountain Time
Re: Locating a file
« Reply #1 on: January 19, 2011, 10:17:12 AM »
locate might work if at some point you did an updatedb while that partition was mounted.

I expect you know that already though.
Search First.
Forum Rules
Hero means I talk a lot, nothing more, nothing less!
Have an Awesome Day!
Healthy System

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Locating a file
« Reply #2 on: January 19, 2011, 01:18:19 PM »
locate might work if at some point you did an updatedb while that partition was mounted.

I expect you know that already though.

Actually I had not thought of that  :)  Thanks  ;D

It is a rare day I do not updatedb so the info would not last long I guess.

This has been on my mind today .......  and there 'must' be some command that will do this ......  as I just remembered Grub will do it, so it is indeed possible!

I put /pclos/myfile.txt on a partition of a removable drive ....  safely removed it, and later reinserted it without mounting any partitions.
Launched Grub and yes it found the file ........

Code: [Select]
grub> find /pclos/myfile.txt
 (hd2,4)

grub>

So apparently it is possible .....  at least from Grub ......  but what is the equivalent command in Linux?

regards.

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6381
  • I'm going South
Re: Locating a file
« Reply #3 on: January 19, 2011, 02:12:10 PM »
locate might work if at some point you did an updatedb while that partition was mounted.

I expect you know that already though.

Actually I had not thought of that  :)  Thanks  ;D

I think this is your best bet. But note that in the file  /etc/updatedb.conf some directories and filesystems are excluded from the search, and among those that are excluded by default you'll find both /mnt and /media. So you might want to edit /etc/updatedb.conf.

Quote
It is a rare day I do not updatedb so the info would not last long I guess.

Wherever the info is stored it will be overwritten sooner or later.

Quote
This has been on my mind today .......  and there 'must' be some command that will do this ......  as I just remembered Grub will do it, so it is indeed possible!

I put /pclos/myfile.txt on a partition of a removable drive ....  safely removed it, and later reinserted it without mounting any partitions.
Launched Grub and yes it found the file ........

Code: [Select]
grub> find /pclos/myfile.txt
 (hd2,4)

grub>

So apparently it is possible .....  at least from Grub ......  but what is the equivalent command in Linux?

regards.
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Locating a file
« Reply #4 on: March 13, 2011, 08:07:48 AM »
I am back knocking on this door again ......  trying to find an equivalent command in Bash to the "find" command in Grub, which searches unmounted partitions for the specified file.

any further ideas welcome, thanks

Offline marcin82

  • Full Member
  • ***
  • Posts: 129
  • Jest wirek - jest impreza ;]
Re: Locating a file
« Reply #5 on: March 27, 2011, 05:06:47 AM »
Without mounting usb-HDD-drive it's rather impossible.
First, edit file:
Code: [Select]
/etc/updatedb.confIn the line "PRUNEPATHS= ... " delete path '/media'. Then type:
Code: [Select]
#updatedbnext ...
Code: [Select]
locate myfile.txtAt the end ... restore the file /etc/updatedb.conf to it's original format.
marcin'82

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Locating a file
« Reply #6 on: March 27, 2011, 06:03:09 AM »
Code: [Select]
locate myfile.txt
....  but locate does not work on non-mounted media, so that is of no use.

Seems the only means is to use Grub .......  ?

It does work and is an acceptable 'workaround' I guess.

Thanks for the reply.

regards.

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6381
  • I'm going South
Re: Locating a file
« Reply #7 on: March 27, 2011, 06:23:39 AM »
Code: [Select]
locate myfile.txt
....  but locate does not work on non-mounted media, so that is of no use.

Well, locate doesn't work on either unmounted or mounted media that weren't mounted when updatedb was last run. Nor does it work on directories that are excluded from the search in /etc/updatedb.conf. But the media's present state doesn't matter.

In other words: locate reports on the system as it used to be, not as it is.

So you may be correct when you write:
Quote
Seems the only means is to use Grub .......  ?

It does work and is an acceptable 'workaround' I guess.

Thanks for the reply.

regards.
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D