Linux File Permissions

File Permissions
Every file on the system has associated with it a set of permissions. Permissions tell UNIX what can be done with that file and by whom. There are three things you can (or can’t) do with a given file:

  • r : read it,
  • w : write (modify) it and
  • x : execute it.

$ chmod [options] mode file(s)

chmod a-x file

This means that the execute bit should be cleared (-) for all users. (owner, group and the rest of the world) The permissions start with a letter specifying what users should be affected by the change, this might be any of the following:

  • u – the owner user
  • g – the owner group
  • o – others (neither u, nor g)
  • a – all users

This is followed by a change instruction which consists of a +(set bit) or -(clear bit) and the letter corresponding to the bit that should be changed.
Every one of the three digits on the mode number corresponds to one of the three permission triplets. (u, g and o) Every permission bit in a triplet corresponds to a value: 4 for r, 2 for w, 1 for x.

Triplet for u: rwx => 4 + 2 + 1 = 7
Triplet for g: r-x => 4 + 0 + 1 = 5
Tripler for o: r-x => 4 + 0 + 1 = 5
Which makes : 755

So, 755 is a terse way to say ‘I don’t mind if other people read or run this file, but only I should be able to modify it’ and 777 means ‘everyone has full access to this file’

Change multiple folder and file permissions recursively
$ chmod 755 'Folder' -R

Change multiple folder and file owner and Group recursively
chown user:group 'Folder' -R

Useful Linux Terminal Commands

Here are some useful and helpful commands which is generally used in day to day workings on the Linux system. Following commands were tested on the Ubuntu/Debian Linux.

To fix the broken packages
$ sudo apt-get install -f


Removing automatic installed packages
$ sudo apt-get autoremove


Check Gnome Shell version
$ gnome-shell --version

Current Kernel Version
uname -r


Compress PDF file using ghostscript
$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf


Open help and options info of a command
$ man <command>


Short help info of any command
$ <command> --help


Make ISO of A Directory
An ISO of a directory containing files and sub-directories can be made using this command.
mkisofs -o image.iso -R /path/to/folder/

Force Kill Application
Run following terminal command then click the application’s window to close it.
xkill


Logout without prompt
$ pkill -KILL -u $USER


Create an ISO image of CD/DVD
sudo cat /dev/sr0 > foo.iso