What is the use of type (Bash builtins)?

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.


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.