Special characters can be distinguished using backslash character \ . However, I want to treat full period as a normal character to operate on hidden folders. For example:
ls -lh .
It will list the current directory. However, I want to list all the hidden folders. I want it to be usable with du -h
, so I know the disk space the hidden folders consumed.
Also, keep these rules in mind. Don't start or end your filename with a space, period, hyphen, or underline. Keep your filenames to a reasonable length and be sure they are under 31 characters.
Move Cursor on The Command LineCtrl+A or Home – moves the cursor to the start of a line. Ctrl+E or End – moves the cursor to the end of the line.
The dot command ( . ), aka full stop or period, is a command used to evaluate commands in the current execution context. In Bash, the source command is synonym to the dot command ( . ) and you can also pass parameters to the command, beware, this deviate from the POSIX specification.
In Unix-like operating systems, any file or folder that starts with a dot character (for example, /home/user/. config), commonly called a dot file or dotfile, is to be treated as hidden – that is, the ls command does not display them unless the -a or -A flags ( ls -a or ls -A ) are used.
Files and directories whose names start 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 dot files if you refer to them explicitly. *
expands to all non-dot files; .*
expands to all dot files.
(Other tools and commands may also treat them as hidden; for example, GUI file managers like Nautilus typically don't show dot files by default, but there's often an option to show them.)
ls -a
overrides the special treatment of files whose names start with .
. ls -A
lists "hidden" files and folders, but excludes .
(this directory) and ..
(the parent directory); some versions of ls
might not support -A
.
The du
command, as far as I know, doesn't treat dot files as hidden. du -h
should show the entire directory tree starting at the current directory. (Try it in a small directory tree to make sure yours behaves this way.)
EDIT :
I've confirmed that at least the GNU coreutils version of du
doesn't treat files or directories whose names start with .
specially; nothing is hidden.
For example, this script:
#!/bin/sh
mkdir -p .dot/.dot .dot/nodot nodot/.dot nodot/nodot
du -h
produces this output on my system (the specific numbers depend on the nature of the file system, and are irrelevant 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 that meet your requirements? If not, can you explain more clearly just what you're looking for? Do you want to list all directories, whether their names begin with .
or not? Do you want to list only "hidden" directories? What output would you like for the directory structure created by the above script?
Wrong place for this question, but it's simple enough:
ls -lhd .*
what about ls -lh .*
? (This may answer you question)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With