Write a Bourne shell script called age_ls.sh that expects two files as command l
ID: 665910 • Letter: W
Question
Write a Bourne shell script called age_ls.sh that expects two files as command line arguments. The first file should be a directory, and the script should list all files in that directory that are newer than the file given as the second command line argument. Your script should then print the message “Excluded x older files”, where x is a count of the number of files in the given directory that are older than the file given as the second parameter.
How do I write code in file.sh?
#!/bin/sh
.....
Explanation / Answer
vi hello.sh #!/bin/bash echo "Hello, World!" echo "Knowledge is power." #!/bin/bash START=$HOME # change your directory to command line if passed # otherwise use home directory [ $# -eq 1 ] && START=$1 if [ ! -d $START ] then echo "$START not a directory!" exit 1 fi # use find command to get all subdirs name in DIRS variable DIRS=$(find "$START" -type d) # loop thought each dir to get the number of files in each of subdir for d in $DIRS do [ "$d" != "." -a "$d" != ".." ] && echo "$d dirctory has $(ls -l $d | wc -l) files" done echo "Excluded x older files"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.