GGshow reloaded GGshow reloaded

December 19, 2012

Linux command – 1.2 – Searching for files

find – search for files in a directory hierarchy

Usage:

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

Options:

-P
Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.

-L
Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points). Use of this option implies -noleaf. If you later use the -P option, -noleaf will still be in effect. If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched. When the -L option is in effect, the -type predicate will always match against the type of the file that a symbolic link points to rather than the link itself (unless the symbolic link is broken). Using -L causes the -lname and -ilname predicates always to return false.

-H
Do not follow symbolic links, except while processing the command line arguments. When find examines or prints information about files, the information used shall be taken from the properties of the symbolic link itself. The only exception to this behaviour is when a file specified on the command line is a symbolic link, and the link can be resolved. For that situation, the information used is taken from whatever the link points to (that is, the link is followed). The information about the link itself is used as a fallback if the file pointed to by the symbolic link cannot be examined. If -H is in effect and one of the paths specified on the command line is a symbolic link to a directory, the contents of that directory will be examined (though of course -maxdepth 0 would prevent this).

locate – find files by name

Usage:

locate [OPTION]... PATTERN...

Options:

-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 symbolic 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.

-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 broken 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 licence 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.

Filter contents using ls & grep

Example: list all mp3 files in current working directory

$ ls -B |grep ".mp3"
?????.mp3
?????.mp3
?????.mp3
Filed under: Linux — Tags: , , , — GG @ 5:41 pm

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

© 2017 GGSHOW | Powered by WordPress