I want to list all hidden files and directories and then save result to file.
Is there any command for this?
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 communityI want to list all hidden files and directories and then save result to file.
Is there any command for this?
If using GNU find, you can do
find /path -path '*/.*' -ls | tee output-file
Edit
To avoid to show non-hidden items contained in hidden directories
find /path -name '.*' >output-file
(as noted, tee
could be avoided if you do not need to see the output, and -ls
option should be used only if required).
>
instead of | tee
, if one doesn't want to see the whole output on the terminal.
– rozcietrzewiacz
Aug 7 '11 at 13:25
-ls
on this, that might be extra messy information to parse thought.
– Caleb
Aug 7 '11 at 17:03
-path
is POSIX since 2008. -ls
is not standard but quite common.
– Stéphane Chazelas
Aug 25 '15 at 13:34
To list the hidden files and directories in the current directory, including .
and ..
:
echo .*
To list the hidden files and directories in the current directory and its subdirectories recursively:
find . -name '.*'
If you want to save the results to a file, use a redirection:
find . -name '.*' >output-file.txt
With zsh
(using the glob qualifier D
):
print -rl ./**/.*(D)
To include non-hidden files in hidden directories:
setopt extendedglob
print -rl ./**/*~^*/.*(D)
You can actually put the same argument multiple times in the same command line:
find /storage/????-????/ -iname '.*' -iname "*" | tee -a file-list-micSD-20190801163729.fli
The tee -a
command is able to display the command's output (or stdout) simultaneously whie writing it to a file. The -a
options prevents clobbering and does append the information to the target output file instead.
/storage/????-????/
is an example path. It is the path to the MicroSD card of newer Android Mobile phones (there is also a terminal application for Android, with fewer commands but still many and significantly increased since Android 6.0). The MicroSD card was formerly /storage/extSdCard
. Now, it is the volume serial number.