Friday, May 3, 2024
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 2367  / 2 Years ago, fri, july 8, 2022, 4:11:49

I would like to do something like


ls -RA .?* >> LSRA.list

but with this command and some other variants I tried, I always get also all non-hidden files in the directory where I am.


Namely, if the directory contains files


.hiddenfile foo

with above command I get ther recursive list of both, while I would like to ave only the recursive list of files and directory starting with . (but not the . directory itself!)


I checked answers to this question but I did't find the solution to my problem.


Update: best options found so far:


 ls -RA .!(|.)*

and


 find -path './.*' -name '.*' -empty -printf %Pn

the latter recursively list all hidden files in all hidden directory (so if am hidden directory contains a non-hidden files, it does not show that file).


Further update. both answers of bac0n and vanadium work: I cannot accept both! (first one recursively shows nonhidden files in hidden directory, latter one recursively shows only hidden files)


More From » command-line

 Answers
5

To recursively list only hidden files from a terminal, you can use the tool find with the -type f option:


find ~ -type f -name '.*'

This will find all files in the user's home directory for which the basename starts with a dot, i.e., a hidden file or folder. Remove -type f to list both hidden files and folders, or specify type d to list only hidden directories. Specify any other directory by replacing ~ with a valid pathname. Specify . to list hidden files in the current working directory and below.


[#1880] Sunday, July 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cupwire

Total Points: 365
Total Questions: 126
Total Answers: 125

Location: Malaysia
Member since Thu, Feb 16, 2023
1 Year ago
cupwire questions
Wed, Feb 1, 23, 14:35, 1 Year ago
Fri, Jan 20, 23, 07:19, 1 Year ago
Sun, May 15, 22, 08:53, 2 Years ago
;