FactorPad
Build a Better Process

Linux chmod Command Summary with Examples

Linux chmod allows you to change file permissions
  1. Purpose - Learn what chmod is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with chmod.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux chmod, 75 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / chmod-command.html


An ad-free and cookie-free website.


Examples of the Linux chmod Command

Beginner

Learn to change file and directory permissions at the Linux command line.

Video Tutorial

Videos can also be accessed from the YouTube Linux Essentials Playlist on YouTube.

Linux chmod Command Summary with Examples (4:10)

Video Script

The Command and Why You Need It

Our seventy-fifth word, or command to memorize is chmod from our category Users.

chmod allows you to change file permissions.

Common Linux chmod Options
-options description
-h, --help Print help screen
-R, --recursive Apply to files within directories recursively

Recall from the file listing ls command, we've seen permissions, and in this video on file mode, as in change mode, chmod we'll kick off a set of videos on the topic covering users, then groups and then the world.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The chmod command has only 9 options, the first argument is the mode to change, followed by the file or list of files.

Like most commands, help is available with double-dash --help. The -r option applies changes of directories recursively.

So why is chmod an important command? Well, in Linux, unlike other operations systems, file permissions are given more importance, so you'll need to grasp how to make these changes. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's start with a directory listing.

$ ls stuff video23.txt video34.txt video40.txt video57.txt video69b.txt video72.zip video05.txt video24.txt video35.txt video44.txt video64.txt video69b.txt.gz video73a.txt video11.txt video26.txt video36.txt video48a.txt video65.txt video70.txt video73.tar video16.txt video27.txt video37.txt video48b.txt video67.txt video70.txt.bz2 video19.txt video31.txt video38a.txt video54.txt video68a.txt video71.txt video20.txt video32.txt video38b.txt video55.txt video68b.txt video71.txt.xz video21.txt video33.txt video38c.txt video56.txt video69a.txt video72

Thanks for sticking with it, if have been here from the start, we have been busy.

I've used a convention like ls -og to keep the display here simple.

$ ls -og drwxr-xr-x 2 4096 Oct 14 -rw-r--r 1 176 Oct 04 18:14 video05.txt -rw-r--r 1 100 Oct 10 18:42 video11.txt -rw-r--r 1 0 Oct 09 21:16 video16.txt -rw-r--r 1 45 Oct 12 10:11 video19.txt -rw-r--r 1 149 Oct 12 16:10 video20.txt -rw-r--r 1 31 Oct 13 10:11 video21.txt -> ../ridiculouslylongfilename.txt -rw-r--r 1 86 Oct 13 19:40 video23.txt -rw-r--r 1 86 Oct 14 18:57 video24.txt -rw-r--r 1 1203 Oct 15 13:17 video26.txt -rw-r--r 1 1259 Oct 15 20:05 video27.txt -rw-r--r 1 352 Oct 17 21:17 video31.txt -rw-r--r 1 362 Oct 18 12:26 video32.txt -rw-r--r 1 594 Oct 18 16:27 video33.txt -rw-r--r 1 247 Oct 18 18:15 video34.txt -rw-r--r 1 247 Oct 19 14:36 video35.txt -rw-r--r 1 247 Oct 20 12:01 video36.txt -rw-r--r 1 59 Oct 20 17:06 video37.txt -rw-r--r 1 306 Oct 21 07:10 video38a.txt -rw-r--r 1 245 Oct 21 07:23 video38b.txt -rw-r--r 1 395 Oct 21 13:07 video38c.txt -rw-r--r 1 149 Oct 22 13:27 video40.txt -rw-r--r 1 145 Oct 24 14:19 video44.txt -rw-r--r 1 2678 Oct 26 15:49 video48a.txt -rw-r--r 1 114705 Oct 26 15:49 video48b.txt -rw-r--r 1 5451 Oct 29 14:43 video54.txt -rw-r--r 1 5171 Oct 29 17:30 video55.txt -rw-r--r 1 4581 Oct 30 13:33 video56.txt -rw-r--r 1 2161 Oct 30 16:26 video57.txt -rw-r--r 1 51054 Nov 3 15:17 video64.txt -rw-r--r 1 1877 Nov 3 22:05 video65.txt -rw-r--r 1 3364 Nov 4 15:23 video67.txt -rw-r--r 1 17742 Nov 5 14:04 video68a.txt -rw-r--r 1 17742 Nov 5 14:04 video68b.txt -rw-r--r 1 17752 Nov 5 19:15 video69a.txt -rw-r--r 1 17752 Nov 5 19:15 video69b.txt -rw-r--r 1 6366 Nov 5 19:15 video69b.txt.gz -rw-r--r 1 17752 Nov 6 10:15 video70.txt -rw-r--r 1 5859 Nov 6 10:15 video70.txt.bz2 -rw-r--r 1 17752 Nov 6 16:07 video71.txt -rw-r--r 1 6112 Nov 6 16:07 video71.txt.xz -rw-r--r 1 4096 Nov 6 19:24 video72 -rw-r--r 1 48385 Nov 6 19:24 video72.zip -rw-r--r 1 14920 Nov 7 11:34 video73a.txt -rw-r--r 1 20480 Nov 7 11:42 video73.tar

And video7* just to show a set, instead of all the files we've been working on.

$ ls -og video7* -rw-r--r-- 1 17752 Nov 6 10:15 video70.txt -rw-r--r-- 1 5859 Nov 6 10:15 video70.txt.bz2 -rw-r--r-- 1 17752 Nov 6 16:07 video71.txt -rw-r--r-- 1 6112 Nov 6 16:07 video71.txt.xz -rw-r--r-- 1 48385 Nov 6 19:24 video71.zip -rw-r--r-- 1 14920 Nov 7 11:34 video71.txt -rw-r--r-- 1 20480 Nov 7 11:42 video71.tar video72: total 144 -rw-r--r-- 1 93424 Nov 6 19:23 video72a.txt -rw-r--r-- 1 53014 Nov 6 19:23 video72b.txt

So, let's dig a bit deeper here and at the left, you can see 10 dashes or letters, the first indicates file type, dash - is for a regular file, d for directory, l for link. Then the permissions in the next set of three for the owner, followed by three for the group, and three for the rest of the world.

Next, let's create a new empty file using touch video75.txt and ls -og video75.txt.

$ touch video75.txt $ ls -og video75.txt -rw-r--r-- 1 0 Nov 8 09:40 video75.txt

For me the mode is read and write rw-, for the group and world it's read only r-- so I'll chmod the group g and add +w for write.

$ chmod g+w video75.txt

And last, verify with an lg -og video75.txt.

$ ls -og video75.txt -rw-rw-r-- 1 0 Nov 8 09:40 video75.txt

The group can now write.

A Final Tip

Okay now you know how to use chmod. And you know the syntax for commands, options and arguments.

One last tip about the chmod command. So we're just kicking off here (with file permissions) and I kept it very simple. We have a few more videos (tutorials) to come on the topic of users and I put a table in the Description (also see the Linux Cheat Sheet) on the modes and two others called octals and binaries, which we'll cover in the next few videos because this is all so very important.

Okay, thanks for visiting today. I hope this was a helpful introduction to the chmod command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Be on the lookout for new videos, subscribe, follow and join.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / chmod-command.html


chmod file permissions
chmod command
linux chmod
chmod linux
chmod permissions
chmod example
linux file permissions
chmod directory
linux permissions
linux file permissions
linux change permissions
chmod folder
file permissions linux
linux change folder permissions
chmod recursive
chmod syntax
change file permissions
man chmod
chmod binary
chmod octal
chmod mode

A newly-updated free resource. Connect and refer a friend today.