LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-21-2011, 04:22 AM   #1
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Rep: Reputation: Disabled
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
 
Old 12-21-2011, 04:28 AM   #2
jhw
Member
 
Registered: Apr 2010
Posts: 83

Rep: Reputation: 32
I would try to solve this issue with 'find'. The manpage has lots of infos on your requirements.
 
Old 12-21-2011, 04:30 AM   #3
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
could you please elaborate little more on your post
thank you
 
Old 12-21-2011, 04:37 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
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.
 
1 members found this post helpful.
Old 12-21-2011, 04:47 AM   #5
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-21-2011, 04:56 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
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.
 
Old 12-21-2011, 05:12 AM   #7
singhharmeet
LQ Newbie
 
Registered: Dec 2011
Posts: 21

Rep: Reputation: Disabled
# ls -l [directory-path]
 
Old 12-21-2011, 05:19 AM   #8
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-21-2011, 05:21 AM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 12-21-2011, 05:40 AM   #10
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Lightbulb

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


 
Old 12-21-2011, 07:56 AM   #11
singhharmeet
LQ Newbie
 
Registered: Dec 2011
Posts: 21

Rep: Reputation: Disabled
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

Last edited by singhharmeet; 12-21-2011 at 08:04 AM.
 
Old 12-21-2011, 09:58 PM   #12
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 12-22-2011, 01:36 AM   #13
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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..
 
1 members found this post helpful.
Old 12-22-2011, 01:42 AM   #14
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
Originally Posted by Nylex View Post
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
 
Old 12-22-2011, 05:09 AM   #15
grungesabin
LQ Newbie
 
Registered: Dec 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
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
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 01:45 AM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 12:21 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:32 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