I came across a command in Bash script in which I found:
find /var/log/abcd -type f
The above command was in context of cleaning the log files.
I know what find
does.
After having seen -type f
, I looked manual page for it.
I got to see it in man page of BASH_BUILTINS(1)
The description of -f flag under type
command is :-
The -f option suppresses shell function lookup, as with the command builtin.
Following are my questions:
- What is the use of
type
? - What is the significance of
-f
flag? - What is the use of using
type
withfind
command?
[EDIT]:- After having read all the comments and answers till now, I would like to mention the cause for my misinterpretation of -type option in command find
Vs type command
.
This all happened because I was assuming and till date have seen only the short options(Tests in case of the find
command) with a single minus sign '-', example, ls -l
. Most of the times I have seen long options with double minus sign '–' , example, ls --version
.
Best Answer
In this case
type
has nothing to do with the bash built-intype
, but more on that later on.A little about "type"
The BASH built-in
type
command gives you information about commands. Thus:The syntax is:
-t
: print only type, if found-a
: print all occurrences of the command, both built-in and other.-p
: print the disk file that would be executed on call to command, or nothing.If we look at
time
,kill
andcat
as an example:Now, this specify that if you are in a Bash shell and type
time some_cmd
, the bash builtintime
is used. To use the systemtime
you can do/usr/bin/time some_cmd
.One way often used to ensure that the system, and not built-in, command is used is by using
which
.and then use
$tt
to call systemtime
.The command in question
In this case the
-type
is an option to the commandfind
. The option takes one argument of by which specify the type of entity. ExampleThere are more, check
man find
for the rest.To search for the specific option you can do (whilst in man):
Then use
n
for next until you find it.A little about shell command
This is a bit of a personal interpretation.
Some of the things worth mentioning, in this specific case, are commands, options, arguments and pipes.
This is somewhat loosely used, but in my vocabulary we have in short:
In a command specification square brackets are used to specify options and, optionally less/greater then, used to specify arguments. Thus:
Gives
-a
-b
and-s
as optional parameters, andfile
a required one.-t
is optional, but if specified takes the required argumentbar
. Dots represent that it can take several files.This is no exact specification, and often
man
orhelp
is required to be sure.Positioning of arguments options and input can often be mixed up, but it is generally best to keep to a position based approach as some systems does not handle mixed positioning of arguments. As an example:
Both work on some systems, whilst the latter does not on other.
In your exact command all parameters belongs to
find
– thus if you wonder about a propertyman find
is the correct place to look. In cases where you need to look at man pages for the shell etc. could be in e.g.:The
-exec
is a special one where-exec some_command {} \;
are all parameters given tofind
, but thesome_command {} \;
part is expanded, withinfind
tosome_command string_of_found_entity
.Further on
You might find this useful.