1

When i am about to change my file permission like this

 $ sudo chmod a+x *.* 

This error appear

 chmod: cannot access ‘*.*’: No such file or directory

And when i want to change the permission of every single file in a directory with

 $ sudo chmod a+x directory/* 

The same error appear

 chmod: cannot access ‘directory/*’: No such file or directory

When i try the same command in other directory it works but under this directory /var/www/html it does not work but even when i change the permission file by file to a+x when i run

 ls

A permission error appear

 ls: cannot open directory .: Permission denied
1
  • Could you edit your question and add namei -mo /var/www/html command output? – Lety Dec 14 '14 at 22:12
3

The file extension in Linux is nothing special, it is just a part of the file name. The file globbing of the the shell uses * for all characters so you can just use chmod a+x * instead of .

1
  • This is right if in folder are not present file like foo.bar, and it seems that command sudo chmod a+x directory/* fails due to wrong directory or the directory is empty. @UweBurger if you want you can add this comment in your answer. – Lety Dec 14 '14 at 21:49
1

The ls issue sounds like you might not have sufficient privileges on the directory. As https://stackoverflow.com/a/15800917/3501748 states: directories need the execute permission set in order to see their contents.

cd back a level and see what the permissions are on the directory you have just come from. sudo does not give you any rights to access a folder if root does not have any rights to that folder. Maybe sudo -u <username> might help.

If you need to recurse through the directory tree below your starting point use chmod -R.

2
  • Probably ls command fail because folder is executable (user can cd in it) but not readable by the user. – Lety Dec 14 '14 at 22:07
  • You should advise user to be careful using chmod -R, this command is dangerous and can break system if it is executed with wrong parameter and sudo right. – Lety Dec 14 '14 at 22:08
1

First, I'd like to acknowledge existing answers:

  • As UweBurger says one uses * for a general wildcard in Ubuntu (or, I believe, Unix in general). (Is it possible that directory in your example is empty, causing the error chmod: cannot access ‘directory/*’: No such file or directory?)
  • As northern-bradley suggested, one can use the R flag in chmod to make it traverse the tree recursively, changing the permissions of everything under your current point. That is, use chmod -R directory, or if you lack privileges sudo chmod -R directory (however, do be sure not to inadvertently change permissions on system files when using sudo to chmod; your own user simply lacks privileges to do so, making the first variant safer).

However, I'd like to add that you might not want to change directories' permissions in the same manner you do files'. As explained in the official documentation, the read (r) permission for directories means being able to view its contents (such as using ls), the write (w) permission allows a user to create/remove files in it, and the execute (x) permission to cd inside. There's a great answer here suggesting a method to distinguish between files and directories when applying new permissions recursively. The variant using xargs is supposedly faster. You might wish to add the r flag to xargs to avoid an error in case find returns nothing, and if you need root privileges you should use sudo for both halves of the pipe (again, exercise care when chmoding as root), so that would be:

sudo find [path/to/dir] -type d -print0 | sudo xargs -0r chmod [desired-dir-permissions]

sudo find [path/to/dir] -type f -print0 | sudo xargs -0r chmod [desired-file-permissions]

where [desired-*-permissions] can be given explicitly (777) or using letters (like a+x).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.