In today’s article, and for no apparent reason, we’re going to learn how to disallow directory listing in the terminal. This seems like a good article for beginners to learn, and it seems like something most folks might like to know. So, if you want to disallow directory listing read on!
You never know when you might want some additional privacy, though I’d definitely not confuse this for strong privacy measures like encryption, amongst your files. Perhaps you’re planning on releasing a memo and you don’t want anyone to read it until you’re done?
I dunno? It’s up to you as to why you’d want the potential privacy from making it so that the files in a directory can’t be listed. Your reasons are your own. I just share tidbits of knowledge.
We will be using ‘chmod’ in this exercise. The man page for ‘chmod’ describes itself like:
chmod – change file mode bits
But, for our purposes and generally speaking, it’s used to adjust the file permissions. As you should know, files have various permissions in Linux – and everything in Linux is a file. There are read, write, and executable bits that can be set (with said chmod, for example) and there’s also file ownership (for another day). We’ll be using those permissions to prevent listing the files in a directory.
Ready? It really won’t take long – and it should be easy enough for anyone…
Disallow Directory Listing:
As the title suggests, this is another ‘in the terminal’ application. So, of course, you’ll need an open terminal. You should open a terminal now. If you don’t know how to open the terminal, you can do so with your keyboard – just press
With your terminal now open, let’s first start by making a directory – just so that we can then use that to disallow directory listing. We’ll just do this in your /home directory. Start with:
Now, let’s move to the new ‘sample’ directory and make a couple of files.
touch foo.txt bar.txt
Now, what we’re going to do is change the permissions of the ‘sample’ directory, like so:
chmod 0111 ~/sample
You don’t need ‘sudo’ or anything, because these files belong to you. But, you can now test it. While still in the folder, try any of the following:
Or (from outside the directory, if you’d like):
In all cases, it should give you a ‘permission denied’ error, because you no longer have permission to list files from within that directory.
If you wish to reverse this, you can simply try changing the permissions again. You can just:
chmod 0666 ~/sample
With that command, you can resume directory listing. So, it’s pretty easy to reverse the process. It’s also not the greatest security measure you can take, because of that. So, do what you will with it, as you now know how to disallow directory listing in the terminal.
There you have it, it’s yet another article. This one seemed like an interesting one to write, so I figured I’d write it. You never know when you want to disallow directory listing, but now you know how to do so. If you have any questions, feel free to ask…
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.