Find all writable files in the current directory

后端 未结 10 447
[愿得一人]
[愿得一人] 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 12:26

    If you are in shell use

    find .  -maxdepth 1 -type f -writable
    

    see man find

    You will find you get better answers for this type of question on superuser.com or serverfault.com

    If you are writing code not just using shell you may be interested in the access(2) system call.

    This question has already been asked on serverfault

    EDIT: @ghostdog74 asked if you removed write permissions for this file if this would still find the file. The answer, no this only finds files that are writable.

    dwaters@eirene ~/temp
    $ cd temp
    
    dwaters@eirene ~/temp/temp
    $ ls
    
    dwaters@eirene ~/temp/temp
    $ touch newfile
    
    dwaters@eirene ~/temp/temp
    $ ls -alph
    total 0
    drwxr-xr-x+ 2 dwaters Domain Users 0 Mar 22 13:27 ./
    drwxrwxrwx+ 3 dwaters Domain Users 0 Mar 22 13:26 ../
    -rw-r--r--  1 dwaters Domain Users 0 Mar 22 13:27 newfile
    
    dwaters@eirene ~/temp/temp
    $ find .  -maxdepth 1 -type f -writable
    ./newfile
    
    dwaters@eirene ~/temp/temp
    $ chmod 000 newfile
    
    dwaters@eirene ~/temp/temp
    $ ls -alph
    total 0
    drwxr-xr-x+ 2 dwaters Domain Users 0 Mar 22 13:27 ./
    drwxrwxrwx+ 3 dwaters Domain Users 0 Mar 22 13:26 ../
    ----------  1 dwaters Domain Users 0 Mar 22 13:27 newfile
    
    dwaters@eirene ~/temp/temp
    $ find .  -maxdepth 1 -type f -writable
    
    dwaters@eirene ~/temp/temp
    

提交回复
热议问题