howtouselinux

5 Options for Linux Find command

Table of Contents

Linux find command is one of the most powerful tools in the Linux system administrators’ arsenal.

We collect 5 options for Linux find command. Hope it can help you find files or directory quickly.

 

Find and remove multiple files

$ find . -type f -name “*.mp3” -exec rm -f {} \;

Find and remove single file

$ find . -type f -name “howtouselinux.txt” -exec rm -f {} \;

 

Find and delete 100mb files

$ find / -type f -size +100m -exec rm -f {} \;

 

Find specific files and delete

$ find / -type f -name *.mp3 -size +10m -exec rm {} \;

 

 

Find and replace

$ find ./ -type f -exec sed -i ‘s/find/replace/g’ {} \;

$ find ./ -type f -readable -writable -exec sed -i “s/old/new/g” {} \;

 

Find and rename

$ find . -type f -name ‘file*’ -exec mv {} {}_renamed \;

$ find . -type f -name ‘file*’ -exec sh -c ‘x=”{}”; mv “$x” “${x}.bak”‘ \;

 

Find and move

find . -name ‘*.mp3’ -exec mv {} /tmp/music \;

Find and move it to a specific directory

David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.