I have a directory called pub on a Ubuntu 20.04 server, that I wish to protect from deletion, and I found https://askubuntu.com/questions/504151/how-to-prevent-directory-from-being-deleted-by-user so I tried:

$ sudo chattr +i pub

Good enough, now I want to check if that attribute has been set:

$ lsattr pub
--------------e----- pub/__pycache__
--------------e----- pub/file1.py
--------------e----- pub/file2.py
--------------e----- pub/file3.py
--------------e----- pub/file4.py

So, I got the contents of the directory listed, but I did not get the directory listed, which is what I wanted.

I mean, if it at least gave me an entry for pub, I would have been fine - but here I get all the children and NOT what I requested for... it is so amazingly stupid.

Turns out, there is lsattr -R switch for "recursive", which I've expected to provide output like above - but when I run it, it simply also descends into __pycache__ directory.

So, how do you lsattr a directory only, so you can see if you achieved the right thing with chattr?

1 Answer 1


Use -d, which lists directories like other files instead of listing their contents:

lsattr -d pub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.