Wednesday, February 11, 2009

Finding file and directories : HP-UX

The find command recursively descends a directory locating all the files that meet the criteria given on the command line. Without any options the find command will take no action on the files it finds, so the -print option is used to write the found files to standard output. The format of the find command is:

find path_name_list [options]

Where path_name_list is one or more directories.

% find . -name Makefile -print
/home/huron2/admin/scot/tutorial/Makefile
%
The . is a directory abbreviation for the current directory. The -name option specifies that only files with the given name should be found. The name option can include wildcard character:
% find . -name "core*" -size +3 -mtime +7 -exec rm -i {} \; -print
/home/huron2/admin/scot/core: ? (y/n) y
/home/huron2/admin/scot/core
%
==>Some Options to Find
--------------------------------------------------------------------
-name file Find files named file

-size n Find files that contain size...
n exactly n blocks (1 block = 512 bytes)
+n more than n blocks
-n less than n blocks

-mtime n Find files that were modified
n exactly n days ago
+n more than n days ago
-n less than n days ago

-exec cmd Execute command cmd on each file

-type type Find files that match the type
f ordinary file
d directory
b block device
c character device
p named pipe
--------------------------------------------------------------------
Actions can be taken when files are found by using the -exec option. The -exec option uses the {} (left curly-brace right curly-brace) syntax to specify the current file that find has found. The exec command ends with the \; syntax. If we did not have the print option at the end we would not get a confirmation the file had been removed.

...ciao...

No comments:

Post a Comment