Bizzard's Hackshop
Always under construction!
6th
Sep
2012

Change Linux File Permissions Recursively via Command Line

Change permissions of files and directories separately in GNU/Linux using command line.
For Directories:

find location -type d -print -exec chmod 755 {} \;

For Files:

find location -type f -print -exec chmod 644 {} \;

Conditional permission changing

find location -type d -perm 777 -print -exec chmod 755 {} \;

Changes all directories(including sub-directories) with 777 permission to 755

Tagged with: , , , ,

4 thoughts on “Change Linux File Permissions Recursively via Command Line

  1. Jishnu says:

    For all files
    chmod -R 755 *

    For all directories.
    chmod -R 755 */

  2. Tried
    chmod -R 755 */
    It changed permissions of all files, not just directories. What I wanted to achieve was to make all files 644 and directories 755, to avoid permission issues with web server.

  3. Jishnu says:

    */ denotes directories in current folder.
    ls -d */ will list directories.

    chmod -R 755 */ and just chmod 111 */ works for me. ( I did check again, right now.)

  4. Here is the issue I face:

    tvm@Bizzard-Laptop ~/Desktop/test $ ls -l
    total 8
    drwxr-xr-x 3 tvm tvm 4096 Sep 7 17:56 1.dir
    -rw-r–r– 1 tvm tvm 0 Sep 7 17:55 1.txt
    drwxr-xr-x 2 tvm tvm 4096 Sep 7 17:55 2.dir
    tvm@Bizzard-Laptop ~/Desktop/test $ ls -l 1.dir/
    total 4
    drwxr-xr-x 2 tvm tvm 4096 Sep 7 17:55 1.1.dir
    -rw-r–r– 1 tvm tvm 0 Sep 7 17:56 1.1.txt
    tvm@Bizzard-Laptop ~/Desktop/test $ chmod -R 777 */
    tvm@Bizzard-Laptop ~/Desktop/test $ ls -l
    total 8
    drwxrwxrwx 3 tvm tvm 4096 Sep 7 17:56 1.dir
    -rw-r–r– 1 tvm tvm 0 Sep 7 17:55 1.txt
    drwxrwxrwx 2 tvm tvm 4096 Sep 7 17:55 2.dir
    tvm@Bizzard-Laptop ~/Desktop/test $ ls -l 1.dir/
    total 4
    drwxrwxrwx 2 tvm tvm 4096 Sep 7 17:55 1.1.dir
    -rwxrwxrwx 1 tvm tvm 0 Sep 7 17:56 1.1.txt
    tvm@Bizzard-Laptop ~/Desktop/test $

    The permissions of files in parent directory is fine, but the file in sub directory got changed.

Leave a Reply