1

In my script i want to check if file named "Flag" was created more than 10 minutes from now, and if it was, delete it.

Got something like this:

ZMIENNA=`find /home/maciej/testy/ -mmin +10 -name Flag`
if [ -N $ZMIENNA ]
then
        rm /home/maciej/testy/Flag
fi

Thank you for replying.

Maciejek
  • 569
  • 1
  • 5
  • 21
  • Why do you use -N? This option test if the file "is modified since it was last read". Maybe you want to check if the string ZMIENNA is not empty? The is -n lowercase and add "" to protect the string ZMIENNA – terence hill Nov 20 '15 at 09:09
  • 1
    Welcome to StackOverflow. What do you get with the code you have shown? How does it work as opposed to what you expect? – henrikstroem Nov 20 '15 at 09:10

2 Answers2

1

You can just use find to delete a file, for example to delete file1 in the current folder:

find . -name file1 -mmin +10 -exec rm {} \;
terence hill
  • 3,354
  • 18
  • 31
0

According to the manual the option -mmin of find is based on the last modification date:

 -mmin n
        File's data was last modified n minutes ago.

As stated by this post : How to get file creation date/time in Bash/Debian? the creation time is not stored as file metadata on POSIX systems.

Community
  • 1
  • 1
Paul K.
  • 796
  • 2
  • 7
  • 20