Hi,

I'm trying to write a shell script to show me the number of Readable, Writable and executable files in a directory.

I have no idea how I can do that.

Any help???

Thank you.

Recommended Answers

All 4 Replies

Witch OS.

If it is Linux the next question becomes readable, writeable and executable by whom (owner, group and/or world)?

If Linux here is a security check script I wrote to look for files that may be security issues:

#!/bin/bash
#This program looks for possible security risks to the server and stores the list 
#in a file in the /var/log/chksec/ dir for review using the supplied parameter $1 as 
#the file name.  If no paraeter supplied then show usage info.
#
if [ $1 ]
then
	echo $1 > /var/log/chksec/$1
	echo "Starting Checks..." >> /var/log/chksec/$1
	echo "Open Directory check." >> /var/log/chksec/$1
	find /home -type d -perm 777 -ls   >> /var/log/chksec/$1
	find /var -type d -perm 777 -ls   >> /var/log/chksec/$1
	echo "Open File check." >> /var/log/chksec/$1
	find /home -type f -perm 777 -ls | grep -v '/proc'  >> /var/log/chksec/$1 
	find /var -type f -perm 777 -ls | grep -v '/proc'  >> /var/log/chksec/$1 
	echo "Open Group and other Directory check." >> /var/log/chksec/$1
	find /home -type d -perm /022 -exec ls -lad {} \;  >> /var/log/chksec/$1 
	find /var -type d -perm /022 -exec ls -lad {} \;  >> /var/log/chksec/$1 
	#
	#check for web or other writeable directories and files.
	find /home -type f -perm -022 -ls | grep -v '/proc' >> /var/log/chksec/$1
	find /var -type f -perm -022 -ls | grep -v '/proc' >> /var/log/chksec/$1
	#
	#check for web writable files
	#Dispaly file when done.
	less /var/log/chksec/$1
else
	echo "usage securitycheck.sh <outputfile>"
	exit 0
fi

Using Linux(Ubuntu) and find NUMBER of readable, writable, executable files in a directory by the current user (running the script).

By the way, I mentioned that you are using command line argument in your script. How can I do that???

Hello,

Sorry been busy and could not get back to reply till now.

Linux holds command line arguments in variables $1 $2 $3 etc. where the variables are separated by white space (tab or space char). So the following command line:

scriptname var1 var2 var3

would set the following variables:

$1 = var1
$2 = var2
$3 = var3

Does that makes sense?

As far as finding the number of files do you need to know how many are readable as one output, then how many are writeable as a second and so on or just how many are all three or what? Have you tried the following command:

ls -la

It will give you a long directory list and show files with owner, group and the permissions.

Member Avatar for desertdenizen

Using Linux(Ubuntu) and find NUMBER of readable, writable, executable files in a directory by the current user (running the script).

By the way, I mentioned that you are using command line argument in your script. How can I do that???

rch1231 is absolutely correct in his explanation. The technical term for those variables is "positional parameters", where $0 is the script name, and $1, $2, etc., are the variables passed to the script from command line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.