Command line command

I’m a little embarrassed to ask this one but, I just can’t seem to figure it out.

I’m looking a way to display the location of a file from the command line. For those familiar with DOS, I want to do a

DIR SOMEFILE /S

where DIR is a less able version of ls

I want to be able to go above the level of the file tree from where I know the file resides (root as last resort) and issue the command and see the file name and path, not matter where in the file tree it resides.

I’ve tried find and can’t get the results I want. I’ve tried ls and still can’t see a file I know is there.

Dolphin seems to work but I don’t get the same rock solid belief in a graphical tool as I do from the command line. In other words, if Dolphin says the file doesn’t exist, I don’t quite believe it. If I get a file not found from the proper command line command, I know it’s not there.

Bart

Try locate

its in findutils-locate and there’s an app for KDE called kio-locate that does the same as command line but organises it a bit better


find . -name SOMEFILE

in short find is the command you are looking for.


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.0 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.0 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.0 | GMA4500

That is indeed what I was looking for. I looked at the man page again and found the -name option. I’m going to have to spend some time with it, it makes references to things that I don’t have down and need to know before I understand it. I am still however, confused by the . I’m guessing it refers to the starting place for the find command to start. It seems to be in the wrong place.

Thanks so much!

swerdna, after I installed findutils package I now have that command available! Thanks!

The first argument to find is the directory from which to start the
search, the . is just for the current directory, search is recursive,
you can of course explicitly specify any other directory in a relative
or absolute path.

locate is faster than find, it searches a database (which is
created/updated with updatedb as root, usually this update runs as a
chron job once a day for example).


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.0 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.0 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.0 | GMA4500

So, it is as I thought.

locate is faster than find, it searches a database (which is
created/updated with updatedb as root, usually this update runs as a
chron job once a day for example).

Ah! Then the find command is exactly what I wanted. It depends on nothing other than the fact that the file exists. Great!

Again, Thanks!

Bart

On 2013-04-22 01:16, Martin Helm wrote:
> locate is faster than find, it searches a database (which is
> created/updated with updatedb as root, usually this update runs as a
> chron job once a day for example).

Not as root, but as ‘nobody’, which is a user in the system.

It is configured in the file “/etc/sysconfig/locate”. You can select
there the user it runs under, and what directories it does not search.
And a few more things.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-04-22 01:46, montana suse user wrote:

>> locate is faster than find, it searches a database (which is
>> created/updated with updatedb as root, usually this update runs as a
>> chron job once a day for example).
>
> Ah! Then the find command is exactly what I wanted. It depends on
> nothing other than the fact that the file exists. Great!

It makes sense to use ‘locate’ first, because if the file existed
yesterday, it finds it immediately. If you use the option “-e”, it also
verifies that the file is still there.

Then, if locate fails, use find, which can take a long time to complete,
depending on how big is the space you tell it to search.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

I don’t think “locate” is installed by default. It is not on my system, and I never de-selected nor uninstalled it.

On 2013-04-22 04:16, nrickert wrote:
>
> robin_listas;2549790 Wrote:
>> It makes sense to use ‘locate’ first, because …
> I don’t think “locate” is installed by default. It is not on my
> system, and I never de-selected nor uninstalled it.

True, and there is a reason for it: when it creates its database file
once a day, it can tax the system a lot, because it has to search the
entire filesystem. This is disk intensive and on some computers it slows
them unacceptably. There were complains about this and it was no longer
installed by default.

In any case, it is better to create the index once a day, than every
time you want to find a file :slight_smile:

Other tools that also index content are even more taxing, though.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

Wouldn’t that depend on whether “every time you want to find a file” is less than once per day?

Personally, I never found “locate” to be useful. While “find” is useful, I don’t use it very often. Sometime “which” does all of the finding that I need, and at other times I know where to look, so “ls” in the appropriate directory is sufficient.

On 04/22/2013 05:16 AM, nrickert wrote:
> Personally, I never found “locate” to be useful. While “find” is
> useful, I don’t use it very often. Sometime “which” does all of the
> finding that I need, and at other times I know where to look, so “ls” in
> the appropriate directory is sufficient.

hmmmm…matter of taste i reckon…because it is blazing fast i
almost always use ‘locate’ first…unless i am sure i seek an
executable in my path (in that case i use ‘which’)…

to me, ‘find’ is excruciatingly slow.

and, if i know enough about where to look to use ls, then i just use
mc and visually scan…

the ‘trick’ is to schedule the daily db build during a time which is
convenient: a default install of ‘locate’ will result in a daily
build at the cron appointed ‘daily’ time…which by default is in
openSUSE (iirc) 2 AM local time…

but, if your machine is shutoff at 2 AM it will build within 15
minutes of booting, along with everything else

i just change that so that locate (and all daily crons) run at a time
i expect to not be using the machine each day (during ‘lunchtime’ for
example) and thereby get blazing fast locate with no machine slowdown
while i’m sitting at it.

ymmv


dd

Am 22.04.2013 02:43, schrieb Carlos E. R.:
> Not as root, but as ‘nobody’, which is a user in the system.
Sorry, you are right
/etc/cron.daily/suse-updatedb is as nobody.


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.0 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.2 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.0 | GMA4500

On 04/22/2013 11:20 AM, Martin Helm wrote:
> Am 22.04.2013 02:43, schrieb Carlos E. R.:
>> Not as root, but as ‘nobody’, which is a user in the system.
> Sorry, you are right
> /etc/cron.daily/suse-updatedb is as nobody.
>

well…it is a matter of opinion…my opinion is that the
likelihood of making much on my machine more secure by using ‘nobody’
is not very high…so i let root do it.


dd
openSUSE®, the “German Engineered Automobile” of operating systems!

On 2013-04-22 09:20, dd wrote:

> the ‘trick’ is to schedule the daily db build during a time which is
> convenient: a default install of ‘locate’ will result in a daily build
> at the cron appointed ‘daily’ time…which by default is in openSUSE
> (iirc) 2 AM local time…
>
> but, if your machine is shutoff at 2 AM it will build within 15 minutes
> of booting, along with everything else

It is controlled by the file “/etc/sysconfig/cron”:


> # At which time cron.daily should start. Default is 15 minutes after booting
> # the system. Due to the fact that cron script runs only every 15 minutes,
> # it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time
> # you set.
>
> DAILY_TIME="22:10"
> # Maximum days not running when using a fixed time set in DAILY_TIME.
> # 0 to skip this. This is for users who will power off their system.
> #
> # There is a fixed max. of 14 days set,  if you want to override this
> # change MAX_NOT_RUN_FORCE in /usr/lib/cron/run-crons
>
> MAX_NOT_RUN="2"


In my configuration, it will attempt to run after 22:10 (jobs are
checked every 15 minutes), but if it fails to run for two days then it
will run at the first chance.

> i just change that so that locate (and all daily crons) run at a time i
> expect to not be using the machine each day (during ‘lunchtime’ for
> example) and thereby get blazing fast locate with no machine slowdown
> while i’m sitting at it.

Exactly :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-04-22 11:31, dd wrote:
> On 04/22/2013 11:20 AM, Martin Helm wrote:
>> Am 22.04.2013 02:43, schrieb Carlos E. R.:
>>> Not as root, but as ‘nobody’, which is a user in the system.
>> Sorry, you are right
>> /etc/cron.daily/suse-updatedb is as nobody.
>>
>
> well…it is a matter of opinion…my opinion is that the likelihood
> of making much on my machine more secure by using ‘nobody’ is not very
> high…so i let root do it.

Yes, of course, you can choose the user. With root every file is found.
Me, I use my own local user.

The default config means it will not search /home, so that other users
may not learn the contents of each other user’s home. If I had other
‘real’ users, I would set it up to nobody again.

Of course, a user could run updatedb on his own adjusted to search his
own files only. I think, I have not tried myself.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)