find files of a variable fileType

Find files of variable fileType The script will search your machine for files with the specified file type and save the results in a CSV file named by timestamp and file type under /Users/Shared directory.

Keep in mind that searching the entire file system may take a long time, depending on the number of files on your machine. You can limit the search to specific directories by changing the starting path in the “find” command. For example, to search only in the user’s home directory, replace the / in find / -type f with the path to the desired directory, like find /Users/username -type f.


# Set the variable fileType to the desired file extension (e.g., txt, jpg, pdf)

# Get the current timestamp
timestamp=$(date +%Y%m%d%H%M%S)

# Define the output CSV file path

# Add the CSV headers
echo "File Name,File Size,File Creation Date,File Modification Date,Path" > "$output_file"

# Find files and save their information to the CSV file
find / -type f -iname "*.${variable_fileType}" -exec stat -f '%N,%z,%SB,%Sm,%p' -t "%Y-%m-%d %H:%M:%S" {} \; | awk -F/ -v OFS=',' '{
    for (i=1; i> "$output_file"


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link