Watch How Many Files There Are In A Folder
Sometimes you have a folder full of tens of thousands of files, a spool folder can quite often grow when something breaks. While you've waiting for a service to process these files you can watch the directory count every 20 seconds or so.
Command: while :; do ls -al /usr/local/nagios/var/spool/perfdata/ | wc -l; sleep 20; done Output: 14651 12519 12000 11565
Stelio Pappas showed me another way of doing this using the watch command: Command: watch "ls -al /usr/local/nagios/var/spool/perfdata/ | wc -l" Output:
The screen will update every 2 seconds with the output of the command
With either command press CTRL + C to stop the watching. Create A tar.gz File Of All Files In A Folder
Command: tar -v -pczf /tmp/nagios_config_backup.tar.gz /usr/local/nagios/etc Output: tar: Removing leading `/' from member names /usr/local/nagios/etc/ /usr/local/nagios/etc/cgi.cfg /usr/local/nagios/etc/htpasswd.users /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/resource.cfg /usr/local/nagios/etc/objects/ /usr/local/nagios/etc/objects/timeperiods.cfg /usr/local/nagios/etc/objects/templates.cfg /usr/local/nagios/etc/objects/printer.cfg /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/commands.cfg /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/windows.cfg /usr/local/nagios/etc/objects/switch.cfg /usr/local/nagios/etc/objects/box293_check_vmware.cfg
Unzip A .zip File Into A Folder
Command: unzip -o /tmp/the_backup.zip -d /tmp/restored/ Output: Archive: /tmp/the_backup.zip creating: /tmp/restored/important_stuff/ inflating: /tmp/restored/ important_stuff /crikey.php
inflating: /tmp/restored/ important_stuff/ CHANGES.TXT
Find A File And List The Details
Command: find /usr/local/nrdp/plugins -name check_icmp -exec ls -la {} \; Output: -rwxrwxr-x 1 nagios nagios 590901 Jun 24 2014 /usr/local/nrdp/plugins/AIX/powerpc/root/check_icmp -rwxrwxr-x 1 nagios nagios 133548 Jun 24 2014 /usr/local/nrdp/plugins/SunOS/sparc/root/check_icmp -rwxrwxr-x 1 nagios nagios 99064 Jun 24 2014 /usr/local/nrdp/plugins/SunOS/i386/root/check_icmp -rwxrwxr-x 1 nagios nagios 97773 Jun 24 2014 /usr/local/nrdp/plugins/Linux/x86_64/check_icmp -rwxrwxr-x 1 nagios nagios 80057 Jun 24 2014 /usr/local/nrdp/plugins/Linux/i386/check_icmp
Find All Files 0 Bytes In Size And Delete Them
Command: find /tmp/ -maxdepth 1 -size 0 -exec rm -f "{}" \; Find All Files LESS than 4000 Bytes In Size And Delete Them
Command: find /tmp/ -maxdepth 1 -size -4000c -exec rm -f "{}" \; |