How to View File and Folder Permissions in Ubuntu Linux Command Line

Last updated on

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

NumericReadableExplanation
0No access.
1–xExecute access.
2-w-Write access.
3-wxWrite and execute access.
4r–Read access.
5r-xRead and execute access.
6rw-Read and write access.
7rwxRead, write and execute access.

Common File Permissions

SettingNumericalOwnerGroupOthers
-rw——-600Read/Write  
-rw-r—–640Read/WriteRead 
-rw-r–r–644Read/WriteReadRead
-rw-rw-r–664Read/WriteRead/WriteRead
-rwx——700Read/Write/Execute  
-rwxr-xr-x755Read/Write/ExecuteRead/ExecuteRead/Execute
-rwx–x–x711Read/Write/ExecuteExecuteExecute
-rw-rw-rw-666Read/WriteRead/WriteRead/Write
-rwxrwxrwx777Read/Write/ExecuteRead/Write/ExecuteRead/Write/Execute

Common Directory Permissions

SettingNumericalOwnerGroupOthers
drwx——(700)Read/Write/Execute  
drwxr—–(750)Read/Write/ExecuteRead 
drwxr-xr-x(755)Read/Write/ExecuteRead/ExecuteRead/Execute
drwxrwx—(770)Read/Write/ExecuteRead/Write/Execute 
drwxrwxr-x(775)Read/Write/ExecuteRead/Write/ExecuteRead/Execute
1 Star2 Stars3 Stars4 Stars5 Stars 4.60 (5 votes)

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

4 replies

avatar
  Subscribe  
newest oldest
Notify of
James
Guest
James
James
11 days ago

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.

Alex Evans
Guest
Alex Evans
Alex Evans
6 months ago

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

Dave
Guest
Dave
Dave
9 months ago

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