Sponsored Content
Top Forums Shell Programming and Scripting ksh - Checking directory trees containing wild cards Post 303004243 by drl on Thursday 28th of September 2017 11:18:37 AM
Old 09-28-2017
Hi.

Not knowing what your environment is, many systems utilize locate:
Code:
NAME
       locate - find files by name

SYNOPSIS
       locate [OPTION]... PATTERN...

DESCRIPTION
       locate  reads  one or more databases prepared by updatedb(8) and writes
       file names matching at least one of the PATTERNs  to  standard  output,
       one per line.
 ...

which might be faster than probing the filesystem, since the updatedb database already contains the results of such a probe.

Available on Linux, Solaris, macOS.

See man locate for details.

For example, finding a file xxx-yyy-zzz (edited ~ for actual home):
Code:
$ time locate xxx-yyy-zzz
~/try/grep/match-nomatch-to-separate-files/xxx-yyy-zzz

real    0m0.095s
user    0m0.088s
sys     0m0.004s

$ time find / -type f -name xxx-yyy-zzz 2>/dev/null
~/try/grep/match-nomatch-to-separate-files/xxx-yyy-zzz

real    0m7.649s
user    0m0.896s
sys     0m2.672s

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to put a space between wild cards..

how do you put a space in a wild card thing.. example "LastAnalysisT.*${MONTH}.*${DAY}.*20${YEAR}" I need to make it something like "LastAnalysisT.*${MONTH}<I need a space here>.*${DAY}.*20${YEAR}" So it would be something like: LastAnalyst*May 24*2004 Where * just means I dont... (1 Reply)
Discussion started by: LordJezo
1 Replies

2. Shell Programming and Scripting

Best way to diff two huge directory trees

Hi I have a job that will be running nightly incremental backsup of a large directory tree. I did the initial backup, now I want to write a script to verify that all the files were transferred correctly. I did something like this which works in principle on small trees: diff -r -q... (6 Replies)
Discussion started by: same1290
6 Replies

3. Linux

problem of wild cards matching..$ls t[A-Z] output

hi all, i have created a file by name tt and while listing the file ,i used the command $ls t from which i was expecting not to list tt file output coz of uppercase range, But it listed that file tt file and am not able understand the reason. kindly help. NOTE OS :Red Hat Enterprise... (0 Replies)
Discussion started by: rajp_8007
0 Replies

4. UNIX for Advanced & Expert Users

How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files. find . -type d gives the perfect list. When I tried tar, it won't work for me because it tars all the files. find . -type d | xargs tar -cvf a.tar So i tried rsync. On my own test box, the... (4 Replies)
Discussion started by: fld2007
4 Replies

5. Shell Programming and Scripting

Checking directory permissions on UNIX directory

Hi, How do i check if I have read/write/execute rights on a UNIX directory? What I'm doing is checking read access on the files but i also want to check if user has rights on the direcory in whcih these files are present. if then...... And I check if the directory exists by using... (6 Replies)
Discussion started by: chetancrsp18
6 Replies

6. UNIX for Dummies Questions & Answers

How to use wild cards to find files beginning with upper and lower case

Im trying to use wild cards to find files that start with either an upper or lower case letter e.g. list files that beginning with b or B, i also want to sort them by the time they were last modified. e.g latest file created first. At the moment i have the following code that ls -d... (3 Replies)
Discussion started by: parker4001
3 Replies

7. Shell Programming and Scripting

How to copy very large directory trees

I have constant trouble with XCOPY/s for multi-gigabyte transfers. I need a utility like XCOPY/S that remembers where it left off if I reboot. Is there such a utility? How about a free utility (free as in free beer)? How about an md5sum sanity check too? I posted the above query in another... (3 Replies)
Discussion started by: siegfried
3 Replies

8. Shell Programming and Scripting

PERL - getting last file using wild cards

Hi experts, I am new to perl. I am trying to get the last file from set of files. Using the below code; but getting error pls help Files: -rw-r--r-- 1 abc abc 12584 Mar 18 16:22 /abc/def/ghi/xyz.HOSTNAME.2016.03.18.16.21.69709-6 -rw-r--r-- 1 abc abc 12623 Mar 18 16:25... (4 Replies)
Discussion started by: sdosanjh
4 Replies

9. UNIX for Advanced & Expert Users

Find wild card directory and its files of some extensions

I want to use Find command to find directories that have certain name and them find files in that directory having only some extensions. So far, I have come up with this command to list directories with wild card name and list ALL the files in that directory. find . -type d -name prog\* -print... (11 Replies)
Discussion started by: sssccc
11 Replies
locate(1)                                                     General Commands Manual                                                    locate(1)

NAME
locate - find files by name SYNOPSIS
locate [OPTION]... PATTERN... DESCRIPTION
locate reads one or more databases prepared by updatedb(8) and writes file names matching at least one of the PATTERNs to standard output, one per line. If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were *PATTERN*. By default, locate does not check whether files found in database still exist (but it does require all parent directories to exist if the database was built with --require-visibility no). locate can never report files created after the most recent update of the relevant data- base. EXIT STATUS
locate exits with status 0 if any match was found or if locate was invoked with one of the --limit 0, --help, --statistics or --version options. If no match was found or a fatal error was encountered, locate exits with status 1. Errors encountered while reading a database are not fatal, search continues in other specified databases, if any. OPTIONS
-A, --all Print only entries that match all PATTERNs instead of requiring only one of them to match. -b, --basename Match only the base name against the specified patterns. This is the opposite of --wholename. -c, --count Instead of writing file names on standard output, write the number of matching entries only. -d, --database DBPATH Replace the default database with DBPATH. DBPATH is a :-separated list of database file names. If more than one --database option is specified, the resulting path is a concatenation of the separate paths. An empty database file name is replaced by the default database. A database file name - refers to the standard input. Note that a database can be read from the standard input only once. -e, --existing Print only entries that refer to files existing at the time locate is run. -L, --follow When checking whether files exist (if the --existing option is specified), follow trailing symbolic links. This causes broken sym- bolic links to be omitted from the output. This is the default behavior. The opposite can be specified using --nofollow. -h, --help Write a summary of the available options to standard output and exit successfully. -i, --ignore-case Ignore case distinctions when matching patterns. -p, --ignore-spaces Ignore punctuation and spaces when matching patterns. -t, --transliterate Ignore accents using iconv transliteration when matching patterns. -l, --limit, -n LIMIT Exit successfully after finding LIMIT entries. If the --count option is specified, the resulting count is also limited to LIMIT. -m, --mmap Ignored, for compatibility with BSD and GNU locate. -P, --nofollow, -H When checking whether files exist (if the --existing option is specified), do not follow trailing symbolic links. This causes bro- ken symbolic links to be reported like other files. This is the opposite of --follow. -0, --null Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1). -S, --statistics Write statistics about each read database to standard output instead of searching for files and exit successfully. -q, --quiet Write no messages about errors encountered while reading and processing databases. -r, --regexp REGEXP Search for a basic regexp REGEXP. No PATTERNs are allowed if this option is used, but this option can be specified multiple times. --regex Interpret all PATTERNs as extended regexps. -s, --stdio Ignored, for compatibility with BSD and GNU locate. -V, --version Write information about the version and license of locate on standard output and exit successfully. -w, --wholename Match only the whole path name against the specified patterns. This is the default behavior. The opposite can be specified using --basename. EXAMPLES
To search for a file named exactly NAME (not *NAME*), use locate -b 'NAME' Because is a globbing character, this disables the implicit replacement of NAME by *NAME*. FILES
/var/lib/mlocate/mlocate.db The database searched by default. ENVIRONMENT
LOCATE_PATH Path to additional databases, added after the default database or the databases specified using the --database option. NOTES
The order in which the requested databases are processed is unspecified, which allows locate to reorder the database path for security rea- sons. locate attempts to be compatible to slocate (without the options used for creating databases) and GNU locate, in that order. This is the reason for the impractical default --follow option and for the confusing set of --regex and --regexp options. The short spelling of the -r option is incompatible to GNU locate, where it corresponds to the --regex option. Use the long option names to avoid confusion. The LOCATE_PATH environment variable replaces the default database in BSD and GNU locate, but it is added to other databases in this imple- mentation and slocate. AUTHOR
Miloslav Trmac <mitr@redhat.com> SEE ALSO
updatedb(8), iconv(1), mlocate Sep 2012 locate(1)
All times are GMT -4. The time now is 03:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy