I'm trying to list all the hidden files in a directory, but not other directories, and I am trying to do this using only ls and grep.
ls -a | egrep "^\."
This is what I have so far, but the problem is that it also lists hidden directories, when I don't want that.
Then, completely separately, I want to list the hidden directories.
Best Answer
To list only hidden files:
Note that files here is everything that is not a directory. It's not file in "everything in Linux is a file" ;)
To list only hidden directories:
Comments:
ls -ap
lists everything in the current directory, including hidden ones, and puts a/
at the end of directories.grep -v /
inverts results ofgrep /
, so that no directory is included."^\..*/$"
matches everything that start with.
and end in/
..
and..
directories from results of the second part, you can use-A
option instead of-a
forls
, or if you like to work with regex, you can use"^\.[^.]+/$"
instead of"^\..*/$"
.Have fun!