find

From Gentoo Wiki
Jump to:navigation Jump to:search

This article is a stub. Please help out by expanding it - how to get started.

GNU find, provided by the sys-apps/findutils package, is a utility to search for files in a directory hierarchy. It is an implementation of the find utility specified by the POSIX standard, the latest version of which is IEEE Std 1003.1-2017.

Installation

USE flags

USE flags for sys-apps/findutils GNU utilities for finding files

nls Add Native Language Support (using gettext - GNU locale utilities)
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
static !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
verify-sig Verify upstream signatures on distfiles

Emerge

The sys-apps/findutils package is part of the @system set, so is installed by default.

root #emerge --ask sys-apps/findutils

Usage

Find all files (-type f) in the current directory and its subdirectories (.) whose name ends in .txt:

user $find . -type f -name '*.txt'

Find all directories (-type d) in /tmp and its subdirectories whose name begins with test:

user $find /tmp -type d -name 'test*'

Find all files in /home/user/test/ whose name ends in .txt and change their permissions to 700:

user $find /home/user/test -type f -name '*.txt' -exec chmod 700 {} +

The {} sequence will be replaced by the name of each file found. The + character designates the end of the command to be executed; an alternative is the ; character, although that typically needs to be escaped in order to prevent it from being interpreted by the shell:

user $find /home/user/test -type f -name '*.txt' -exec chmod 700 {} \;

See also

External resources