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.


#!/bin/bash

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

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

# Define the output CSV file path
output_file="/Users/Shared/${timestamp}_${variable_fileType}.csv"

# 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=',' '{
    file_name=$NF
    file_path=""
    for (i=1; i> "$output_file"

Link:
https://github.com/patent-ed/find-files-of-variable-fileType

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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