LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-919794/)

grungesabin 12-21-2011 04:22 AM

shell script
 
Hello All,
Can anyone give me some idea about the shell script that will display all the files and directories with rwx permission in a particular directory
Thank You

jhw 12-21-2011 04:28 AM

I would try to solve this issue with 'find'. The manpage has lots of infos on your requirements.

grungesabin 12-21-2011 04:30 AM

could you please elaborate little more on your post
thank you

fukawi1 12-21-2011 04:37 AM

You can do it with the find command.

Code:

find ./ -maxdepth 1 -perm -g=w
Which would match anything in the current directory with the user write bit set. You didn't say rwx permission for who, so, thats just an example.

From "man find"
Quote:

-perm mode
File's permission bits are exactly mode (octal or symbolic). Symbolic modes use mode 0 as a point of departure.
-perm -mode
All of the permission bits mode are set for the file.
-perm +mode
Any of the permission bits mode are set for the file.
You could also do it with ls and grep/
Code:

ls -l | grep rwx
But that will match for ANY of the UGO bits being set to rwx.

grungesabin 12-21-2011 04:47 AM

Hello
thank that was a great help but still i couldn't write shell script completely and well i want to display all the files and folders with rwx permission for user
And thank you fukawi1

fukawi1 12-21-2011 04:56 AM

well you would want to use to match the owners permission bits.
Code:

-user username -perm -o=rwx
As jhw said, read the manual, its all in there.

singhharmeet 12-21-2011 05:12 AM

# ls -l [directory-path]

grungesabin 12-21-2011 05:19 AM

still couldn't get what i was trying to do
"i need to list all the files from a particular directory with rwx permission for user using a shell script"
i tried to go through man but its too lengthy and kinda confusing as well
anyways thank you all

Nylex 12-21-2011 05:21 AM

Perhaps you should look at a tutorial for find, such as this one. If you haven't done shell scripting before, then this (for Bash) should be useful.

jv2112 12-21-2011 05:40 AM

This will search for files in the directory you list under the user you want for files then filter with grep everything else but files with rwx permissions for the owner.

Quote:



find /Directory/you/want/to/search/ -user name -and -type f -exec ls -l {} \; | grep ^-rwx




singhharmeet 12-21-2011 07:56 AM

1. create an empty file open it with gedit (if u have gui) or on command line open with vi
write following code

#!/bin/sh

ls -l -a | grep rwx [path of the directory]

2. save the file

3. chmod 755 path-of-the-script-file

4. run the script like

#./script


if you want user to enter the absolute path of the directory use following script:

#!/bin/sh
echo "please enter path of the directory"
read path
ls -l -a $path | grep rwx

grungesabin 12-21-2011 09:58 PM

@singhharmeet:
#!/bin/sh
echo "please enter path of the directory"
read path
ls -l -a $path | grep rwx

the above script displays all the files with rwx permission for all users. What do we need to alter so that is shows only files with rwx permission for user only.

Nylex 12-22-2011 01:36 AM

grungesabin, you don't seem to understand how this site works. We're not going to do everything for you. People have given you hints as to how to write a script to do what you want and now you need to put some effort into learning and attempting to do the rest yourself. When you've attempted something, post and people will help you..

fukawi1 12-22-2011 01:42 AM

Quote:

Originally Posted by Nylex (Post 4555925)
grungesabin, you don't seem to understand how this site works. We're not going to do everything for you. People have given you hints as to how to write a script to do what you want and now you need to put some effort into learning and attempting to do the rest yourself. When you've attempted something, post and people will help you..

Seconded, there is MORE than enough information, for multiple solutions to your problem, provided by a number of users contained within this thread...
Particularly considering your "too long didn't read" attitude towards the manpages.
Quote:

Originally Posted by grungesabin
i tried to go through man but its too lengthy


grungesabin 12-22-2011 05:09 AM

Hey all
thank u so much for the help but as i have said i am extremely new to this OS that was the reason and it wasn't about my attitude but i wasn't getting everything from the manual.
From next time i will keep that in mind that i put enough effort but being a newbie i think i should ask question to clear up my doubts.
Thank you


All times are GMT -5. The time now is 02:14 PM.