See posts by tags

How to Find, Extract, and Copy Files in Linux: A Step-by-Step Guide

  • 1 min read
  • 23 Feb, 2025

Many Linux users need to search for and copy specific file types from nested folders into a designated directory. Using the find command, you can efficiently accomplish this task without additional software.

How to Find and Copy Images in Linux

To find and copy all image files (.jpg, .png, .gif, etc.) into a specific folder, use the following command:

mkdir -p /path/to/destination && find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.tiff" \) -exec cp {} /path/to/destination \;

How Does This Command Work?

  • mkdir -p /path/to/destination – Creates the destination folder if it doesn’t exist.
  • find . -type f – Searches for files in the current directory and its subdirectories.
  • Filter -iname "*.jpg" -o -iname "*.png" – Finds only image files.
  • -exec cp {} /path/to/destination \; – Copies each found file to the specified location.

How to Find and Copy Document Files in Linux

To extract document files (.pdf, .docx, .txt), use the following command:

mkdir -p /path/to/documents && find . -type f \( -iname "*.pdf" -o -iname "*.docx" -o -iname "*.txt" \) -exec cp {} /path/to/documents \;

How to Find and Copy Audio Files

If you need to extract music files, use this command:

mkdir -p /path/to/audio && find . -type f \( -iname "*.mp3" -o -iname "*.wav" \) -exec cp {} /path/to/audio \;

How to Find and Copy Video Files

To copy video files (.mp4, .avi, .mkv), run:

mkdir -p /path/to/videos && find . -type f \( -iname "*.mp4" -o -iname "*.avi" -o -iname "*.mkv" \) -exec cp {} /path/to/videos \;

Moving Files Instead of Copying

If you want to move files instead of copying them, replace cp with mv:

mkdir -p /path/to/destination && find . -type f \( -iname "*.jpg" -o -iname "*.png" \) -exec mv {} /path/to/destination \;

Conclusion

The find command in Linux is a powerful tool for automating file management. Use these commands to locate and copy files of various types into designated folders. This method will help you quickly organize files and streamline your workflow.

📌 Save these commands and never search for files manually again!