-k FILE (conditional operator)
true
if the file or directory exists and has its sticky
bit set.
-k
is not included in POSIX.1-2017, but is provided by some implementations.
Quoting from man chmod
:
The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.
For regular files on some older systems, the bit saves the program’s text image on the swap device so it will load more quickly when run; this is called the sticky bit.
Links
Examples
- Different ways to test if the sticky bit of a file is set:
1 2 3 4
test -k ~/file.txt && echo "sticky bit set" [ -k ~/file.txt ] && echo "sticky bit set" # Bash [[ -k ~/file.txt ]] && echo "sticky bit set"
- Set the sticky bit for a file
1
chmod u+t ~/file.txt
BashSupport Pro ist eine Bash IDE mit Unterstützung für -k – probieren Sie es aus!