Linux Shell Commands: Find File Extensions and .pc_* Files

Managing files in a Linux environment often requires identifying specific file types or extensions recursively across directories. This guide explains two powerful shell commands to: (1) list distinct file extensions and (2) find files with a specific pattern (.pc_*), both excluding CVS directories commonly used in version control. Whether you're auditing a project or troubleshooting an iMX instance, these commands are essential tools for system administrators and developers.

Command 1: List Distinct File Extensions

This command recursively finds all files with extensions, excludes CVS directories, and outputs a unique list of extensions.

find ./ -type f -name "*.*" -not -path "*/CVS/*" | \
    sed 's/.*\.\([^.]*\)$/\1/' | \
    sort -u | \
    while read -r ext; do
        echo "$ext"
    done
        

How It Works

Example Output: txt, sh, py

Command 2: Find Files with .pc_* Pattern

This command locates files matching the .pc_* pattern (e.g., .pc_1, .pc_backup), excluding CVS directories.

find ./ -type f -name "*.pc_*" -not -path "*/CVS/*"
        

How It Works

Example Output: ./scripts/.pc_config, ./data/.pc_backup

Why Exclude CVS?

CVS (Concurrent Versions System) directories contain metadata files (e.g., Entries, Root) that are not part of the project's primary content. Excluding them with -not -path "*/CVS/*" ensures the commands focus on relevant files, improving accuracy and relevance, especially in legacy projects or iMX environments.

Illustration of Linux Shell Commands for Finding File Extensions

Best Practices

← Back to Linux Guides