如何在 Linux 中确定文件类型?

如何在 Linux 中确定文件类型?

我正在编辑 LS_COLORS 环境变量。dircolors列出不同文件类型的默认颜色。文件类型表示如下:

bd = (BLOCK, BLK)   Block device (buffered) special file
cd = (CHAR, CHR)    Character device (unbuffered) special file
di = (DIR)  Directory
do = (DOOR) [Door][1]
ex = (EXEC) Executable file (ie. has 'x' set in permissions)
fi = (FILE) Normal file
ln = (SYMLINK, LINK, LNK)   Symbolic link. If you set this to ‘target’ instead of a numerical value, the color is as for the file pointed to.
mi = (MISSING)  Non-existent file pointed to by a symbolic link (visible when you type ls -l)
no = (NORMAL, NORM) Normal (non-filename) text. Global default, although everything should be something
or = (ORPHAN)   Symbolic link pointing to an orphaned non-existent file
ow = (OTHER_WRITABLE)   Directory that is other-writable (o+w) and not sticky
pi = (FIFO, PIPE)   Named pipe (fifo file)
sg = (SETGID)   File that is setgid (g+s)
so = (SOCK) Socket file
st = (STICKY)   Directory with the sticky bit set (+t) and not other-writable
su = (SETUID)   File that is setuid (u+s)
tw = (STICKY_OTHER_WRITABLE)    Directory that is sticky and other-writable (+t,o+w)

我如何确定文件或目录属于哪个类别?

我引用的 LS_COLORS 链接:

使用file不起作用;查询目录告诉我目录是...目录。但显然它有一个file未显示的文件类型标志,因为有些目录有一个非常糟糕的浅绿色高亮和白色文本。使用ls -lah也不起作用;权限字符串的第一个字母是d,这又是没有足够的信息。

Ubuntu 19.10 | KDE Plasma 5.16.5 | zsh 5.7.1

答案1

我不知道有哪个程序可以列出已知的文件类型dircolors。我怀疑没有,尽管这会是 dircolors 的一个很好的补充,但您可以转储数据库并在那里找到您想要更改的文件类型。例如,对于目录:

$ dircolors -p|grep dir

# Configuration file for dircolors, a utility to help you set the
# slackware version of dircolors) are recognized but ignored.
DIR 01;34 # directory
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable

现在你知道有多少种不同类型的目录了(对于dicolors,它们只是 的目录file。使用ls -ld your_directory

您还可以在系统中列出颜色及其含义。检查这个脚本

我知道这些步骤并不能完全满足您的要求:获取 dircolors 用于特定节点的文件类型。但是,这两者应该有助于调试,并且您可以针对无法找到的文件类型调整颜色。

相关内容