The chmod Command
Do you know how to rename a file you can't read? Better yet, do you know how other users can rename your files? Have you ever ftp'd a program from another host and been unable to run it?
The subject of file permissions, and how to manipulate them with the chmod command, is a good place to start learning about these situations.
First, let's create a file and examine its long listing. (In order to fit in the magazine, all the listings in this article are trimmed to fit.)
$ touch test_file $ ls -l test_file -rw-rw-r-- 1 eric users
Since I created this file, it makes sense that the third column shows my user name as the file's owner and that the fourth shows my group. (On some systems, the group name may be the same as the user name.) As you follow along in these examples, you will see your username in place of “eric”.
The leftmost column of the directory listing shows the file's mode. Mode is the term used to refer to a file's permissions. ls displays the file's type and mode together as a grouping of ten one-character fields:
The type field has several valid values. For the sake of this tutorial, we are only concerned with two: empty (-) for a regular file, and d for directories.
The other three columns cover the three classes of access that are stored for each file in a Unix-like file system. Linux (and Unix) evaluates access in terms of user ownership, group ownership and world (or other).
For each of these classes, rights are evaluated in terms of three operations: reading (r), writing (w) and executing (x). The permissions above specify “full” access for the owner, reading and writing for group, and only reading for world (an unusual combination used for demonstration). Those permissions specify that
The owner of the file is allowed to read, write and execute the file.
Any user who is a member of the group that owns the file is permitted to write to the file.
Any other user can only read the file.
If test_file were a very important document that we did not want anyone to be able to modify or delete, we would need to remove write access from group:
$ chmod g-w test_file $ ls -l test_file -rw-r--r-- 1 eric users
We see that the w for group is now replaced with a -, signifying that write permission is denied to members of the group users.
If test_file contained sensitive information that only members of the group users should be able to review:
$ chmod o-r test_file $ ls -l test_file -rw-r----- 1 eric users
Now we see that the last triplet of the mode field, which specifies permissions for world, are all dashes. This means that other users who do not belong to the users group have no permissions to do anything with test_file whatsoever.
The command line usage for chmod mode looks like this:
chmod [options] new-mode filename
The new mode is specified in octal mode or symbolic mode. We'll cover symbolic mode first. In the first example we used g-w to remove write permission for group. As you might be able to guess, g stood for group, - for remove and w represented write permission.
$ chmod g+wx test_file $ ls -l test_file -rw-rwx--- 1 eric users
This operation added permission for group to write and execute.
Let's look at an example of these permissions in action.
$ chmod u-rwx test_file $ ls -l test_file ----rwx--- 1 eric users $ cat test_file cat: test_file: Permission denied $ cat .profile > test_file bash: test_file: Permission denied
We are not able to display the file's contents because we do not have read access to our own file. When we specified u-rwx to chmod, we removed all access for the user (the file's owner). We were also denied permission when we attempted to add the contents of another file to it since we removed write access. (I should note that rm would still be able to delete this file, although it will normally request confirmation.)
$ chmod u+rwx test_file $ ls -l test_file -rwxrwx--- 1 eric users
When we specify u+rwx, all permissions are restored. Removing permissions from a file we own does not affect our ability to restore the permissions, because the mode is not stored in the file. It is stored in a structure called an inode entry. Only the owner of the file (and root) may modify this.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Roll your own dynamic dns
1 hour 30 min ago - Please correct the URL for Salt Stack's web site
4 hours 42 min ago - Android is Linux -- why no better inter-operation
6 hours 57 min ago - Connecting Android device to desktop Linux via USB
7 hours 26 min ago - Find new cell phone and tablet pc
8 hours 24 min ago - Epistle
9 hours 53 min ago - Automatically updating Guest Additions
11 hours 1 min ago - I like your topic on android
11 hours 48 min ago - This is the easiest tutorial
18 hours 23 min ago - Ahh, the Koolaid.
1 day 2 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Re: Take Command: The chmod Command
is it possible to explain the meanings and values of those chmod numbers. e.g chmod 750