Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Using find and xargs for advanced file searches

find walks directory trees and applies tests to files, while xargs converts a stream of results into arguments for another command. Used separately, each is useful; combined, they support precise searches, bulk inspection and controlled automation across large Linux filesystems.

The GNU versions supplied with RHEL, CentOS and Fedora provide features such as -print0, -exec ... {} + and xargs -0. These matter because ordinary text output is not a dependable boundary: a filename may contain spaces, tabs, quotation marks or even a newline.

Australian administrators often manage RHEL or Fedora servers alongside Windows services in Sydney, Melbourne, Brisbane and Perth offices. A search that works in one shell prompt can fail elsewhere if paths are split incorrectly or generated with ls, so examples should preserve names and remain readable in logs.

Build precise search expressions

Begin with a search root, followed by tests that describe the required files. File type, name, size and modification time can be combined; all tests must match unless an explicit alternative is supplied.

find /srv/reports -type f \( -iname '*.pdf' -o -iname '*.xlsx' \) -size +10M -print

The parentheses group the filename alternatives, while -type f excludes directories and other objects. -iname ignores letter case, which can be useful in Australian workplaces where users capitalise names inconsistently, although -name gives an exact case-sensitive match.

Find expressions also support negation and logical alternatives. For example, -mtime +30 selects files modified more than roughly 30 days ago, subject to GNU find’s whole-day rounding. Use -newermt when an exact timestamp boundary is more useful.

Preserve unusual filenames

Spaces are common in business documents, but quotes, tabs and newline characters are entirely valid on Linux. The usual find output separates records with newlines, so a filename containing a newline can look like two separate results.

The null-delimited variant avoids that ambiguity. GNU find writes each filename followed by a null byte, and xargs -0 reads those same boundaries before constructing a command:

find /srv/cases -type f -print0 | xargs -0 -r stat --printf='%n\t%s bytes\n' --

Here, -r prevents xargs from running stat when the search produces no files. The -- marks the end of command options, which also protects filenames that begin with a hyphen. Avoid piping find through ls or parsing it with sed, because those steps discard the reliable filename boundary.

Pass matches safely to commands

xargs can invoke a command in batches, control how many arguments it receives and report failures through its exit status. This makes it suitable for inspecting large result sets without constructing an oversized command line.

find /srv/reports -type f -name '*.pdf' -print0 |
  xargs -0 -r -n 50 stat --printf='%n\t%s bytes\n' --

The -n 50 option requests batches of up to 50 filenames. GNU xargs chooses a smaller limit when required by the operating system’s argument-size limit. A nonzero exit status should be checked rather than hidden, since it may indicate that one or more commands failed.

For many operations, find -exec is simpler because it manages batching itself. When results feed a searchable team catalogue, grouping them by type, owner and location is more useful than displaying raw paths; interface structure offers a useful design reference for that presentation layer.

Filter by dates sizes and contents

Australian teams commonly encounter dates written as DD/MM/YYYY, making expressions such as -newermt '07/10/2026' ambiguous or invalid. Supply ISO-formatted timestamps such as 2026-10-07 when precision matters.

find /srv/reports -type f -newermt '2026-10-01' ! -newermt '2026-10-07' -print

The ! negates the second timestamp test, selecting files modified on or after 1 October but before 7 October. The -size test is approximate because GNU find rounds file sizes into units; for exact byte counts, retrieve the size with stat or find -printf '%s'.

Content matching can be added without losing safe filename handling:

find /srv/cases -type f \( -iname '*.txt' -o -iname '*.md' \) \
  -exec grep -IlZ 'applicant name' {} + | xargs -0 -r printf '%s\0'

GNU grep’s -l lists matching files, -I skips binary files and -Z terminates each filename with a null byte. The final output remains safe for another null-aware command.

Prune paths and mounted filesystems

Large trees often contain caches, archives and mounted datasets that should not be searched. Pruning removes a directory before the traversal descends into it, avoiding both unnecessary work and irrelevant matches.

find /srv \( -path /srv/cache -o -path /srv/archive \) -prune \
  -o -type f -iname '*.csv' -print

The grouped paths are pruned, while the alternative branch processes ordinary files. This matters for distributed Australian teams in Brisbane and Perth, where hybrid storage and remote access can place NFS or SMB mounts inside an otherwise local directory tree.

Mount points deserve particular care. If /data is managed by systemd, check its systemd mount units before deciding whether to traverse it. The -xdev option restricts a search to the starting filesystem, but it can also skip legitimate mounted data, so use it only when that boundary is intentional.

Review changes before applying them

Independent operations can run concurrently with GNU xargs. For example, checksums can be calculated across four workers:

find /srv/reports -type f -name '*.pdf' -print0 |
  xargs -0 -r -n 1 -P 4 sha256sum --

Parallelism is useful for network-backed storage, but excessive workers can saturate disks or remote links. Output order is also not guaranteed, so results requiring a stable sequence should be sorted separately.

Before any operation changes data, preview its exact scope, confirm the destination and retain a recoverable copy. find -delete and pipelines containing rm deserve particular caution. Searches involving Canberra public-sector agencies or Australian businesses may encounter personal information, including names, ABNs, invoice references and tax file numbers. The Privacy Act 1988 and Australian Privacy Principles can therefore affect how broad searches, copies and audit logs are handled.

The habit to remember is precise matching, null-safe transport and visible review: an advanced file search earns trust when its selected paths and intended changes can both be explained before execution.