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 affected the directory that I am in (which is the opposite of what I want to do). I want to change it on all the files without affecting the current directory that I am in.

How can I chown and chmod all files in current directory?

  • man chown and man chmod easily answer your question. – Shi Aug 15 '12 at 21:08
  • 2
    @Shi I think it's a fair question. Reading that man page wouldn't help. Globbing is not part of chmod. It is builtin to the shell. Also reading documentation on globbing sucks the life out of you (I spent way to much time figuring out all the zsh's features). – djf Aug 15 '12 at 21:27
  • 1
    @djf: chown -R user:group . – Shi Aug 16 '12 at 20:05

You want to use chown username:groupname *, and let the shell expand the * to the contents of the current directory. This will change permissions for all files/folders in the current directory, but not the contents of the folders.

You could also do chown -R username:groupname ., which would change the permissions on the current directory, and then recurse down inside of it and all subfolders to change the permissions.

chown -R username:groupname * will change the permissions on all the files and folders recursively, while leaving the current directory itself alone. This style and the first style are what I find myself using most often.

  • 2
    @Andrew Be on your guard though, he can be both friend and foe to the weary or unprepared. – Darth Android Aug 15 '12 at 21:07
  • 5
    Also, beware of the dangers of the period. As it is placed right next to the almight "/" on the keyboard. A simple typo can easily turn chown -R username:groupname . into chown -R username:groupname /. Making a 2 second task a 2 day nightmare. – teynon Apr 9 '16 at 19:34
  • @Tom That's why I should probably start using -v on all my recursive commands, but too lazy – Kolob Canyon Dec 30 '16 at 19:44

I think you want this:

chown username:groupname *

If you also want to recursively change subdirectories, you'll need the -R (-r is deprecated) switch:

chown -R username:groupname *

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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