Linux file management

Main commands

List file(s) permissions: ls -la <filename/wildcard>

Following commands with -R mean recursive action along the directory tree.

Set file(s) permissions: chmod <object><modifier><digits/symbols> <filename/wildcard>
<object> (if no – set every field): u – owner; g – owners group; o – others;
<modifier>: ‘+’ – set; ‘-‘ – reset;

Set owner: chown <new owner> <filename/wildcard>
Set group ownership: chgrp <new group> <filename/wildcard>

Permissions designations:

Digits Symbols Description (files/folders)
0 no permissions
1 –x execute / get metadata
2 -w- write / modify (with –x only)
4 r– read / get files list
The mask byte: sum of mask numbers.

Permissions structure

owner (user) | owners group | others,
e.g. 7(4+1+2) 6(4+2) 4(4); symbols -rwxrw-r–

The tirck: here are different requirements for files and folders. Files have mostly no eXecutable attribute, but directories (folders) have to have this attribute set, another way it is not allowed to enter it at all. To be more fast with automatic separation of files and directoties, the commands below are useful.

Attention: it works recursively, DO NOT RUN IT ON / OR ANY SYSTEM DIRECTORY: all the files will get unexecutable and system may lost controlability at all.

find . -type f -exec sudo chmod 664 {} \; -exec echo {} \;
find . -type d -exec sudo chmod 775 {} \; -exec echo {} \;

This opens files and folder for full access for the owner and his groups and add X attribure to folders only, not for files.

This entry was posted in cheatsheet, linux and tagged . Bookmark the permalink.