Skip to main content
Clarity
Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

I'm assuming your criterion for avoiding a file/directory is that it has any permission bits set for group or other. You can use either of these constructs to avoid matching such files:

find <path> ! ( <permissions_mask_set> ) -exec ls -ld {} ; find <path> ( <permissions_mask_set> ) -o -exec ls -ld {} ; 

Taking the first one of these because that matches your own example, it would become:

find . \! \( -perm -001 -o -perm -002 -o -perm -004 -o -perm -010 -o -perm -020 -o -perm -040 \) -exec ls -ld {} \; 

For systems with GNU find the permissions mask can be much simplified:

find . \! -perm /077 -exec ls -ld {} \; 

The reason your own attempt is showing everything, including your excluded files, is because one of the values passed to the -exec is a command that looks (partially) like this

ls -l . 

If you run that at the command line you'll get all the (non-"dot") files/directories in the current directory listed - including any you want excluded. The key is either to use the -d flag to avoid listing the contents of directory, or to qualify the find command either looking only for files or excluding directories.

I'm assuming your criterion for avoiding a file/directory is that it has any permission bits set for group or other. You can use either of these constructs to avoid matching such files:

find <path> ! ( <permissions_mask_set> ) -exec ls -ld {} ; find <path> ( <permissions_mask_set> ) -o -exec ls -ld {} ; 

Taking the first one of these because that matches your own example, it would become:

find . \! \( -perm -001 -o -perm -002 -o -perm -004 -o -perm -010 -o -perm -020 -o -perm -040 \) -exec ls -ld {} \; 

For systems with GNU find the permissions mask can be much simplified:

find . \! -perm /077 -exec ls -ld {} \; 

The reason your own attempt is showing everything, including your excluded files, is because one of the values passed to the -exec is a command that looks (partially) like this

ls -l . 

If you run that at the command line you'll get all the files/directories in the current directory listed - including any you want excluded. The key is either to use the -d flag to avoid listing the contents of directory, or to qualify the find command either looking only for files or excluding directories.

I'm assuming your criterion for avoiding a file/directory is that it has any permission bits set for group or other. You can use either of these constructs to avoid matching such files:

find <path> ! ( <permissions_mask_set> ) -exec ls -ld {} ; find <path> ( <permissions_mask_set> ) -o -exec ls -ld {} ; 

Taking the first one of these because that matches your own example, it would become:

find . \! \( -perm -001 -o -perm -002 -o -perm -004 -o -perm -010 -o -perm -020 -o -perm -040 \) -exec ls -ld {} \; 

For systems with GNU find the permissions mask can be much simplified:

find . \! -perm /077 -exec ls -ld {} \; 

The reason your own attempt is showing everything, including your excluded files, is because one of the values passed to the -exec is a command that looks (partially) like this

ls -l . 

If you run that at the command line you'll get all the (non-"dot") files/directories in the current directory listed - including any you want excluded. The key is either to use the -d flag to avoid listing the contents of directory, or to qualify the find command either looking only for files or excluding directories.

Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

I'm assuming your criterion for avoiding a file/directory is that it has any permission bits set for group or other. You can use either of these constructs to avoid matching such files:

find <path> ! ( <permissions_mask_set> ) -exec ls -ld {} ; find <path> ( <permissions_mask_set> ) -o -exec ls -ld {} ; 

Taking the first one of these because that matches your own example, it would become:

find . \! \( -perm -001 -o -perm -002 -o -perm -004 -o -perm -010 -o -perm -020 -o -perm -040 \) -exec ls -ld {} \; 

For systems with GNU find the permissions mask can be much simplified:

find . \! -perm /077 -exec ls -ld {} \; 

The reason your own attempt is showing everything, including your excluded files, is because one of the values passed to the -exec is a command that looks (partially) like this

ls -l . 

If you run that at the command line you'll get all the files/directories in the current directory listed - including any you want excluded. The key is either to use the -d flag to avoid listing the contents of directory, or to qualify the find command either looking only for files or excluding directories.