Linux - find command

Bash Liste Des Attaques Ovh

About

Search, print information and takes actions on files in a directory hierarchy.

Find use stat to extract its information

File Status = File Metadata

Synopsis/Syntax

find [-H] [-L] [-P] [path...] [options] [^(-|(|)|,|!)argument....]
Synbol Default Description
'-H', '-L' and '-P' options control the treatment of symbolic links
path current directory names of files or directories to be examined
^(-|(|)|,|!)argument.... -print
(consider -print0)
expression describing what is to be searched for.
The argument expressions begins with ‘-’, ‘(’, ‘)’, ‘,’, or ‘!’

The expression is made up of:

  • options (which affect overall operation rather than the processing of a specific file, and always return true),
  • tests (which return a true or false value),
  • actions (which have side effects and return a true or false value), all separated by operators.
  • operators. -and is assumed where the operator is omitted. The POSIX standard specifies parentheses ‘(’, ‘)’, negation ‘!’ and the ‘and’ and ‘or’ operators (‘-a’, ‘-o’).

Filtering

Tree Level

Argument Type Description
Level
-maxdepth levels Option Descend at most levels (a non-negative integer) levels of directories below the command line arguments.
'-maxdepth 0' means only apply the tests and actions to the command line arguments.
-mindepth levels Option Do not apply any tests or actions at levels less than levels (a non-negative integer).
‘-mindepth 1’ means process all files except the command line arguments.

Time

This section shows the filter based directly on the date metadata

Time
Argument Type Description
Access time filter (axxx options)
-amin n Test File was last accessed n minutes ago. See File’s status
-anewer file Test File was last accessed more recently than file was modified. See File’s status
-atime n Test File was last accessed n*24 hours ago. See File’s status
Changed time filter (cxxx options)
-cmin n Test File’s status was last changed n minutes ago.
-cnewer file Test File’s status was last changed more recently than file was modified.
-ctime n Test File’s status was last changed n*24 hours ago.
Modify time filter (mxxx options)
-mmin n Test File's data was last modified n minutes ago.
-mtime n File's data was last modified n*24 hours ago.

Name

File name
Argument Type Description
-name pattern Test Base of file name

Example

Search from the current directory

find . -name 'pattern'

where:

  • the point specify to search from the current directory (in or below)
  • the pattern is a regexp pattern of the file name

Search by file name

Search for any file named root.sh in or below the directory /my/directory.

find /my/directory -name root.sh

Search for any file beginning with default

find /my/directory -name default*

The metacharacters (‘*’, ‘?’, and ‘[]’) match a ‘.’ at the start of the base name.

Listing recursively file information

find . -printf "%p %u %g %M %a %c\n"
# for sizing
echo "Relative_Path,Depth,Leading_Dir,Size_in_Byte,User_Name,Last_access_time,Last_change_time" > diskInfo.csv
find . -printf '"%p","%d","%h","%s","%u","%AY-%Am-%Ad","%CY-%Cm-%Cd"\n' >> diskInfo.csv

where:

Path:

  • %p is the full qualified path
  • %P is the relative path
  • %d File’s depth in the directory tree; 0 means the file is a command line argument.
  • %h Leading directories of file’s name (all but the last element).

Size:

  • %k The amount of disk space used for this file in 1K blocks
  • %s File’s size in bytes.

User/Security

  • %u is the user. File’s user name, or numeric user ID if the user has no name
  • %g is the group
  • %M and %m are permissions (respectively in symbolic form as ls and octal form)

Time:

  • %a is the File’s last access time. See %Ak to specify a date format. Example: %AY-%Am-%Ad - YYYY-MM-DD
  • %c is the File’s last status change time. See %Ck to specify a date format
  • %t File’s last modification time in the format returned by the C ‘ctime’ function.

Search newer file

-newer file: File was modified more recently than file. If file is a symbolic link and the -H option or the -L option is in effect, the modification time of the file it points to is always used.

touch -d '2011-12-31 10:22' foo
find . -newer foo

Action on file with exec

Syntax:

find -exec command {} \;
find -exec command {} \+

where:

  • \ in \; is an escape sequence. ; is the end of the exec command not of the find command.
  • {} is a placeholder for the filename found.
  • + will make only one command invocation

Example:

  • Remove the directory named “jsp_servlet”
 find . -name "jsp_servlet" -exec rmdir {} \;
  • Moving all library file
find . -type f -iname '*.so' -exec mv -t ./test/ {} \+

Documentation / Reference





Discover More
Bip Eclipse Web Service
BIP - Web Service

Getting Started with BIP Web Service How to generate the BI Publisher Stub Classes See See Include the following jar files in your classpath activation.jar from the Java...
Undraw File Manager Re Ms29
File System - Analytics

See also: Every file system has a way to dump file system information. Disk usage Example on Linux with the find command to list information recursively where: Path: %p is the relative...
Bash Liste Des Attaques Ovh
How to Zip / Unzip on Linux

The zip manager in Linux Compression: take advantage of redundancy between files. split archives: storing a large archive on multiple removable media. split big file ? List the content...
Bash Liste Des Attaques Ovh
Linux - File

Linux file management See Using Parameters Expansion Removal From a path string where the file does not exist dirname returns the first parent of an existing path file. ...
Linux - File/Folder Permissions - Access Control List ( ACL ) - Posix Model

In Linux, every object is a file. A directory or a folder is then also a file. Linux follows the POSIX permissions model. A permission is a combination between: an access right (read, write, execute)...
Bash Liste Des Attaques Ovh
Linux - Stat (File status)

This page is the file metadata (also known as file status) on the linux file system Principally, the stat command display the file metadata. find command man where: Through the --printf=FORMAT...
Bash Liste Des Attaques Ovh
Linux - ls (List directory content)

ls is a Linux Command utility that lists the contents of a directory ll is an alias of “ls -la” You can also list files and directories with the find command This script will: list the...
Card Puncher Data Processing
Shell Data Processing - Global Regular Expression Print (GREP command) (line filtering, word search)

grep stands for “global regular expression print”. Grep searches lines of a file that match a regular expression pattern and returns them. It is by default case sensitive. searches all files...
Card Puncher Data Processing
Shell Data Processing - Stream

This page is the creation of Stream in the Shell context. You start a stream with an initialization function that creates a standard output such as: grep ... You connect then: the first...



Share this page:
Follow us:
Task Runner