Find all writable files in the current directory

后端 未结 10 406
[愿得一人]
[愿得一人] 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

    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.

提交回复
热议问题