Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Find Command with Multiple Exec Statements

Submitted by on February 10, 2011 – 12:32 am 2 Comments

This is a very simple one, but somehow I always forget the correct syntax. I want to use the “find” command to locate files and then use several “exec” statements to perform various operations on whatever “find” finds. In the following example I am making sure that all /etc/*.conf files are owned by “root:root” and that they don’t have permissions greater than 644. So here we go…

find /etc -type f -name "*.conf" -exec chown root:root {} ; -exec sh -c '
	if [ `stat -c "%a" "{}"` -gt 644 ]
	then
		chmod 644 "{}"
	fi
' ;

Here’s an example of what files looked like before this command was executed:

icebox:/etc # ls -als
total 488
 4 drwxr-xr-x   2 root root   4096 Feb  9 23:26 .
12 drwxr-xr-x 123 root root  12288 Feb  9 23:25 ..
 4 -rw-r--r--   1 root root    509 Dec  3  2008 a11y.conf
 4 -rw-------   1 root root   2726 Jan 14  2009 autofs_ldap_auth.conf
 4 -rw-r--r--   1 root root     79 Dec  3  2008 cups-autoconfig.conf
 4 -rw-r--r--   1 xbmc users   408 Dec  3  2008 depmod.conf
 4 -rwxrwxrwx   1 root root   1411 Dec  3  2008 dhclient.conf
20 -rw-r--r--   1 xbmc users 18485 Dec  2  2008 dnsmasq.conf
16 -rw-r--r--   1 root root  14283 Jan  6  2009 dvdwizard.conf
 4 -rw-r--r--   1 root root    373 Dec  9  2008 esd.conf
 4 -rw-r--r--   1 root root   2689 Dec  3  2008 gai.conf
 4 -rw-r--r--   1 root root   1984 Dec  3  2008 gnome_defaults.conf
 4 -rw-------   1 xbmc users    66 Jan 27 09:47 grub.conf
 4 -rwxrwxrwx   1 root root    840 Dec  3  2008 gssapi_mech.conf
 4 -rw-r--r--   1 root root    370 Dec  3  2008 host.conf

And after…

icebox:/etc # ls -als
total 488
 4 drwxr-xr-x   2 root root  4096 Feb  9 23:26 .
12 drwxr-xr-x 123 root root 12288 Feb  9 23:25 ..
 4 -rw-r--r--   1 root root   509 Dec  3  2008 a11y.conf
 4 -rw-------   1 root root  2726 Jan 14  2009 autofs_ldap_auth.conf
 4 -rw-r--r--   1 root root    79 Dec  3  2008 cups-autoconfig.conf
 4 -rw-r--r--   1 root root   408 Dec  3  2008 depmod.conf
 4 -rw-r--r--   1 root root  1411 Dec  3  2008 dhclient.conf
20 -rw-r--r--   1 root root 18485 Dec  2  2008 dnsmasq.conf
16 -rw-r--r--   1 root root 14283 Jan  6  2009 dvdwizard.conf
 4 -rw-r--r--   1 root root   373 Dec  9  2008 esd.conf
 4 -rw-r--r--   1 root root  2689 Dec  3  2008 gai.conf
 4 -rw-r--r--   1 root root  1984 Dec  3  2008 gnome_defaults.conf
 4 -rw-------   1 root root    66 Jan 27 09:47 grub.conf
 4 -rw-r--r--   1 root root   840 Dec  3  2008 gssapi_mech.conf
 4 -rw-r--r--   1 root root   370 Dec  3  2008 host.conf
Print Friendly, PDF & Email

2 Comments »

  • PillowMan1234 says:

    I’m planning on making my own Coat of Arms and I need to get this translated into Latin. Unfortunately I’m not proficient in the language. I have an idea but I want to get the phrase in the correct syntax & arrangement.

  • Smashing Pumpkins says:

    “Vote like your life depends on it.
    Because it does.”

    I would like you to translate that in the correct syntax and closest possible form in french. Google translate and Babelfish aren’t helping.

Leave a Reply

%d bloggers like this: