Wednesday, February 6, 2008

Fixing the root user's ls command to not show hidden files

Hidden files in Linux are preceded by a dot. For example, a user's home directory is usually full of hidden directories like .ssh, .mozilla, .gnome, and many more.

One really annoying thing that is unique to SUSE (as far as I know), is the fact that the ls command, when run as root, shows hidden files by default. This "feature," exists because of the alias ls='ls $LS_OPTIONS'. In /etc/bash.bashrc you will see the following snippet of code:


if test "$UID" = 0 ; then
LS_OPTIONS="-A -N $LS_OPTIONS -T 0"
else
LS_OPTIONS="-N $LS_OPTIONS -T 0"
fi

The $UID variable has been set to equal the user ID (UID). For root the UID is 0. According to the above code, if "ls" is typed as root, the command that actually gets executed is "ls -A -N $LS_OPTIONS -T 0."

Simply removing the "-A" from the code snippet above (found in /etc/bash.bashrc) will make it so hidden files are not displayed when the root user runs the ls command.

1 comment:

knocte said...

Fortunately many applications are already switching to use a common .config folder (and put their subfolders beyond that level), like Banshee or MonoDevelop ;)