Stack Overflow

Questions

Developer Jobs

Tags

Users

1,221

●2●15●26

current community

help
chat
log out

Stack Overflow

Meta Stack Overflow

your communities

edit
cancel

Stack Overflow
1,221

Ask Ubuntu
8

Cryptography
101

Bitcoin

reset to default list

more stack exchange communities

company blog

Tour

Start here for a quick overview of the site

Help Center

Detailed answers to any questions you might have

Meta

Discuss the workings and policies of this site

About Us

Learn more about Stack Overflow the company

Business

Learn more about hiring developers or posting ads with us

Using `find -perm` to find when a permission is not set

Ask Question

up vote
55
down vote

favorite

9

I want to find the non-readable files in my directory (eg the files with g-r). So I tried this:

find . -perm -g-r

It shows me all of the files?? So I tried this:

find . -perm -g+r

And it showed me only the readable files. It appears that -perm -g-r matches all files. I'm using CentOS 5.5. Am I doing something wrong? It doesn't look like -perm -g-r does anything useful.

linux bash find

share|edit|flag

asked Dec 7 '10 at 23:05

User1

14.6k42150216

add a comment |

start a bounty

3 Answers
3

active

oldest

votes

up vote
78
down vote

accepted

Try:

find . ! -perm -g+r

share|edit|flag

edited Dec 7 '11 at 15:29

Tim Cooper

103k23204206

answered Dec 7 '10 at 23:13

jgr

3,0911724

3

upvote

flag

That worked! I'm still mystified by -perm -g-r not working, but oh well.
– User1
Dec 7 '10 at 23:23

upvote

flag

It's an obvious extension to find files that are not executable, too. Thanks!
– Walter Nissen
Mar 22 '11 at 21:44

upvote

flag

What if I want to limit my search to files and not directories, and want a -maxdepth of 2? I mean, how do I negate the perms while asserting the other things? EDIT: Nevermind. You can negate any option with !. It didn't seem to be working at first, but it really was. I did find -maxdepth 2 ! -perm -g+r -type d and found directories to a depth of 2 that did not have group read permission.
– Buttle Butkus
Nov 25 '12 at 9:03

add a comment |

up vote
19
down vote

If you want to find files that are non-readable by you, you could use

find . ! -readable

share|edit|flag

answered Dec 7 '10 at 23:16

Charley

43129

6

upvote

flag

This works for Linux, but the BSD find on the Mac (from 2008) doesn't support it.
– Walter Nissen
Mar 22 '11 at 21:43

upvote

flag

Good point. There are probably quite a few versions of find out there that don't support -readable.
– Charley
Mar 25 '11 at 6:30

add a comment |

up vote
-3
down vote

You were able to see all files when you executed the below instruction, because you were executing it as root.

find . -perm -g-r

Try executing as a normal user.

share|edit|flag

edited May 7 '11 at 14:33

Mia Clarke

6,60433960

answered May 3 '11 at 13:26

seenshee91

131

7

upvote

flag

File attributes (permissions, ownership, size, etc.) do not depend on the user. I believe your answer is wrong.
– tommy.carstensen
Apr 1 '14 at 14:42

upvote

flag

Also, OP asked how to find bits not set, which Tim Cooper's answer does and yours misses.
– Mike Diehn
Jul 20 at 14:50

add a comment |

Your Answer

draft saved

draft discarded

community wiki

discard

Not the answer you're looking for? Browse other questions tagged linux bash find or ask your own question.

asked

6 years, 11 months ago

viewed

52,375 times

active

5 years, 11 months ago

Featured on Meta

What can we put in a question template to help people ask better questions?

What’s Happening With Channels?

Hot Meta Posts

9

Is my account data deleted on account deletion?

5

Dynamicly Expand the Community Bullentin, if no Hot Meta Post is shown

Linked

0

how to find directories without access permissions ?

4

How can I properly check delete/write permissions for a folder hierarchy?

Related

599
How can I exclude all “permission denied” messages from “find”?

499
Shell command to tar directory excluding certain files/folders

329
Using grep to find files that don't contain a given string pattern

747
Exclude directory from find . command

869
How to set a variable to the output from a command in Bash?

286
How to recursively find and list the latest modified files in a directory with subdirectories and times?

157
“find: paths must precede expression:” How do I specify a recursive search that also finds files in the current directory?

305
How do I get cURL to not show the progress bar?

522
grep, but only certain file extensions

2869
How do I find all files containing specific text on Linux?

Hot Network Questions

Are smartphone apps theoretically capable of detecting what a user is looking at?

How can I prevent students from writing answers on an assignment, then claiming I didn't see their answer?

Which pitfalls should I watch out for when meeting my half-brother who hasn't been aware of my existence for 25 years?

Identify a comic where Scrooge McDuck was protected against a beam because he went swimming in his money

Why does Andrew Ng prefer to use SVD and not EIG of covariance matrix to do PCA?

How to properly address an unsolved problem that is very hard to solve in mathematical thesis?

Does a CPU keep its processing speed after years of use?

Comparing rated, stall, and inrush current in DC motor

Why would the Rhodesians trust Blacks in their army?

What were the first humans with alphanumeric designations?

Bigger SSD = longer life due to wear leveling

Want to write, have ideas, no story telling techniques or experience, feeling lost?

Is it illegal to backup your hard drive if you have copyrighted software on it?

Is it bipartite?

How can Scrooge McDuck dive into money without hurting himself?

Reason for popularity of Apple IIGS

Where would a vampire-like creature get its energy from?

Where was green squadron at the Battle of Yavin and the Battle of Scarif?

Shell script to create a file if it doesn't exist?

Checking for balanced brackets in Python

Is my barcode valid?

Tree vs lightning rod : why one burns and the other doesn't?

Is austerity in the UK responsible for "120,000" extra deaths?

Why is being "on hold" on the telephone not made less annoying?

more hot questions

question feed

lang-sh

Stack Overflow

Questions

Jobs

Developer Jobs Directory

Salary Calculator

Help

Mobile

Stack Overflow
Business

Talent

Ads

Enterprise

Insights

Company

About

Press

Work Here

Legal

Privacy Policy

Contact Us

Stack Exchange
Network

Technology

Life / Arts

Culture / Recreation

Science

Other

Stack Overflow

Server Fault

Super User

Web Applications

Ask Ubuntu

Webmasters

Game Development

TeX - LaTeX

Software Engineering

Unix & Linux

Ask Different (Apple)

WordPress Development

Geographic Information Systems

Electrical Engineering

Android Enthusiasts

Information Security

Database Administrators

Drupal Answers

SharePoint

User Experience

Mathematica

Salesforce

ExpressionEngine® Answers

Stack Overflow em Português

Blender

Network Engineering

Cryptography

Code Review

Magento

Software Recommendations

Signal Processing

Emacs

Raspberry Pi

Stack Overflow на русском

Programming Puzzles & Code Golf

Stack Overflow en español

Ethereum

Data Science

Arduino

Bitcoin

more (26)

Photography

Science Fiction & Fantasy

Graphic Design

Movies & TV

Music: Practice & Theory

Worldbuilding

Seasoned Advice (cooking)

Home Improvement

Personal Finance & Money

Academia

Law

more (16)

English Language & Usage

Skeptics

Mi Yodeya (Judaism)

Travel

Christianity

English Language Learners

Japanese Language

Arqade (gaming)

Bicycles

Role-playing Games

Anime & Manga

Puzzling

Motor Vehicle Maintenance & Repair

more (32)

MathOverflow

Mathematics

Cross Validated (stats)

Theoretical Computer Science

Physics

Chemistry

Biology

Computer Science

Philosophy

more (10)

Meta Stack Exchange

Stack Apps

API

Data

Area 51

Blog

Facebook

Twitter

LinkedIn

site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0
with attribution required.
rev 2017.11.16.27769