Skip to main content
  1. Technologies/

find

·115 words·1 min· ·
Table of Contents
Technologies notes - This article is part of a series.
Part 3: This Article

The find command is handy tool to manage files inside the file system, the command structure is:

find dir criteria [action]

Where:

  • dir is the starting dir
  • criteria is a filter for the element that have to match
  • action is the action to perform on the elements that matches the criteria

Limit file search #

In order to limit the depth level of the search the -maxdepth option can be used

find dir -maxdepth <VALUE> criteria [action]

Oneliners
#

  • remove files only in current dir with confirmation
find . -maxdepth 1 -type f  -exec rm -i {} \;
  • exclude elements by regex
find . -not -regex 'REGEX'
  • filter by element name
find . -name 'REGEX'
Matteo Longhi
Author
Matteo Longhi
I’m a software engineer with a passion for Music, food, dogs, videogames and open source software, i’m currently working as a devops engineer
Technologies notes - This article is part of a series.
Part 3: This Article