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

sky*_*sea 4 configuration kubuntu ls

我正在编辑 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)
Run Code Online (Sandbox Code Playgroud)

如何确定文件或目录属于这些类别中的哪一个?

我为 LS_COLORS 引用的链接:

使用file不起作用;查询目录告诉我该目录是...一个目录。但很明显它有一个file没有显示的文件类型标志,因为有些目录有一个绝对糟糕的淡绿色突出显示和白色文本。使用ls -lah也不起作用;权限字符串的第一个字母是d,这又是不够的信息。

Ubuntu 19.10 | KDE 等离子 5.16.5 | zsh 5.7.1

小智 5

我不知道有什么程序可以列出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
Run Code Online (Sandbox Code Playgroud)

现在您知道有多少不同类型的目录(对于dicolors,它们只是 的目录file。检查浅绿色目录上的白色的权限ls -ld your_directory

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

我知道这些步骤并不完全符合您的要求:获取用于某个节点的文件类型 dircolors。但是,在两者之间,它们应该有助于调试,并且您可以为那些您无法找到的文件类型调整颜色。