Windy764
Windy764

Reputation: 87

Modified time from user's input bash script

I am new with shell script programming and I want to create a searching program using shell script. When user enter the modified time, it will show a list of all files which have modified time less than the user's input. But nothing appear. What have I messed up?

#!/bin/bash
echo "Enter a date:"
read -r numdate
result4=$(find -type f -mtime -"$numdate" -print)
echo "$result4" 

Upvotes: 0

Views: 192

Answers (1)

sjsam
sjsam

Reputation: 21965

Below will work

#!/bin/bash
read -p "Enter day/s : " numdays
echo "Files which were modified $numdays days ago"
result4=$(find -type f -mtime "$numdays")
echo "$result4"         

Notes:

  1. You could use read prompt here ie -p option.
  2. find manpage says the mtime expects days as an integer:

    -mtime n
    File's data was last modified n*24 hours ago.

Upvotes: 1

Related Questions