How to access a file starting with the period '.' in a shell

Special characters can be distinguished with the backslash character \. However, I want to consider the full period as a regular symbol for working with hidden folders. For instance:

ls -lh .

It will display the current directory. However, I want to list all the hidden folders. I want to be able to use it with du -h , so I know which drive the hidden folders occupy.

+4
source share
3 answers

Files and directories whose names begin with . , are β€œhidden” only in the sense that (a) ls ignores them by default and (b) wildcard expansion excludes them. In both cases, you can see point files if you refer to them explicitly. * Expands to all non-point files; .* extends to all point files.

(Other tools and commands may also treat them as hidden ones, for example, graphic file administrators such as Nautilus usually don’t display dot files by default, but can often be shown.)

ls -a cancels special handling of files whose names begin with . . ls -a lists hidden files and folders, but excludes them . (this directory) and .. (parent directory); some ls versions may not support -A .

The du command, as far as I know, does not treat point files as hidden. du -h should show the complete directory tree, starting from the current directory. (Try in the small directory tree to make sure that you behave this way.)

EDIT:

I have confirmed that at least the GNU coreutils du version does not process files or directories whose names begin with . on purpose; nothing is hidden.

For example, this script:

 #!/bin/sh mkdir -p .dot/.dot .dot/nodot nodot/.dot nodot/nodot du -h 

produces this conclusion on my system (specific numbers depend on the nature of the file system and are not relevant to the current discussion):

 4.0K ./.dot/.dot 4.0K ./.dot/nodot 12K ./.dot 4.0K ./nodot/.dot 4.0K ./nodot/nodot 12K ./nodot 32K . 

Does this fit your requirements? If not, can you explain more clearly what exactly you are looking for? You want to list all directories, whether their names begin with . or not? Do you want to list only "hidden" directories? What result would you like to create for the directory structure created by the above script?

+7
source

Wrong place for this question, but it is simple enough:

ls -lhd .*

+1
source

what about ls -lh .* ? (This may answer your question)

0
source

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


All Articles