目录内容
rtetteh@PW02R9F3:~/Projects$ ls -al
total 68
drwxr-xr-x 5 rtetteh rtetteh 4096 Oct 27 13:45 .
drwxr-xr-x 18 rtetteh rtetteh 4096 Oct 27 13:45 ..
-rw-r--r-- 1 rtetteh rtetteh 12288 Sep 30 15:19 .ThreadTest.cpp.swp
drwxr-xr-x 2 rtetteh rtetteh 4096 Oct 27 13:45 .recycleBin
-rw-r--r-- 1 rtetteh rtetteh 953 Oct 27 13:44 ThreadTest.cpp
-rwxr-xr-x 1 rtetteh rtetteh 24984 Sep 30 15:14 ThreadTest_exe
drwxr-xr-x 2 rtetteh rtetteh 4096 Aug 17 18:26 hello
drwxr-xr-x 6 rtetteh rtetteh 4096 Oct 21 15:12 python-account-manager
-rwxr-xr-x 1 rtetteh rtetteh 168 Aug 19 20:23 test_pos_param.sh
测试1
rtetteh@PW02R9F3:~/Projects$ ls -al *.sh
-rwxr-xr-x 1 rtetteh rtetteh 168 Aug 19 20:23 test_pos_param.sh
测试2
rtetteh@PW02R9F3:~/Projects$ ls -al *.swp
ls: cannot access '*.swp': No such file or directory
为什么测试1有效而测试2无效。我如何让测试2工作,即显示扩展名为.swp的文件
您的错误假设是星号扩展为包含">";在字符串的开头。Shell默认值在regexp中不匹配。
您需要特别指定">.*.swp";以便进行正确的膨胀。这也不需要ls的-a开关,因为您指定了">";前缀