How to find files in Bash?

Find files by their name in Bash in all subdirectories

find . | grep MyFileName

Find files by their name in Bash in the current directory

ls | grep MyFileName

How to find new files in Bash?

find . -mmin -5
find . -mtime -5

How to find old files in Bash?

find . -mmin +5
find . -mtime +5

How to find files by size in bash?

find . -type f -size -4M
find . -type f -size +4M

Find files containing a string in bash

grep -rlI "string in file" .

How to sort all files in a directory in bash by time?

ls -1rt
find . -printf "%T+ %p\n" | sort | sed 's/^[^ ]* //g'

How to make ‘find’ and ‘grep’ work on Mac?

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install findutils

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store