I'm trying to find a command that would list all files (including hidden files), but must exclude the current directory and parent directory. Please help.
$ ls -a \.\..
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
/bin/ls -A excludes the dot directories, but ls -A does not? At least, that is the case on my system, which runs a distro based on Ubuntu 14.04.5.ls is some alias (or shell function) e.g. in your .bashrc\ls -A to disable ls alias, but /bin/ls is bullet proof :)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