14

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:

  1. What is the use of type ?
  2. What is the significance of -f flag?
  3. What is the use of using type with find 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.

  • 1
    The type builtin command is not used by find. The -type option to find does something else. See help type and man find to get your answers. – user13742 Nov 18 '13 at 10:14
  • 1
    This specific misinterpretation is very specific and unlikely going to help others as a question – Anthon Nov 18 '13 at 10:38
  • 9
    Why downvoting? While the question does show the OP doesn't know much about Unix, that's not right to downvote a question on those grounds. Akshay even went as far as reading a man page which most people asking questions here do not do. – Stéphane Chazelas Nov 18 '13 at 12:16
  • please consider rephrase your question title, because your current title is preventing people who really is looking for the use of bash built-in 'type' from getting accurate answer.. – Sajuuk Jul 10 '18 at 6:11
19

In this case type has nothing to do with the bash built-in type, but more on that later on.

A little about "type"

The BASH built-in type command gives you information about commands. Thus:

$ type type
type is a shell builtin

The syntax is:

type [-tap] [name ...]
  • -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 and cat as an example:

$ type time kill cat
time is a shell keyword
kill is a shell builtin
cat is /bin/cat

$ type -t time kill cat
keyword
builtin
file

$ type -a time kill cat
time is a shell keyword
time is /usr/bin/time
kill is a shell builtin
kill is /bin/kill
cat is /bin/cat

$ type -ta time kill cat
keyword
file
builtin
file
file

Now, this specify that if you are in a Bash shell and type time some_cmd, the bash builtin time is used. To use the system time 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.

tt=$(which time)

and then use $tt to call system time.


The command in question

In this case the -type is an option to the command find. The option takes one argument of by which specify the type of entity. Example

find . -type f  # File
find . -type d  # Directory

There are more, check man find for the rest.

To search for the specific option you can do (whilst in man):

/^\s*-typeEnter

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:

  • command: a program or built-in.
  • parameter: an entity after the command word.
  • option: an optional parameter.
  • argument: a required parameter.

In a command specification square brackets are used to specify options and, optionally less/greater then, used to specify arguments. Thus:

foo [-abs] [-t <bar>] <file> ...
foo [-abs] [-t bar] file ...

Gives -a -b and -s as optional parameters, and file a required one. -t is optional, but if specified takes the required argument bar. Dots represent that it can take several files.

This is no exact specification, and often man or help 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:

chmod -R nick 722 foo
chmod nick 722 foo -R

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 property man 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.:

find . $(some command)
find . `some command`
find . $some_var
find . -type f -exec some_command {} \;
find . -type f | some_command
...

The -exec is a special one where -exec some_command {} \; are all parameters given to find, but the some_command {} \; part is expanded, within find to some_command string_of_found_entity.


Further on

  • quoting
  • expansion
  • command substitution
  • and so much more

You might find this useful.

7

You shoul look in man find, not in help type or man bash. type in find will specify what file type you need:

   -type c
          File is of type c:

          b      block (buffered) special

          c      character (unbuffered) special

          d      directory

          p      named pipe (FIFO)

          f      regular file

          l      symbolic link; this is never true if the -L option or the
                 -follow option is in effect, unless the symbolic link  is
                 broken.  If you want to search for symbolic links when -L
                 is in effect, use -xtype.

          s      socket

          D      door (Solaris)

And builtin type is completely different thing and it's NOT the one is used inside find.

0

You looked to the wrong manual page, this isn't the type -f command but find -type f option which is quite different, have a look to the find manual for proper explanations.

0

-type f tells find to only print files of type f ie plain files, not directories, not symbolic links and not device files. man find then search for -f option.

0

This is not the right manual page you are looking at. You should be using

man find

that will tell you that with -type f the -type predicate selects only the regular files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.