Find all writable files in the current directory

后端 未结 10 409
[愿得一人]
[愿得一人] 2020-12-25 11:47

I want to quickly identify all writable files in the directory. What is the quick way to do it?

相关标签:
10条回答
  • 2020-12-25 12:35

    -f will test for a file

    -w will test whether it's writeable

    Example:

    $ for f in *; do [ -f $f ] && [ -w $f ] && echo $f; done
    
    0 讨论(0)
  • 2020-12-25 12:35

    The problem with find -writable is that it's not portable and it's not easy to emulate correctly with portable find operators. If your version of find doesn't have it, you can use touch to check if the file can be written to, using -r to make sure you (almost) don't modify the file:

    find . -type f | while read f; do touch -r "$f" "$f" && echo "File $f is writable"; done

    The -r option for touch is in POSIX, so it can be considered portable. Of course, this will be much less efficient than find -writable.

    Note that touch -r will update each file's ctime (time of last change to its meta-data), but one rarely cares about ctime anyway.

    0 讨论(0)
  • 2020-12-25 12:38
    for  var in `ls`
    do
    if [ -f $var -a -w $var ]
    then
    echo "$var having write permission";
    else
    echo "$var not having write permission";
    fi
    done
    
    0 讨论(0)
  • 2020-12-25 12:41

    If you want to find all files that are writable by apache etal then you can do this:

    sudo su www-data
    find . -writable 2>/dev/null 
    

    Replace www-data with nobody or apache or whatever your web user is.

    0 讨论(0)
提交回复
热议问题