-rw—–– ??

ls -la

Since I mainly use the terminal, I use the ls command to check files in the current directory, but occasionally when I need to see all files, I use the ls -la command. A while ago, a question suddenly came to mind.

“What do those things at the beginning of each line mean?”




Permission

rwx

The 10-11 characters at the beginning each have their own meaning, and when broken down separately, they look like this.

The First Character (1 position)

This shows the type of the file.

CharacterTypeMeaning
-Regular fileText, image, program, data files, etc.
dDirectoryFolder
lSymbolic linkShortcut pointing to another file or directory
cCharacter deviceDevices that input/output character by character (terminal, modem)
bBlock device fileDevices that input/output by blocks (hard disk, CD-ROM)

Remaining Access Permissions (next 9 positions)

These are grouped in sets of 3, applied in order to Owner (User), Group, and Others.

PositionPermissionMeaning
rReadCan view file contents or check directory listing
wWriteCan modify file contents or create/delete files in directory
xExecuteCan execute file as a program or access and navigate into directory
-No permissionThe corresponding permission is not granted

So if you see -rw-r--r--, the file or directory has the following permissions:

  • -: Regular file
  • rw-: Owner can read and write
  • r--: Group users can only read
  • r--: Other users can only read




Setting Permissions

chmod

Now let’s set permissions for files or folders. The most common and basic method is using the chmod command. There are two ways to execute this command, which means “change mode”.

1. Octal (Numeric) Notation

This method specifies the final permissions to be granted to the Owner (User), Group, and Others using numbers. It’s the most commonly used and has an intuitive characteristic.

PermissionCharacterOctal Value
Executex1
Writew2
Readr4

You can add the numbers of each permission from the table to create a 3-digit number.

rwx = 4 + 2 + 1 = 7, r-x = 4 + 1 = 5, rw- = 4 + 2 = 6

// Command format
chmod [User][Group][Others] [file-name/directory-name]
// Command format
chmod [User][Group][Others] [file-name/directory-name]
chmod 644 [file-name/directory-name]
chmod 644 [file-name/directory-name]

Commands like chmod 600 ssh-name or chmod 644 ssh-name that you’ve probably used when generating SSH keys also follow this formula. (Applies read and write permissions only to the owner)

When changing directory permissions, if you want to change permissions for all sub-files and directories inside that directory as well, you can use the -R (recursive option).

chmod -R 755 [directory-name]
chmod -R 755 [directory-name]

2. Symbolic (Character) Notation

This method is used when you want to add (+), remove (-), or newly set (=) specific permissions from existing permissions.

Target (Who)Operation (Operator)Permission
u (User)+ (add)r (read)
g (Group)- (remove)w (write)
o (Other)= (set)x (execute)
a (All)

The symbolic notation of chmod can be usefully used when adding or removing specific permissions, such as u+x (add execute permission to owner) or g-w (remove write permission from group).

// Command format
chmod [Who][Operator][Permission] [file-name/directory-name]
// Command format
chmod [Who][Operator][Permission] [file-name/directory-name]
// Example
chmod u+r [file-name/directory-name]
// Example
chmod u+r [file-name/directory-name]

Occasionally when running ls -l, you may see a + after the permission bits, like -rwxr-xr-x+. This is a special indicator that there’s an additional Access Control List (ACL) set through the setfacl command, in addition to the standard permissions (UGO). (e.g., /home/user)




Conclusion

end

Today I wrote briefly about something I looked up when I had questions during my early Linux days. Although the chmod command isn’t frequently used, I added related content thinking you’ve probably encountered it often when setting up SSH.