How to find a hidden file

I have several files, they are called such

.abc efg.txt 
.some other name has a dot in front.txt
......

and I want to do something like this

for i in `ls -a` ; do echo $i; done;

i expected result should be

.abc efg.txt
.some other name has a dot in front.txt

but the noise of the mess turns out. how can i get a hidden file ???

thank

+3
source share
3 answers

Instead of using, lsuse shell pattern matching:

for i in .* ; do echo $i; done;

If you want all files, hidden and normal, to execute:

for i in * .* ; do echo $i; done;

( , . .., , , , , () , * .*)

bash , , dotglob nullglob. dotglob * ( . ..), nullglob *, . :

shopt -s dotglob nullglob
for i in * ; do echo $i; done;
+4

. .., :

find . -name ".*" -type f -maxdepth 1 -exec basename {} ";"

, . - , echo, exec.

for fname in .*; do echo $fname; done; . ...

+2

To find hidden files, use find:

find . -wholename "./\.*"

To exclude them from the result:

find . -wholename "./\.*" -prune -o -print

And another way to handle entire files with spaces is to treat them as strings:

ls -1a | while read aFileName
do
  echo $aFileName
done
+1
source

Source: https://habr.com/ru/post/1781094/


All Articles