我在运行CENTOS 6.5的Linux服务器上访问在typesNFS上挂载的ext4文件系统上的文件时遇到了问题。 我知道文件存在于这个文件系统上,因为当我明确地调用这些文件时(例如使用ls , awk或者cat ),我可以看到它们,但是对于像rsync这样的程序或者从ls到另一个程序如grep awk 。
举一个例子来澄清一下,以下将返回空:
ls /mnt/seisvault2/data/sac/201402/20140203_220000_MAN/ | grep WCI\.BH1\.IU.10
虽然这显示了该文件实际存在:
ls /mnt/seisvault2/data/sac/201402/20140203_220000_MAN/WCI.BH1.IU.10 。
在许多目录中,这是一个问题,大多数文件显示正常,不需要显式调用,如示例中所示。
任何人都可以帮我理解这个问题吗?
作为一个例子,为什么这是一个问题,rsync -a在第一次运行时复制“missing”文件,但是对于后续的每次运行,它不认为文件在目标目录中,因此再次复制它。
这个问题似乎可以通过File Sharing / NFS下的configuration来解决。 原来,我的操作模式configuration为“用户模式”。 但是,看起来这应该是“内核模式”。
Grep使用正则expression式,其中'。' 恰好是一个特殊的字符。 为了演示,想象一下,我做一个空的,并执行以下操作:
[root@db test]# touch testfile{1,2,3,4,5} [root@db test]# touch testfile{1,2,3,4,5}.other [root@db test]# ls -lah total 8.0K drwxr-xr-x 2 root root 4.0K Jun 21 00:43 . dr-xr-x---. 4 root root 4.0K Jun 21 00:41 .. -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile1 -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile1.other -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile2 -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile2.other -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile3 -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile3.other -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile4 -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile4.other -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile5 -rw-r--r-- 1 root root 0 Jun 21 00:43 testfile5.other
现在,让我们做一些思考! 正如所料, ls | grep test ls | grep test返回目录中的所有文件:
[root@db test]# ls | grep test testfile1 testfile1.other testfile2 testfile2.other testfile3 testfile3.other testfile4 testfile4.other testfile5 testfile5.other
但让我们说,我们只是想与“。”的文件。 在他们中:
[root@db test]# ls | grep . testfile1 testfile1.other testfile2 testfile2.other testfile3 testfile3.other testfile4 testfile4.other testfile5 testfile5.other
呃,这很糟糕。 正如刚才提到的, '。' 在正则expression式中有特殊含义(即匹配1个字符)。 如何解决这个问题呢? 反斜杠来救援…作为… ESCAPANATOR
[root@db test]# ls | grep '\.' testfile1.other testfile2.other testfile3.other testfile4.other testfile5.other
请注意,我已经把它放在单引号中。 这也适用于双引号 – 在大多数情况下(shell扩展可以在更复杂的正则expression式上刻录)。 如果你需要做任何引号,你必须逃脱两次(一次为bash,一次为grep)。 它看起来像这样:
[root@db test]# ls | grep \\. testfile1.other testfile2.other testfile3.other testfile4.other testfile5.other