The Directory Management Challenge
When restructuring a web server in Ubuntu Linux, you frequently need to execute bulk permission changes that apply only to folders and strictly ignore the files contained within them. For example, a standard WordPress installation requires all directories to possess 755 permissions, while all files must strictly remain at 644. If you run a blanket chmod -R 755, you will instantly compromise the security of every single file in the hierarchy. You must combine the filtering power of find with the execution engine of -exec to surgically target folders.
Using the find Command with -type d and -exec
The Linux find command allows you to stack the -type d (Directory) filter directly onto the -exec action flag to isolate structural nodes.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To scan the
/var/www/html/directory and applychmod 755exclusively to the folders, type the following command exactly: find /var/www/html/ -type d -exec chmod 755 {} \;- Press Enter.
Targeted Execution Forensics
The syntax processes left to right. First, -type d evaluates the filesystem and completely discards any node that is a file, symlink, or socket. Only true directories are passed down the chain. The -exec flag then takes that filtered list and injects the directory paths one by one into the {} placeholder, running the chmod 755 command. Finally, the \; terminates the execution string. This command is an absolute necessity for system administrators repairing broken permission matrices on complex web application stacks.