Linux / UNIX List User Dot-Files

by on August 26, 2009 · 7 comments· LAST UPDATED August 26, 2009

in , ,

How do I list only user dot-files from $HOME under UNIX and Linux operating systems? How do I ensure that user Dot-Files are not World-writable?

Use the ls command and shell GLOB characters to list only user Dot-Files, enter:

ls -ld /root/.[A-Za-z0-9]*
ls -ld $HOME/.[A-Za-z0-9]*

Sample Outputs:

-rw-r--r--  2 root  wheel  1455 Jun 12 18:47 /root/.cshrc
-rw-------  1 root  wheel  2650 Jul 28 06:26 /root/.history
-rw-r--r--  1 root  wheel   299 Jun 12 18:40 /root/.login
-rw-------  1 root  wheel    57 Jun 12 22:07 /root/.mysql_history
-rw-r--r--  2 root  wheel   260 Jun 12 18:40 /root/.profile

Run chmod command on misconfigured file to remove group- or world-writable permissions, enter:

# chmod go-w $HOME/.dot-file-name

Owners can run the same command to fix permission issue.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 7 comments… read them below or add one }

1 Alexei August 26, 2009 at 6:11 pm

Why not just this command?

ls -ld \.* 

And this?

find ~ -name \.\* -exec chmod go-w {} \;

Reply

2 silvio January 30, 2014 at 2:47 pm

ls -ld \.*
lists ‘.’ and ‘..’ as well. The point here is avoid including these two.

The find command works.

Reply

3 silvio January 30, 2014 at 2:50 pm

ls -ld .[^.]*

think it works

Reply

4 nixCraft August 26, 2009 at 6:21 pm

@ Alexei,

Nice. I almost forgot about find, pipes and xargs :(

Reply

5 oll August 26, 2009 at 7:28 pm

find ~ -name \.\* -exec chmod go-w {} \;
Since I don’t know any dot file or dot directory that contains less than 2 letters, what I do is :
chmod -R go-w ~/.??*
But in a script, Alexei find’s syntax is smarter indeed.

Reply

6 Juan Giordana September 1, 2009 at 9:36 am

find $HOME -maxdepth 1 -iname '.*'
find ~ -maxdepth 1 -iname '.*'

Reply

7 BOUAZIZ MOURAD September 28, 2009 at 7:50 pm

HELLO;I WANT SOME HELPE ABOUT THE SOLARIS COMMANDS

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous Faq:

Next Faq: