LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-25-2007, 03:05 PM   #1
subnet_rx
Member
 
Registered: Oct 2001
Distribution: Ubuntu 9.10
Posts: 148

Rep: Reputation: 15
Need a bash script


I would like to get all files modified within the last 3 days and change the owner:group permissions on these files. How can I do that in bash?
 
Old 01-25-2007, 03:20 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well it'd be a "find" one liner really. check the -mtime option to locate files on modified time stamps, and just use -exec to sne dthose results to the command of choice, chown in this case.
 
Old 01-25-2007, 03:51 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
With the option -mtime, the find command looks for the files modified more than n days ago. To retrieve the files modified within the last three days I would use the -newer option as in the following code (but probably there is a better way to do this)

Code:
touch -t `date +%Y%m%d%H%M.%S -d "3 day ago"` /tmp/testfile && find . -newer /tmp/testfile -exec chown user:group {} \; && rm /tmp/testfile
The -newer option ensures to retrieve the files more recent than a file modified three days ago.
 
Old 01-25-2007, 07:05 PM   #4
subnet_rx
Member
 
Registered: Oct 2001
Distribution: Ubuntu 9.10
Posts: 148

Original Poster
Rep: Reputation: 15
Thanks colucix. I'm going to give that a try.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration