nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell Script To Outputs File Permissions of Most Recently Modified File

This is a discussion on Shell Script To Outputs File Permissions of Most Recently Modified File within the Shell scripting forums, part of the Development/Scripting category; Dear All, I was wondering if there are somebody would be able to help me with my task. I was ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-25-2008, 10:56 AM
Junior Member
User
 
Join Date: Aug 2008
OS: UBUNTU
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
glen_4455 is on a distinguished road
Unhappy Shell Script To Outputs File Permissions of Most Recently Modified File

Dear All,

I was wondering if there are somebody would be able to help me with my task. I was asked to write a shell script (/bin/sh) which outputs the file permissions of the most recently modified file in the current directory. If those file permissions are " -rw-r----- " then the name of the file should be appended to a file called "log". Please help me..
Reply With Quote
  #2 (permalink)  
Old 08-25-2008, 03:39 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 691
Thanks: 15
Thanked 18 Times in 17 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Here is shell script
Code:
#!/bin/bash
LOGFILE="log"
# List all the files in your current directory tree that were both accessed and modified between now and 2 days ago
FILES=$(find . -daystart -atime -2 -mtime -2  \! -type d 2>/dev/null)
>$LOGFILE
for f in $FILES
do
  # compare file permission
  # 640 == rw-r------
  [ $(stat -c '%a' $f) -eq 640 ] && echo $f >>$LOGFILE
done
Read following man pages to get idea about find and stat command:
Code:
man stat
man find
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply

Tags
bash , file permissions , find , shell script , stat


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
[Solved] Shell script for ftp the file vishal_titre Shell scripting 4 08-21-2009 04:50 PM
shell script to search specific file from txt file inside zip file and extract it aasif.shaikh Shell scripting 2 05-31-2008 07:44 PM
Shell Script Searching For a Record In The File vinz4ever Shell scripting 1 05-11-2008 08:35 PM
If file modified execute a script karabaja Shell scripting 3 11-23-2006 03:39 AM
error shell script no such file or directory /bin/sh Linux software 1 01-08-2006 09:34 PM


All times are GMT +5.5. The time now is 02:11 AM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38