I tried to display only hidden files but don't know how to do it.
That is working (but matching also dots in other places)
ls -la | grep '\.'
Was trying adding
^ but didn't find the solution.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
ls -ld .* will do what you want.
find . -type f -name '\.*' -print
Must work if you want list every hidden file down in the directory hierarchy.
Here are two other ways to find hidden files only.
find . -maxdepth 1 -name ".*" -type f -ls
find . -maxdepth 1 -name ".*" -type f -printf "%P \n"
-maxdepth to specify how far you want to search in the directory tree.
If you want to parse
ls output, you must add
^ at beginning of regex and don't use
-l option. Using
-l causes each line output start with file or folder permission information, not file or folder name. So you should use like this:
ls -Ad | grep '^\.'
Or you can do with
printf bash builtin:
printf "%s\n" .*
If you use
zsh, you can use:
print -l .*
An improvement on Flup's answer:
ls -lad .[!.]* ..?*
This will list all files whose name starts with a dot and that are neither
Note that if you want to pipe the output of
grep (which, as pointed out by devnull, is never a good idea), make sure you use
command ls because if
ls is aliased to show you colored output (as it is on Debian for example), its output contains ANSI escape sequences to create colored output, which will trip up your
grep if its pattern is anchored at the start of line.
The solution of val0x00ff is really good, but it forgets hidden directories.
If you want hidden files and hidden directories, without . and .. :
find -maxdepth 1 -regex '\./\..+' -printf "%P\n"
You can try :
ls -a |grep -E "^\."
^ indicates it's the beginning of content with regexp
Below one is much compact and support many variants
1) Display hidden files, directories and sub-directories
find . | grep "^\./\."
2) Display hidden directories and sub-directories only
find . -type d | grep "^\./\."
3) Display hidden files only in current and sub-directories
find . -type f | grep "^\./\."
4) Display hidden files and directories in current folder
find . -maxdepth 1 | grep "^\./\."