LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2002, 06:31 PM   #1
nabil
Member
 
Registered: Feb 2001
Location: MI, USA
Distribution: Debian Linux 100% GNU
Posts: 210

Rep: Reputation: 31
Script that lists #of permissions


what should be the script that lists the number of readable, writable and executable files in your home directory. ??

Example:

$filenum
There are 5 executable files
There are 3 writable files
There are 4 readable files


Thanks for any help

Last edited by nabil; 04-21-2002 at 08:12 PM.
 
Old 04-22-2002, 06:50 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Maybe something like this:

Code:
#!/bin/bash

dir=~

readable=0
writeable=0
executeable=0
count=0

for file in `ls $dir`
do
  if [ -r $file ]
  then
    let readable+=1
  fi
  
  if [ -w $file ]
  then
    let writeable+=1
  fi 

  if [ -x $file ]
  then
    let executeable+=1
  fi

  let count+=1
done

echo "$count file(s)"
echo "There are $readable readable file(s)"
echo "There are $writeable writeable file(s)"
echo "There are $executeable executeable file(s)"
 
Old 04-22-2002, 07:58 PM   #3
nabil
Member
 
Registered: Feb 2001
Location: MI, USA
Distribution: Debian Linux 100% GNU
Posts: 210

Original Poster
Rep: Reputation: 31
Thank you,
That was pretty good ...Did just exactly what I asked for..
 
Old 04-22-2002, 08:20 PM   #4
nabil
Member
 
Registered: Feb 2001
Location: MI, USA
Distribution: Debian Linux 100% GNU
Posts: 210

Original Poster
Rep: Reputation: 31
Just curious,

Your script kind of came late as I had to think to make one my self.
I thought some thing along these lines:


Code:
This will give you number of files with readable permission 
Code: 
ls -l | grep "r" | wc |awk '{print $1}'  

This will give you number of files with writable permission 
Code: 
ls -l | grep "w" | wc |awk '{print $1}'  

This will give you number of files with execute permission 
Code: 
ls -l | grep "x" | wc |awk '{print $1}'


What do you think,
Does it do the job too, not sure if it works every time.
 
Old 04-22-2002, 10:12 PM   #5
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
It might not work if the executable file has a w in the name it'll count it as writable, it will give you 1 file if run it against writable file check, and so on.
 
Old 04-23-2002, 02:32 AM   #6
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Like neo said if the name, user or group has a r w x in it then your count will be inaccurate. You could have modified it to something like this to make sure it only checks the permissions:

ls -l | cut -f 1 -d ' ' | grep r | wc | awk '{print $1}'
 
Old 04-23-2002, 03:06 AM   #7
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
why are you using something as big as awk to do something so simple? just use "wc -l" instead.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to set up permissions amwink Linux - General 2 10-22-2005 09:32 AM
Script to change folder permissions waitingforOES Linux - Newbie 1 03-07-2005 01:34 PM
perl script, users and permissions djgerbavore Programming 1 12-29-2004 12:41 PM
Listing permissions with shell script Ollir Programming 1 10-18-2004 06:50 AM
check file permissions in a script cambie Linux - General 9 09-22-2004 12:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:51 AM.

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