0

How do I find out the default permissions for a newly created text file? I've tried

ls -l filename.txt

but it keeps saying to me that it cannot access the txt file, so I'm pretty sure that I'm doing it wrong. I've gone over notes and googled but I can't find out how to look at it's default permissions.

  • Can you please include the error message you are receiving? Either you do not have access to run ls in the directory you are in, or the file you want to ls does not exist. – Peschke Oct 20 '15 at 0:21
  • Sorry, specifically its saying ls: cannot access filename.txt: No such file or directory. But i created the text file using vi filename.txt – jestermonkey Oct 20 '15 at 0:23
  • 1
    @jestermonkey the file is not created until you save in vi (:w) – jordanm Oct 20 '15 at 0:39
0

As jordanm stated in a comment above, vi does not write a file until you use the write command :w.

If you are unsure how to write the file, I would recommend creating a file with either touch filename.txt or >filename.txt. Now you can see the default permissions of a newly created file with ls -l filename.txt

| improve this answer | |
0

What controls the default permissions is known as the umask.

BUT....

It depends on how the file was created, because various daemons can be configured to use a different default umask. So creating a file by a samba/cifs share, or via sftp, or by logging in interactively and using touch or creating a new file by saving in some text editor like vi or joe or whatever can all end up with different permissions, even if the files are created by the same user in the same directory.

In the same vein, there is also the ownership of files/directories created. The system default is probably the owner is the creating user and the group is the creating user's primary group. But be aware that other file permissions can affect this (ie, the setgid bit on a directory) as well as various daemon configuration options just like the umask setting.

| improve this answer | |
-2

Write

ls -l

And you will see, something like:

drwxrwxr-x  3 username username     4096 lip 28 01:20 filename.txt

The values may of course differ, and there likely will be a many lines like these for different files. What you look for is the drwxr.... information which tells you about permissions.

Here you have their meanings.

| improve this answer | |
  • the key word in the question here is default permissions, not resulting permissions. – Jeff Schaller Aug 27 '17 at 17:32

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.