Questions tagged [chmod]

chmod (short for change mode) is a Linux / Unix command used to change permissions of files and directories.

chmod accepts either human readable notation of the octal bitwise mask. The bitwise mask often has the three digits, specifying (from left to right) permissions for the world, group and the owner of the file. The bits (left to right) are read, write, and execute. For instance,

chmod 740 x.sh

makes x.sh viewable, editable and executable for the current owner. The group can view but not change or execute, and the world has no access. This can be verified with ls -l x.sh:

-rw-r--r-- 1 me 11 2013-01-25 09:53 x.sh

Permission flags can also be specified as letters (r - read, w - write, x - execute), using + or - sign to turn them on or off, for all users. For instance

chmod +r-x x.sh

with make x.sh readable for possible users but no longer executable, even for the owner. The write permission that has not been mentioned in the command, will not be revoked form the owner:

-rw-r--r-- 1 me 11 2013-01-25 09:53 x.sh

Chmod also accepts the forth (actually first) digit that sets (left to right) setUID, setGUI and sticky flags. If not specified, it is assumed 0 (no such flags).

If chmod parameter is less than 3 digits, the first owner and then group permissions are assumed zero. The following example sets (probably in an unexpected way) full permissions for the world and no permissions for the user or group:

chmod 7 x.sh
cat x.sh
cat: x.sh: Permission denied
320 questions
762
votes
10 answers

How to recursively chmod all directories except files?

How to chmod 755 all directories but not files (recursively)? Inversely, how to chmod only files (recursively) but no directories?
Olivier Lalonde
  • 10,107
  • 7
  • 29
  • 33
202
votes
5 answers

Linux - How to recursively chmod a folder?

How can I recursively chmod everything inside of a folder? e.g. I have a folder called var which contains many subfolders and files. How can I apply chmod 755 recursively to this folder and all its contents?
Black
  • 7,349
  • 17
  • 40
  • 61
101
votes
4 answers

How to remove executable bit recursively from files (not directories)

When I plug-in an USB stick (FAT) into my Mac or Ubuntu machine, all files have the executable bits set. After having copied the directory structure to my hard disk how do I remove the executable bits recursively just from the files and keep those…
Mike L.
  • 5,617
  • 16
  • 50
  • 69
91
votes
8 answers

Equivalent of chmod to change file permissions in Windows

Is there any Windows equivalent of Linux's chmod to change the permissions of a file?
sunmoon
90
votes
5 answers

How to chown/chmod all files in current directory?

I am trying to change the ownership and permissions of some files (and directories) in the current directory. I tried this: chown username:groupname . ...expecting that it would affect all the files in the current directory, but instead only…
Andrew
  • 14,554
  • 30
  • 70
  • 82
79
votes
7 answers

Using Cygwin in Windows 8, chmod 600 does not work as expected?

I'm trying to change the permissions to my key file key.pem in Cygwin 1.7.11. It has the permissions flags: -rw-rw---- chmod -c 600 key.pem Reports: mode of 'key.pem' changed from 0660 (rw-rw----) to 0600 (rw-------) However: ls -l key.pem…
Castaa
  • 980
  • 3
  • 9
  • 11
74
votes
3 answers

Chmod to allow read and write permissions for directory

I have created directories in root. I am looking for the chmod command to allow all users read and write permissions to a specific directory. I have done chmod 775 for a file but I need this for a directory. This includes permissions on all files…
chrisg
  • 843
  • 1
  • 6
  • 6
59
votes
5 answers

What is the meaning of "chmod 666"?

I am using Linux. What is the meaning of chmod 666?
Seno
  • 765
  • 3
  • 13
  • 23
52
votes
3 answers

Do I really need recursive chmod to restrict access to a folder?

If I want to restrict access to a folder secret on a shared machine, do I really need recursive chmod on the folder chmod -R g=,o= secret or is chmod on the folder sufficient? chmod g=,o= secret What's the practical difference?
clemisch
  • 629
  • 5
  • 12
49
votes
4 answers

Find all files on server with 777 permissions

I'm looking for a Linux command to go through all the directories on my server and find all files with 777 permission. The output would be a list of all those files with full path.
bartclaeys
46
votes
2 answers

Allow specific user permission to read/write my folder

I have a folder /home/samantha/folder that I want to share with the user tom. He can read/write the folder. How do I do that? chown wouldn't do it because I still want to be able to be the owner of the folder. I don't see how to do this with chmod…
Zenet
  • 685
  • 1
  • 7
  • 14
45
votes
3 answers

How can I do a recursive chmod only on directories?

I want to change permissions on a tree on Centos 4 to add execute permissions for all directories recursively from a directory. If I use normal chmod, files other than directories are also modified: chmod -R o+x /my/path/here How can I only affect…
WilliamKF
  • 7,778
  • 34
  • 103
  • 145
44
votes
4 answers

"chmod" doesn't work

I wrote a /bash script and to execute it I decided to set all the rights, so I tried chmod 777 * //I had 3 text files in the directory, so that's ok Then to check the result I typed ls -l But the rights hadn't changed at all. I haven't got any…
hrust
  • 543
  • 1
  • 4
  • 11
38
votes
4 answers

How to chmod and chown hidden files in Linux?

How do I recursively execute chmod or chown for hidden files? sudo chmod -R 775 * does not work on hidden files. The same thing goes for sudo chown -R user:group.
36
votes
3 answers

Creating files and directories with a certain owner (user/group) while sudoing

I need to wget something (results in a compressed file in cwd), then I have to extract it, then do some copy/move/modification stuff and perhaps finally execute an script (from the downloaded archive). Now all these task either directly (wget,…
Ashkan Kh. Nazary
  • 461
  • 1
  • 4
  • 5
1
2 3
21 22