什么是“常规文件"?在CentOS和Ubuntu上? [英] What is "the regular file" on CentOS and Ubuntu?

查看:80
本文介绍了什么是“常规文件"?在CentOS和Ubuntu上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的环境是:

  • CentOS 6.9
  • Ubuntu 16.04 LTS

GNU coreutils 8.4具有test命令,可使用 -f 选项检查文件.

The GNU coreutils 8.4 has the test command to check the file using -f option.

man test 显示

  -f FILE
         FILE exists and is a regular file

常规文件"的定义对我来说是模棱两可的.

The definition of the "regular file" is ambiguous for me.

我在航站楼上

$ touch afile
$ ln -fs afile LN-FILE

然后,我执行了以下脚本(check_file_exist_180320_exec)

Then, I executed the following script (check_file_exist_180320_exec)

#!/usr/bin/env bash
if [ -e LN-file ]
then
    echo "file exists [-e]"
fi

if [ -f LN-file ]
then
    echo "file exists [-f]"
fi

对于CentOS和Ubuntu,对于符号链接文件(LN-FILE)都显示-e和-f.

For CentOS and Ubuntu, both show -e and -f for symbolic linked file (LN-FILE).

但是,ls -l返回LN-FILE文件的 l:symbolik链接(不是-:regular file )标识符.(请参阅. https://linuxconfig.org/identifying-file-types-in-linux)

However, ls -l returns l:symbolik link (not -:regular file) identifiers for the LN-FILE file. ( see. https://linuxconfig.org/identifying-file-types-in-linux)

另一方面,我发现以下内容, if -e和if -f

On the other hand, I found following, Difference between if -e and if -f

常规文件不是目录/符号链接/套接字/设备等

A regular file is something that isn't a directory / symlink / socket / device, etc.

回答了2012年4月18日7:10

answered Apr 18 '12 at 7:10

jman

我应该检查常规文件"(对于CentOS和Ubuntu)的引用是什么?

What is the reference I should check for the "regular file" (for CentOS and Ubuntu)?

推荐答案

请注意 man test

除-h和-L之外,所有与FILE相关的测试均取消引用链接.

Except for -h and -L, all FILE-related tests dereference symbolic links.

基本上,当您执行 -f LN-file 且LN-file是符号链接时, -f 测试将跟随该符号链接,并为您提供结果符号链接指向的内容.

Basically when you do -f LN-file , and LN-file is a symbolic link, the -f test will follow that symlink, and give you the result of what the symlink points to.

如果要检查文件是符号链接还是常规文件,则需要执行以下操作:

If you want to check if a file is a symlink or a regular file, you need to do e.g.

if [ -h LN-file ]
then
    echo "file is a symlink [-h]"
elif [ -f LN-file ]
then
    echo "file is a regular file [-f]"
fi

这篇关于什么是“常规文件"?在CentOS和Ubuntu上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆