From 00bc8547ca33a452c1f30dbc38430b88f9414b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 31 Jan 2023 00:04:57 +0100 Subject: [PATCH] Add option to filter files by inode number Add the option on Unix systems to filter files by their inode number. The Windows equivalent FileIndex is not yet stabilized, see https://github.com/rust-lang/rust/issues/63010. This is especially useful to debug audit records, e.g.: Jan 30 17:48:55 laptop audit: PATH item=0 name="pulse" inode=7340042 dev=fe:03 mode=040700 ouid=1001 ogid=1001 rdev=00:00 obj=system_u:object_r:unlabeled_t:s0 nametype=NORMAL cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0 Closes: #880 --- README.md | 1 + doc/fd.1 | 3 +++ src/cli.rs | 14 ++++++++++++++ src/config.rs | 4 ++++ src/main.rs | 4 ++++ src/walk.rs | 14 ++++++++++++++ 6 files changed, 40 insertions(+) diff --git a/README.md b/README.md index 376148f34..310e7e2a5 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,7 @@ Options: executable (x), empty (e), socket (s), pipe (p), char-device (c), block-device (b) -e, --extension Filter by file extension + --inum Filter by inode number -S, --size Limit results based on the size of files --changed-within Filter by file modification time (newer than) --changed-before Filter by file modification time (older than) diff --git a/doc/fd.1 b/doc/fd.1 index 501bb1598..14b7bbc5b 100644 --- a/doc/fd.1 +++ b/doc/fd.1 @@ -271,6 +271,9 @@ Always colorize output. .BI "\-j, \-\-threads " num Set number of threads to use for searching & executing (default: number of available CPU cores). .TP +.BI "\-\-inum " num +Filter files by their inode number. +.TP .BI "\-S, \-\-size " size Limit results based on the size of files using the format .I <+-> diff --git a/src/cli.rs b/src/cli.rs index 601250fef..83da037a5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -375,6 +375,20 @@ pub struct Opts { )] pub extensions: Option>, + /// Filter files by their inode number. + /// Format: [inum]. + /// + /// Examples: + /// {n} --inum 4242 + #[cfg(unix)] + #[arg( + long, + value_name = "inode-number", + help = "Filter by inode number", + long_help + )] + pub inum: Option, + /// Limit results based on the size of files using the format <+->. /// '+': file size must be greater than or equal to this /// '-': file size must be less than or equal to this diff --git a/src/config.rs b/src/config.rs index d0a2fd209..03b6a7241 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,6 +47,10 @@ pub struct Config { /// Whether elements of output should be separated by a null character pub null_separator: bool, + #[cfg(unix)] + /// The inode number to search for. + pub inode_number: Option, + /// The maximum search depth, or `None` if no maximum search depth should be set. /// /// A depth of `1` includes all files under the current directory, a depth of `2` also includes diff --git a/src/main.rs b/src/main.rs index 764b7e340..eb5fc14ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,6 +206,8 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result Result