Author Topic: Using the ls Command  (Read 3438 times)

Martin109

  • Vectorite
  • ***
  • Posts: 290
Using the ls Command
« on: May 04, 2008, 10:02:42 am »
Can I use ls to track down files with a specific extension on my system, regardless of directory?  That is, is there a switch to override current directory and search all?
Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

uelsk8s

  • Administrator
  • Vectorian
  • *****
  • Posts: 2504
Re: Using the ls Command
« Reply #1 on: May 04, 2008, 10:46:57 am »
not really.
you can use ls to list the contents of any dir
ls alone lists content of current folder
ls /   will list contents of root(base) folder
ls /usr/bin lists the contents of /usr/bin

I use find "find / -name *.tlz" for instance or "find / -name *.iso|grep 5.9"
there are lots of commands here: http://vectorlinux.osuosl.org/Uelsk8s/test/

HTH,
Uelsk8s

kidd

  • Packager
  • Vectorian
  • ****
  • Posts: 682
Re: Using the ls Command
« Reply #2 on: May 04, 2008, 10:51:02 am »
list files recursively , ls provides -R flag, but somehow it's not working here if I want to narrow the search by extension.

Alternatives:

Using zsh globbing allows you to do something like ls **/*pl  meaning list all pl files under the current directory.  it's a zsh feature, so **/*pl will be expanded before calling ls.  That means you can rm **/*pl and much more.

Otherwise you can use find command:

Code: [Select]
find . -name "*pl"
Probably there are more ways to do it, I just provided a couple.

HTH.

Martin109

  • Vectorite
  • ***
  • Posts: 290
Re: Using the ls Command
« Reply #3 on: May 04, 2008, 11:04:42 am »
Thanks for that!
Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

saulgoode

  • Vectorite
  • ***
  • Posts: 340
Re: Using the ls Command
« Reply #4 on: May 04, 2008, 11:25:38 am »
'locate' is probably the fastest way to search your filesystem because it uses a database wherein are stored all the filenames. However, the database is only updated on a daily basis so 'locate' will not find files that have been added since the last database update. The argument passed to locate can appear anywhere in the filename (example: "locate .ogg"); if you want to use more complex wildcards then use the "-r" switch along with a regular expression.
A complex system that works is invariably found to have evolved from a simple system that works.

Martin109

  • Vectorite
  • ***
  • Posts: 290
Re: Using the ls Command
« Reply #5 on: May 04, 2008, 12:17:35 pm »
I'm trying to find .ppd files relating to my printer.

Executing 'locate .ppd' gives the following error message:

locate: warning: database /var/lib/slocate/slocate.db' is more than 8 days old
locate: fatal error: set_path_head: path_head len <=0 : 0
Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

kidd

  • Packager
  • Vectorian
  • ****
  • Posts: 682
Re: Using the ls Command
« Reply #6 on: May 04, 2008, 12:21:53 pm »
run updatedb as root.

you could add a cron job that rebuilds the database.

Martin109

  • Vectorite
  • ***
  • Posts: 290
Re: Using the ls Command
« Reply #7 on: May 04, 2008, 12:33:41 pm »
I must be making progress - I just discovered the updatedb command myself! :D
Compaq Armada E500, i686 Pentium III, 512Mb RAM, 3.2 Gb HDD, running Vector Linux 5.9 Standard

Fujitsu Lifebook, i686 Pentium M, 1.7 GHz, 1028Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

Compaq Evo, i686 Pentium M, 1.4 GHz, 512Mb RAM, 40 Gb HDD, running Vector Linux 6.0 Standard

katsushiro

  • Member
  • *
  • Posts: 3
Re: Using the ls Command
« Reply #8 on: May 06, 2008, 01:34:47 pm »
ls can find files just fine....in the directory you're already in....in conjunction with the grep command.  ;)

syntax would be
ls -a |grep *.ppd


this will show you any file in the diretory ending in .ppd.

toothandnail

  • Tester
  • Vectorian
  • ****
  • Posts: 2527
Re: Using the ls Command
« Reply #9 on: May 08, 2008, 12:43:05 pm »
ls can find files just fine....in the directory you're already in....in conjunction with the grep command.  ;)

syntax would be
ls -a |grep *.ppd


this will show you any file in the diretory ending in .ppd.

Not to nit pick (well, not too much, anyway  ;D ) but the -a flag is not likely to be necessary for a printer definition file. And ls will happily use wildcards, so a simple

Code: [Select]
ls *.ppd
would do exactly the same thing. Trouble is, it is limited to the current directory, so it doesn't help much for searching.

paul.

kidd

  • Packager
  • Vectorian
  • ****
  • Posts: 682
Re: Using the ls Command
« Reply #10 on: May 08, 2008, 01:04:40 pm »
Tired of looking for files, and then go to the directory to open that file, I started writing a perl wrapper to locate, that updates a locate database on a given directory ($HOME usually), asks you for an extension and a pattern, and searches for files.  If there is more than one file matching the pattern, it'll show you a menu to choose one. If it's the first time you ask for a given extension, it'll ask you for a command to open that kind of files.  It'll never ask for it again.  It uses perl and ratmen (available through vpackager).

It can search in remote machines, and do some fancy stuff with your files, and execute apps, but hey, try it and see...

It's still a work on progress, but I find it pretty useful.

http://code.google.com/p/ratfinder/ ---> up to date code (svn) and wiki

http://raimonster.googlepages.com/rat-finder ----> some (old) screenshots, and some random ideas of how should it evolve.

./rat-finder --man will show you some documentation, but if you want to use it, PM me and I'll tell you how to get it working (docs have to be improved)

It's like Beagle for hackers and/or low-end boxes.

HTH
« Last Edit: May 08, 2008, 01:08:48 pm by kidd »