0

It has been awhile since I have had to drive into shell scripting. However, I have a shell script where I'm renaming files based on the file extension from a ftp upload.

Currently, the files are uploaded to the server via an FTP process. All files are renamed from filename.txt to filename.dat. What I would like to do is only rename the files based on the file's modified date after a certain number of minutes.

i.e. all files whose modified time is greater than five (5) minutes.
-mtime -5.

Below is my shell script:

#!/bin/bash for name in /u/easy/ep2/data/download/*.txt; do newname=${name%.txt}.log mv "$name" "$newname" done 

1 Answer 1

0

You need +5 for more than 5 minutes.

find /u/easy/ep2/data/download -maxdepth 1 -name '*.txt' -mtime +5 \ -exec sh -c 'mv "$1" "${1%.txt}.log"' arg0ignored {} \; 

Edit

Example:

$ find /tmp -maxdepth 1 -name '*.txt' -mtime +5 -exec sh -c 'echo mv "$1" "${1%.txt}.log"' x0 '{}' \; mv /tmp/1.txt /tmp/1.log mv /tmp/2.txt /tmp/2.log 
18
  • Sorry, I should have included the Linux version. We are running RedHat Enterprise v 7.4. Commented Aug 9, 2018 at 19:00
  • This is the error message I get when I run the script from the command line or inside the script. find: paths must precede expression: -exec Commented Aug 9, 2018 at 19:08
  • I have GNU find 4.6.0, for me this works. I forgot the arg0, that is ignored, but that shouldn't lead to this message. Commented Aug 9, 2018 at 19:17
  • I will give that a try! Thank you for your help! Commented Aug 9, 2018 at 19:18
  • Still returns the same error message when I added the arg0ignored. Commented Aug 9, 2018 at 19:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.