Command to list all files except . (dot) and .. (dot dot)

Regarding the ls(1) documentation (man ls):

-A, --almost-all do not list implied . and ..

you need (without any additional argument such as .*):

ls -A

or better yet:

/bin/ls -A

I have a situation where I want to remove a series of dot-directories. In my servers we mark directories for removal adding a dot and certain other text patterns (timestamp) for automated removal. Sometimes I need to do that manually.

As I commented to Basile Starynkevitch's reply, when you use a globbing pattern like the one below the -A switch loses its function and works just as -a:

 runlevel0@ubuntu:~/scripts$ ls -1dA .*
.
..
.comparepp.sh.swp

It would most certainly give an error if I try to remove files as a user, but I just don't want to think what could happen as root (!)

My approach in this case is:

for dir in $(ls -1ad .* | tail -n +3) ; do rm -rfv $dir  ; done

I tail out the 2 first line containing the dots as you can see. To tailor the answer to the question asked this would do the job:

ls -d1A .* | tail -n +3

$ ls -lA

works best for my needs.

For convenience I recommend to define an alias within .bashrc-file as follows:

alias ll='ls -lA'

Tags:

Linux

Shell

Ls