Highlight directories in path with execute permission for others


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Highlight directories in path with execute permission for others
# 1  
Old 04-08-2011
Highlight directories in path with execute permission for others

Hi all, I'm trying to make a script that takes at the most one argument and lists all directories in the path in a special format:

User Group Other Filename
rwx r-- r-x \
rwx r-x r-- home


This is my code as it is right now:

Code:
if [ $# -gt 1 ]
then
    echo 'Usage: dirpath [ dir-name ]' 1>&2
    exit 1
fi
if [ $# = 1 ]
then
      if [ ! -d $1 ]
     then
          echo "dirpath: $1 is not a valid directory name"
         exit 1
      fi
     cd $1
fi


echo " Owner Group Other Filename"
echo " ----- ----- ----- --------"

pathnow="/$(pwd | sed 's/\// /g')"
for dirs in $pathnow
do
cd $dirs

if [ $(ls -ld . | cut -c10) != 'x' ]
then
tput smso
fi
echo -n `ls -ld . | cut -c1`
echo -n ' '
echo -n `ls -ld . | cut -c2`
echo -n ' '
echo -n `ls -ld . | cut -c3`
echo -n ' '
echo -n `ls -ld . | cut -c4`
echo -n ' '
echo -n `ls -ld . | cut -c5`
echo -n ' '
echo -n `ls -ld . | cut -c6`
echo -n ' '
echo -n `ls -ld . | cut -c7`
echo -n ' '
echo -n `ls -ld . | cut -c8`
echo -n ' '
echo -n `ls -ld . | cut -c9`
echo -n ' '
echo  -n `ls -ld . | cut -c10`
echo " $dirs"
tput rmso
done

exit 0

This is what I get when I run my script:

dirpath ~/BTP100
Owner Group Other Filename
----- ----- ----- --------
d r w x r - x r - x /
d r w x r - x r - x home
d r w x - - x - - x drey5

As you can see aren't there as I want them and the directory BTP100 isn't listed. Also, directories that have execute permission for others aren't being highlighted.

Any help is appreciated.
# 2  
Old 04-08-2011
There's far more wrong with your script than it not printing in color... Using 'cut' to get a single character, 10 times in a row, is roughly 2,000 times slower than using shell builtins.

What is your system? What is your shell?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

2. Red Hat

Use of Execute permission for folder

Hi All, What is the use of execute permission for a folder. I know "for execute a file(script file) we have to provide execute permission to that respective file".But what is the use to give execute permission to folder.Is it equal to read permission ? Regards, Mastan (1 Reply)
Discussion started by: mastansaheb
1 Replies

3. Debian

Execute permission problem

Hello, I need to install a program from a DVD. It uses a sh script called setup. root@ragnok: head -2 /media/cdrom0/setup #!/bin/sh root@ragnok: ls -l /media/cdrom0/setup -r-xr-xr-x 1 root root 4688 Nov 8 08:38 /media/cdrom0/setup root@ragnok: /media/cdrom0/setup bash:... (2 Replies)
Discussion started by: snorkack59
2 Replies

4. UNIX for Dummies Questions & Answers

Provide execute permission to a user

Hi, I have a shell script(test.sh) and need to give execute permission for this shell script to user group cobr_sftp and oracle. Could you please help as to how to give this permission. I have already given full access(777) to script test.sh. Does this mean all the users/user group can access... (1 Reply)
Discussion started by: abhi_123
1 Replies

5. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

6. Shell Programming and Scripting

Problem with execute my file permission

Here is my script. 1 echo -n "Enter file name : " 2 read file 3 chmod 777 $file 4 && W="write = yes" || W="Write = no" 5 chmod 777 $file 6 && X="Execute = yes" || X="Execute = No" 7 chmod 777 $file 8 && R="Read = yes" || R="Read = No" ... (0 Replies)
Discussion started by: qral_hdr
0 Replies

7. Shell Programming and Scripting

Only Execute Permission for Others...

This might be very silly question but i dont know y is it so... i Have script I have Given the permissions in the following manner... -rwxrwx--x 1 root system 3 Jun 08 15:46 temp I want no one to see what is present in that but should be able to execute it.. but when... (3 Replies)
Discussion started by: pbsrinivas
3 Replies

8. Shell Programming and Scripting

without execute permission

how can a script run without execute permissions. when i run myscript as : sh a.sh it was working but when i say simple a.sh its not working since it has no x permission.but how about fist case? (1 Reply)
Discussion started by: Raom
1 Replies

9. UNIX for Dummies Questions & Answers

No permission to execute file

I am logged in as root and am trying to execute a file called x_cleanup_equdata but keep getting the message ksh: x_cleanup_equdataNEW: 0403-006 Execute permission denied. I did FTP this file from another server using GET, would this make the difference? I tried chmod 666 but still no luck. ... (2 Replies)
Discussion started by: markbeeson
2 Replies
Login or Register to Ask a Question