Recursively set permissions on directories

The following command will execute a command on a directory and all its sub-directories:

$ find plugins -type d -exec chmod g+w {} \;

In this case, we’re changing the group permissions on the plugins directory and all sub-directories.

 

Update your SELinux policy

If you’ve recently installed an application or applied some patches that begin to generate a lot of SELinux audit entries, you can update your local policy to accommodate your recent changes. Please note that this isn’t a substitute for ensuring your files have the appropriate selinux roles and types.

# grep avc /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
 

I recently came across a command that allows me to search and replace a string of text in all files within a directory structure. This is very useful for updating static information in HTML files and the like.

find ./ -iname \*.htm\* -exec sed -i 's/www\.example\.com/www2\.example\.com/g' {} \;

Note that you must denote special characters with the backslash character (e.g., the dots in www.example.com).

 

Find world writable directories

I recently found myself needing to locate all world writable files in a directory tree and came across the following useful command:

find /var/ -type d -perm -o+w -exec ls -ld {} \;

The syntax may vary depending on the flavour of Unix/Linux you’re using, but this worked on Ubuntu for me.

 

Using rsync over ssh

You can securely synchronize directory structures between two Linux computers by using the following command:

rsync -ave ssh --delete myhost.example.com:Documents/ Documents/

The −−delete option ensures that any files or directories that no longer exist on the source are also removed from the destination.

Tagged with: