Question: Change up this script a little to still make it work still. Write me a script that takes a directory to start in. It should
Change up this script a little to still make it work still.
Write me a script that takes a directory to start in. It should print all files that meet at least on criteria, and tell me why. It can list the same file more than once if need be.
Here is what I did, please change it a little from what I have.
#!/bin/bash
dir=$1 #reads the dir we want from the command line
# find empty files find "$dir" -type f -size 0 -printf "%p: Empty file " 2>/dev/null
# find empty directories find "$dir" -type d -empty -printf "%p: Empty directory " 2>/dev/null
# find files last accessed more than 1 year ago find "$dir" -type f -atime +365 -printf "%p: Last accessed more than 1 year ago " 2>/dev/null
# find files owned by no valid user find "$dir" -type f ! -uid "$(id -u)" -printf "%p: Owned by no valid user " 2>/dev/null #! = is not
# find files owned by root find "$dir" -type f -user root -printf "%p: Owned by root " 2>/dev/null
# find .bashrc files with world or group write permission find "$dir" -name ".bashrc" \( -perm -g=w -o -perm -o=w \) -printf "%p: .bashrc with world or group write permission " 2>/dev/null
# find files larger than 10M find "$dir" -type f -size +10M -printf "%p: Larger than 10MB " 2>/dev/null
# find device special files find "$dir" -type c -o -type b -printf "%p: Device Special File " 2>/dev/null
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
