Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
man chown and man chmod easily answer your question. – Shi Aug 15 '12 at 21:08
@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
@djf: chown -R user:group . – Shi Aug 16 '12 at 20:05
up vote 50 down vote accepted

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.

share|improve this answer
Ah, the asterisk. Thanks! – Andrew Aug 15 '12 at 20:55
@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
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. – Tom Apr 9 at 19:34

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 *

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .