Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Recursively list files with no read acess


    Hi There

    I have sucessfully written some PHP scripts that recursively traverse the file system checking for all image files (jpg or gif) that do not have read permissions.

    Now I would like to know how to do this using the command line but I cant seem to get started. I know there must be an easier way than a php script.

    Any help would be greatly appreciated.

    Thanks
    Neil

  2. #2
    something like:

    find /path/to/check -type f -iname '*' -perm '+r'

    Look into the man page for find for the "-perm" option. That will probably be the best way
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,375
    Hi.

    An example script:
    Code:
    #!/bin/sh
    
    # @(#) s1       Demonstrate locating files which lack read permission.
    
    # Remove previous debris.
    
    rm -rf d1
    
    # Establish test directory.
    
    mkdir d1
    cd d1
    touch t1.gif t2.jpg t3.gif t4 t5 t6
    chmod 333 t2.jpg
    chmod 300 t3.gif
    chmod 030 t4
    chmod 003 t5
    chmod 000 t6
    ls -l
    cd ..
    
    echo
    echo " These files lack read permission:"
    find d1 ! -perm +444
    
    echo
    echo " These jpg files lack read permission:"
    find d1 -iname '*.jpg' ! -perm +444
    
    echo
    echo " These jpg and gif files lack read permission:"
    find d1 -iname '*.jpg' -o -iname '*.gif' ! -perm +444
    
    exit 0
    Which produces:
    Code:
    % ./s1
    total 0
    -rw-r--r--  1 drl drl 0 Mar 28 09:43 t1.gif
    --wx-wx-wx  1 drl drl 0 Mar 28 09:43 t2.jpg
    --wx------  1 drl drl 0 Mar 28 09:43 t3.gif
    -----wx---  1 drl drl 0 Mar 28 09:43 t4
    --------wx  1 drl drl 0 Mar 28 09:43 t5
    ----------  1 drl drl 0 Mar 28 09:43 t6
    
     These files lack read permission:
    d1/t4
    d1/t5
    d1/t6
    d1/t2.jpg
    d1/t3.gif
    
     These jpg files lack read permission:
    d1/t2.jpg
    
     These jpg and gif files lack read permission:
    d1/t2.jpg
    d1/t3.gif
    See the tutorial at http://amitsharma.linuxbloggers.com/how_to_find.htm for a number of interesting uses of find ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •