notes note: most of these commands are for HP-UX
using find to clean /tmp of files older than 1 day
host.root-#-> find . -atime +1 -name '*' -exec rm -f {} \; or host.root-#-> find /tmp -atime +1 -name '*' -exec rm -f {} \;
also: find /usr/tmp -atime +1 -name '*' -exec rm -f {} \; remove cores: find / -name core -exec rm -f {} \;using find to compress overladen user directories
find . -type f -exec compress -f {} \; (and to undo it should they complain:) find . -type f -exec uncompress {} \;examples from the HP-UX man pages
EXAMPLES Search the two directories /example and /new/example for files containing the string Where are you and print the names of the files: find /example /new/example -exec grep -l 'Where are you' {} \;
Remove all files named a.out or *.o that have not been accessed for a week: find / \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \; Note that the spaces delimiting the escaped parentheses are required.
Print the names of all files on this machine. Avoid walking nfs directories while still printing the nfs mount points: find / -fsonly hfs -print
Copy the entire file system to a disk mounted on /Disk, avoiding the recursive copy problem. Both commands are equivalent (note the use of -path instead of -name): cd /; find . ! -path ./Disk -only -print | cpio -pdxm /Disk cd /; find . -path ./Disk -prune -o -print | cpio -pdxm /Disk
Copy the root disk to a disk mounted on /Disk, skipping all mounted file systems below /. Note that -xdev does not cause / to be skipped, even though it is a mount point. This is because / is the starting point and -xdev only affects entries below starting points. cd /; find . -xdev -print | cpio -pdm /Disk
Change permissions on all regular files in a directory subtree to mode 444, and permissions on all directories to 555: find-type f -print | xargs chmod 444 find Note that output from find was piped to xargs(1) instead of using the -exec primary. This is because when a large number of files or directories is to be processed by a single command, the -exec primary spawns a separate process for each file or directory, whereas xargs collects file names or directory names into multiple arguments to a single chmod command, resulting in fewer processes and greater system efficiency. Hewlett-Packard Company - 7 - HP-UX Release 10.20: July 1996-type d -print | xargs chmod 555
remove old core filesfind core files with an access time over 4 days, then removefind . -atime +4 -name core -exec rm -f {} \;find / -atime +4 -name core -exec rm -f {} \; note: find commands from / are often frowned upon by system owners use the . command or specify the path. IN addition, if not run as root you will run into permission problem errors. find core files, then removefind . -name core -exec rm -f {} \;find / -name core -exec rm -f {} \; note: find commands from / are often frowned upon by system owners use the . command or specify the path. IN addition, if not run as root you will run into permission problem errors. find old files, then removefind . -atime +60 -exec rm -f {} \;find large file, say 100,000 bytes, not accessed for 7 daysfind /users -size +100000c -atime +7 |
EMAIL TO: john@wagoneers.com Copyright © 1997 John Meister All rights reserved.
john's home page. --
HTML tags page. --
cool awk tricks --
lvm info --
nfs example --
System Administration Humor (?):
SysAdmin field guide --
SysAdmin song --
never say... --