命令列出除以外的所有文件.(点)和..(点点) - Linux

non*_*doo 22 linux shell ls

我正在尝试查找列出所有文件(包括隐藏文件)的命令,但必须排除当前目录和父目录.请帮忙.

$ ls -a \.\..
Run Code Online (Sandbox Code Playgroud)

Bas*_*tch 29

阅读ls(1)文档(可能带有man ls).至少,要养成尝试的习惯

ls --help
Run Code Online (Sandbox Code Playgroud)

或更好(因为ls可能是别名,例如你的~/.bashrc)

/bin/ls --help
Run Code Online (Sandbox Code Playgroud)

你会得到一些东西:

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
Run Code Online (Sandbox Code Playgroud)

等等....

你想要ls -A或更好/bin/ls -A(没有任何额外的参数,如.*)

  • 为什么 `/bin/ls -A` 排除点目录,但 `ls -A` 不排除?至少,我的系统是这样的,它运行基于 Ubuntu 14.04.5 的发行版。 (2认同)
  • @AndyForceno:可能`ls`是一些别名(或shell函数),例如在您的.bashrc中 (2认同)

Ala*_*lan 6

$ ls -lA
Run Code Online (Sandbox Code Playgroud)

最适合我的需要。

为了方便起见,我建议在 .bashrc 文件中定义一个别名,如下所示:

alias ll='ls -lA'
Run Code Online (Sandbox Code Playgroud)