Intro

I'll collect some popular find commands here. These are mainly mental notes for commonly occuring ad-hoc searches.

 

 

Examples

The fun starts here!

 

Find a particular file in this folder and sub-folders

Find a file called hosts in the folder I'm in, as well as those below. Since I'm in the root-folder, it will search all folders on the system.

$ find / -name "hosts" -type f 
/etc/hosts

 

 

Find all files containing specific text

Find all files in the folder /etc containing the text cyndane2.

$ grep -rnw '/etc/' -e 'cyndane2'
/etc/hosts:4:192.168.0.8 cyndane2 srbu.se www.srbu.se
/etc/sysconfig/network:2:HOSTNAME=cyndane2

 

 

Find all files with a specific extension and recursively delete them all

This is a dangerous command to run, so let's first do a dry-run.

The first command will find all files in the current directory that have an extension .bak.

$ find . -name "*.bak" -type f
./foo.bak

If all seems okay, run it for real this time, adding the delete parameter.

$ find . -name "*.bak" -type f -delete
$

 

 

Find all files with spaces and replace them recursively with periods

This will recursively search in folder foo for filenames with basename bar and replace the spaces with periods.

$ find . -depth -name '* *' | while IFS= read -r f ; do mv -i "$f" "$(foo"$f")/$(bar "$f"|tr ' ' .)" ; done

 

 

 

 

Sources

Legio

 

 

 

 

 

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext