Setting read only based on modification time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting read only based on modification time
# 1  
Old 03-21-2016
Setting read only based on modification time

Hi all

first a setup scenario
create 3 files with modification date 1, 2, and 3 days ago
as stated in the find line it should only do something to the files 2 and 3 days old
find . -mtime +2 works fine and only displays the 2 files but running the entire line sets all files to read only.

i hope that someone here can help me out with this cause i'm stuck
i advance thanks

Masterdraco


Code:
_dir="${1:-.}"
_fperm="0444"
_dperm="0445"
_ugperm="root:wheel"
_chmod="/bin/chmod"
_chown="/usr/sbin/chown"
_find="/usr/sbin/find"
_xargs="/usr/bin/xargs"

find "$_dir" -mtime +2 | $_chown -R "${_ugperm}" "$_dir" | $_chmod -R "${_fperm}" "$_dir" | find "$_dir" -type d -print0 | $_xargs -0 -I {} $_chmod $_dperm {}


Last edited by jim mcnamara; 03-21-2016 at 01:13 PM..
# 2  
Old 03-21-2016
Merely an opinion: cramming dozens of command onto one line is cool. And horrible to maintain.

As a result, my answer would be to break that up, and then I could suggest where you could insert a single command line to solve your question. Some one else who is a one-line lover could maybe help you. I draw the line on this as the question is stated.
# 3  
Old 03-21-2016
Merely an opinion: cramming dozens of commands onto one line is not cool.
# 4  
Old 03-21-2016
Why the pipe to the second find? Does not appear to make any sense.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

File date/time modification and permissions

First, oh great Unix gurus, forgive if this is a stupid question. Unix/Linux is not my main thing but I have been programming in C/C++ for many years. I will do my best to be specific. I have a program in C/C++ that needs to modify the time of a given file. Currently I do this using utime()... (5 Replies)
Discussion started by: Pug
5 Replies

2. Shell Programming and Scripting

How to change modification time of file?

Explain it with proper e.g (4 Replies)
Discussion started by: sidpatil
4 Replies

3. Shell Programming and Scripting

Ls ignoring files from their modification time

Hi everyone, I'd like to know if is there a way to list files but ignoring some according to their modification time (or creation, access time, etc.) with the command 'ls' alone. I know the option -I exist, but it seems to only looking in the file name.. Thank you in advance for the... (8 Replies)
Discussion started by: Keyhaku
8 Replies

4. Shell Programming and Scripting

How to list the files based on the modification time using the find command?

Hi All, I need to list the files based modification time of the files from a directory, I cannot use "ls -t" as there are lot of files, which "ls" command cannot handle. New files will land there daily. So iam looking for an alternative through "find"command. All suggestions are welcomed. ... (6 Replies)
Discussion started by: Kesavan
6 Replies

5. UNIX for Dummies Questions & Answers

Need Modification Time of a file

Hi all, I need the modification time of a file on a particular day say 3 days before. I just don't want the last modification time. I need all the modification times on a particualar day. Is there anyway to do it? Kindly help. Could anyone tell me where the modification time is stored?... (1 Reply)
Discussion started by: vidhyab
1 Replies

6. Shell Programming and Scripting

File modification time comparison

Hi All, I have two files (given below) each exists under different paths. I want to compare the modification time stamp of file1.txt is lessthan the modification time of file2.txt. month1=`ls -l file1.txt | awk '{ print $6}'` date1=`ls -file1.txt | awk '{ print $7}'` time1=`ls... (1 Reply)
Discussion started by: Arunprasad
1 Replies

7. Shell Programming and Scripting

time modification in script

Hi All.. I have a file with a number of non-unique entries as below: 1243 01:42:29,567 --> 01:42:32,108 blah blah .... blah blah .. 1244 01:42:32,709 --> 01:42:34,921 blah blah .... 1245 01:42:35,214 --> 01:42:36,533 blah blah .... blah blah .. blah blah .... blah blah .. (4 Replies)
Discussion started by: UniRock
4 Replies

8. Shell Programming and Scripting

Archive Files over certain modification time

Environment is cygwin on Windows Server 2003 as I could not think how I would achieve this using Windows tools. What I want ot achieve is the following. I have a Directory D:\Data which contains further subfolders and files. I need to move "files" older than 6 months modification time to... (4 Replies)
Discussion started by: jelloir
4 Replies

9. Shell Programming and Scripting

Copy files based on modification date

How to copy files from a location to a directory <YYMM> based on last modification date? This will need to run daily. I want to copy those file for May to 0905 and Jun to 0906. Appreciate your guidance.:) Thanks. -rw-rw-rw- 1 ttusr tgrp 4514 May 29 21:49 AB24279J.lot_a... (17 Replies)
Discussion started by: KhawHL
17 Replies

10. UNIX for Dummies Questions & Answers

File modification time

Does anyone know how to display the time with seconds of when a file was last modified. I can get hour & minutes but would also like seconds. --Running AIX (1 Reply)
Discussion started by: edog
1 Replies
Login or Register to Ask a Question