Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list only the dot files and dot folder names (without the content in them)

Tags:

linux

shell

ls

I want to list only the files and folders that are hidden (starting with dot). When I use the command

ls .??*

I get the output

.gitignore

.git:
COMMIT_EDITMSG FETCH_HEAD     HEAD           ORIG_HEAD      branches       config         description    hooks          index          info           logs           objects        packed-refs    refs

I don't want the content in the folder. Instead I'm looking for the output which only lists the folders

.gitignore
.git [different color for the folders, like the normal ls]
like image 440
Joe Avatar asked Mar 14 '14 14:03

Joe


People also ask

Can you have dots in folder names?

As far as I know there are no issues with naming folders and files with a single or multiple dots.

How do you list only hidden files?

Display only the hidden files and directories. To display only the hidden files and directories, the simplest approach is to show the hidden files with ls -a and then use grep to filter only the entries that start with a . (dot).


2 Answers

try:

ls -d .*

fyi

   -d, --directory
          list directories themselves, not their contents

if your ls is not alias of other command, the output of above ls -d .* will output files/dirs in same line. If you want to have them each in its own line:

ls -d1 .*

if you want colored output:

ls -d1 --color=auto .*
like image 98
Kent Avatar answered Oct 23 '22 01:10

Kent


ls -d .??*

The -d switch makes ls treat directory arguments just like file arguments, and won’t list its contents, but instead show the usual output (manpage excerpt follows, thanks @fedorqui):

list directory entries instead of contents, and do not dereference symbolic links

It combines well with -l and others, and will, without any further switches, default to the usual multi-column view of ls.

like image 45
Jonas Schäfer Avatar answered Oct 22 '22 23:10

Jonas Schäfer