Thursday, February 22, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1563  / 2 Years ago, mon, october 11, 2021, 12:08:10

A. I used the following code to get the modified date of a file. But this is also selecting the subdirectories and thus returning an error. How can I fix this?



for file in $1/*; do
echo `stat -c %y $file | cut -d ' ' -f1`
done


$1 is the directory I am passing.



B. Also is there any way to do this thing. That I need to pass a directory and date range as command-line argument and list the file and modified date which lies in this date range.



Eg output.sh /home/user/desktop 2014-10-07 2014-11-17 should list all the files in this directory which are modified in this time interval.


More From » command-line

 Answers
2

Regarding part A of your question, here is a reference to the standard file tests.



In particular, what you can do is:



for file in $1/*; do
[ ! -d "$file" ] && echo `stat -c %y $file | cut -d ' ' -f1`
done


As for part B, see this stackoverflow question.


[#22446] Tuesday, October 12, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nalystcul

Total Points: 390
Total Questions: 106
Total Answers: 115

Location: Tokelau
Member since Sun, May 7, 2023
10 Months ago
nalystcul questions
Sun, May 1, 22, 17:05, 2 Years ago
Mon, Sep 6, 21, 08:12, 3 Years ago
Fri, Mar 18, 22, 20:06, 2 Years ago
;