To View Permissions
To list permission of each file in a directory, in this example /var
:
ls -l /var
Output:
total 48
drwxr-xr-x 2 root root 4096 Feb 8 06:25 backups
drwxr-xr-x 13 root root 4096 Oct 22 00:29 cache
drwxrwxrwt 2 root root 4096 Aug 13 17:32 crash
To list file permissions for filename.txt
:
ls -l filename.txt
Output:
-rw-r--r-- 1 root root 0 Jan 29 2018 filename.txt
To list directory permissions for /var
:
ls -ld /var
Output:
drwxr-xr-x 15 root root 4096 Apr 23 12:03 /var
To list permissions files in a folder including hidden files.
ls -la /var
To list file permissions in a folder with human readable file size:
ls -lh /var
Output:
total 52K
drwxr-xr-x 2 root root 4.0K Apr 9 08:52 backups
drwxr-xr-x 11 root root 4.0K Jan 29 2018 cache
drwxrwxrwt 2 root root 4.0K Apr 27 2019 crash
Changing Permissions
Single File or Folder
To change permissions of file to 644
for example:
sudo chmod 664 foo.txt
To change permissions of directory to 755
for example:
sudo chmod 755 /path/to/directory/
All Files
To change all files recursively to 644
.
sudo find /path/to/directory/ -type f -exec chmod 644 {} \;
All Folders
To change all directories recursively to 755
.
sudo find /path/to/directory/ -type d -exec chmod 755 {} \;
Changing Owner/Group
Change Owner/Group of a File
sudo chown username:groupname filename.txt
Change Owner/Group of All Files/Directories
To change the owner and group of all files and directories recursively within a directory.
sudo chown -R username:groupname /path/to/directory/*
To change the owner and group of a directory, and all the files and directories within it recursively.
sudo chown -R username:groupname /path/to/directory*
Permission Groups
Each file and directory has three user based permission groups:
- owner – The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
- group – The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
- all users – The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.
Permission Types
Each file or directory has three basic permission types:
- read – The Read permission refers to a user’s capability to read the contents of the file.
- write – The Write permissions refer to a user’s capability to write or modify a file or directory.
- execute – The Execute permission affects a user’s capability to execute a file or view the contents of a directory.
Numeric Meanings
Numeric | Readable | Explanation |
0 | — | No access. |
1 | –x | Execute access. |
2 | -w- | Write access. |
3 | -wx | Write and execute access. |
4 | r– | Read access. |
5 | r-x | Read and execute access. |
6 | rw- | Read and write access. |
7 | rwx | Read, write and execute access. |
Common File Permissions
Setting | Numerical | Owner | Group | Others |
---|---|---|---|---|
-rw——- | 600 | Read/Write | ||
-rw-r—– | 640 | Read/Write | Read | |
-rw-r–r– | 644 | Read/Write | Read | Read |
-rw-rw-r– | 664 | Read/Write | Read/Write | Read |
-rwx—— | 700 | Read/Write/Execute | ||
-rwxr-xr-x | 755 | Read/Write/Execute | Read/Execute | Read/Execute |
-rwx–x–x | 711 | Read/Write/Execute | Execute | Execute |
-rw-rw-rw- | 666 | Read/Write | Read/Write | Read/Write |
-rwxrwxrwx | 777 | Read/Write/Execute | Read/Write/Execute | Read/Write/Execute |
Common Directory Permissions
Setting | Numerical | Owner | Group | Others |
---|---|---|---|---|
drwx—— | (700) | Read/Write/Execute | ||
drwxr—– | (750) | Read/Write/Execute | Read | |
drwxr-xr-x | (755) | Read/Write/Execute | Read/Execute | Read/Execute |
drwxrwx— | (770) | Read/Write/Execute | Read/Write/Execute | |
drwxrwxr-x | (775) | Read/Write/Execute | Read/Write/Execute | Read/Execute |
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
Cant I just grant root to a user and limit there ability to do anythi9ng administrative?
bassicly I want my second user to be able to access anything and everything but not be able to make system changes on need to remember my password.
Hello,
I am on Ubuntu 20.04, gnome, newcomer from 30 years using Windows.
I setup a backup of my own folders using rsync, Cron scheduler.
I can see the folders and files that were created on the external SD card using terminal command line.
But, gnome file manager shows me an empty folder only. Also tried PCManFM, same thing, can’t see the resulting backup.
Maybe you can tell me what to do…
Cheers
Alex
Hi.
I’m really struggling here.
All my files have 777 permissions. I cannot figure out how to view/open the files.
Everytime I try to open them in windows it will say there is no program to view.
In Ubuntu terminal I can’t seem to view it in any way.
Any ideas?
Thank you
Dave
Who is the owner and group of the files and parent directory? You can find out with:
ls -la /path/to/directory
You may have to change the ownership of the files and directory to your own username and group.
sudo chown -R username:groupname /path/to/directory*