You are not logged in.

#1 2006-08-07 16:20:46

detto
Member
Registered: 2006-01-23
Posts: 510

how can i grep "wrong" dirs/files [SOLVED]

im tryin to write a little bash line or script.
it should manage to list all contents recursively of a directory and grep and print all files that have diffrent permissions as specified, same to dirs.

so i started off, no idea how big_smile
first thing is
ls -laR  lol  lol  ....... ive absolutley no idea how i can start off with scripts like that. dunno where to search or find a good/easy solution to things like that.
plz help me out with my bad scripting knowledge roll

Offline

#2 2006-08-07 16:33:17

dojo
Member
Registered: 2005-11-02
Posts: 97

Re: how can i grep "wrong" dirs/files [SOLVED]

Something like that?

ls -laR | grep -v drwx------

Maybe you it's better to use "find" instead.

Greets

dojo

Offline

#3 2006-08-07 16:41:18

detto
Member
Registered: 2006-01-23
Posts: 510

Re: how can i grep "wrong" dirs/files [SOLVED]

hey thx!

yay, this is goin right direction. smile
although a

ls -laR | grep -v -rw-r--r--

doesn't work :?:

and would be cool, if i can define: "leave dirctories out" or "leave files out"
s.th. like

ls -laR | grep -v --without-dirs -rw-r--r--

  roll

edit: ok, leaving out directories woulb be with grep-option "-d skip" right? smile
edit2: want to archive s.th. like this

ls -laR /mnt/media/Musik/ | grep -d skip -v "-rw-r--r--"

but grep then doesnt work bcoz first thing is a "-" . How to go round this :S

Offline

#4 2006-08-07 17:01:44

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: how can i grep "wrong" dirs/files [SOLVED]

detto wrote:

and would be cool, if i can define: "leave dirctories out" or "leave files out"

Look into the 'find' command (man find):

find /mnt/media/Musik -not -type d
detto wrote:

edit2: want to archive s.th. like this

ls -laR /mnt/media/Musik/ | grep -d skip -v "-rw-r--r--"

but grep then doesnt work bcoz first thing is a "-" . How to go round this :S

Add a "--":

ls -laR /mnt/media/Musik/ | grep -d skip -v -- "-rw-r--r--"

Offline

#5 2006-08-07 19:49:09

detto
Member
Registered: 2006-01-23
Posts: 510

Re: how can i grep "wrong" dirs/files [SOLVED]

mhhhhhhh..... ye i think the find command would be a good one to do that. :? but im stuckin at the last point, trying to find out what parameter or way to do exists to display whole path, i mean, atm i have s.th. like this, but it doesnt work as i want it of course because find only displays from "."

find /mnt/media/Musik -type d | grep -v -- "drwxr-xr-x"
find /mnt/media/Musik -type f | grep -v -- "-rw-r--r--"

those are the two i have now roll
but i dont find this option that may sound like "display whole path" or s.th. like that.

Offline

#6 2006-08-07 20:04:58

detto
Member
Registered: 2006-01-23
Posts: 510

Re: how can i grep "wrong" dirs/files [SOLVED]

O K .. (sry for doublepost, wanted to keep things a bit cleaner :oops: )

Those are the ones that do what i want, although a bit unpretty

find /mnt/media/Musik -type f -printf %m | grep -v 644
find /mnt/media/Musik -type d -printf %m | grep -v 755

Well it works, its just: If with 1st command a file was found with permission not set to 644 it just displays me the current permission but not the filename.
Same to directories with 2nd command.

Would be nice if someone could inform me about this little thingy, would be very thankful. Thx in advance, also to you Cerebral, i think i wouldnt have come so far without help big_smile

Offline

#7 2006-08-07 20:50:45

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: how can i grep "wrong" dirs/files [SOLVED]

Try adding the -ls flag to find:

find /mnt/media/Musik -type d -ls | grep -v "drwxr-xr-x"

Or, you could use find matching even more advanced:

find /mnt/media/Musik -type f -not -perm 0644

Seriously, read up the manpage for find.  It's all there. smile

Offline

#8 2006-08-08 00:54:57

detto
Member
Registered: 2006-01-23
Posts: 510

Re: how can i grep "wrong" dirs/files [SOLVED]

Cerebal,.. i got to thank you again. Works wonderfully now big_smile

Sure, those manpages roll But its always a unfriendly way of typing man program-name and than search up and down, up again and stumble across an option, scroll down again and so on.
Isn't there s.th. of a program for search through man-pages? roll

cheers, detto

Offline

#9 2006-08-08 02:18:27

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: how can i grep "wrong" dirs/files [SOLVED]

Well, whatever pager you use to view manpages can probably search - try typing / followed by a search string when you view a manpage, like:

/perm

Basically vim-style searching.  That's the one I've seen most supported.

Offline

#10 2006-08-08 11:06:13

detto
Member
Registered: 2006-01-23
Posts: 510

Re: how can i grep "wrong" dirs/files [SOLVED]

:shock: uff...damn, workin. also highliting all results, awesome! thx so much smile

Offline

Board footer

Powered by FluxBB