قالب وردپرس درنا توس
Home / Tips and Tricks / Using the Linux command type

Using the Linux command type



  Terminal on a Linux Laptop
Fatmawati Achmad Zaenuri / Shutterstock.com

Find out if a command resolves to an alias, disk file, shell function, built-in command, or reserved word , Use the type to find out how your Linux commands are executed and to better understand your system.

Performing My Bidding

When we open a terminal window and send commands to our Linux computer, we seldom stop thinking about which software components in the operating system respond to our commands and execute them for us. We type in the command, get the result and continue our work.

If we know how to run the commands, we can better understand how our Linux or other Unix-like operating system is built. A look under the bonnet can make us an informed driver.

The instructions we send to the command line are divided into one of the following categories:

  • alias : A command defined by the user (or system) that causes other, usually lengthy, or other complex command sequences take place.
  • disk file : A binary executable file such as / usr / bin / top .
  • Shell function : A custom (or system-defined) function that can be used on the command line or included in scripts.
  • Built-in command : A command executed by the shell itself, z pwd .
  • Reserved word : A word reserved by the shell, e.g. B. if and elif . They are also referred to as keywords.

The command of type indicates which category a Linux command belongs to. Here's a quick guide to understanding the command output.

The Command Type

Let's review a few short examples for each command category.

  Enter date 

  Enter date in a terminal window

The command date is an executable disk file.

  Type ls 

  Type ls in a terminal window

The command ls is an alias, wrapping the underlying command ls to default the option - color = auto to use.

  Type Lowdown 

  Type Lowdown in a Terminal Window

The command lowdown is a user-defined function set up for the commuter with whom this item was researched. It provides a quick overview of some system resources. It is a combination of whoami w free and df .

  type pwd 

  type pwd in a terminal window

The command pwd is a built-in Bash shell command.

  Type elif 

  Type elif in a terminal window

The ] The elif command is a reserved word in the bash shell.

Using Multiple Commands

You can enter multiple commands to identify them at the same time.

  Give a Date Top ls 

  a date above ls in a terminal window

The option -t

None of the options that you enter accepts names. So we can get out our name book and baptize ourselves. If you consider the option -t "scarce", you will not be very wrong. It reduces the responses of type to single word answers.

  Type -t date 
  Type -t Pwd 
  Type -t Lowdown 

  Demonstration of the type -t option in a terminal window

The option -a

Let's call this Option the option "all". All the positions where the command is located are listed. Note that this option does not work if you also use the option -p .

For example, if you have an alias with the same name as the underlying command, you can get information about the alias and the command.

  Type -a ls 

  Demonstration of the option type -a in a terminal window

-f option

The option -f enforces that does not search for user-defined functions or system-defined functions. Think of this option as a "feature search". Note that if the command is a function, type reports that the command can not be found.

  Type -f top 
  type -f lowdown 

  Demonstration of the type -f option in a terminal window

Option -P

If you have the option -P type only searches directories in $ PATH. So we can call this option "path". Note that this option uses a capital letter "P".

  Type -P date chmod adduser 

  Type -P date chmod adduser in a terminal window

option -p

If you use the option -p type only if the command is a disk file. Note that this option uses a lowercase letter "p".

  Type -p mount 
  Type -p ls 
  Type -p -a ls 

  Demonstration of the option type -p in a terminal widow

type There is no answer for ls since ls is an alias and not a disk file.

-a option, so that the type searches for all instances of the command ls lists the underlying disk file that the ls -Alias ​​uses of.

Summary

That was nice and simple, but still lighting.

We tend to think of anything we put in a terminal window as a "command" and leave it at that. In fact, commands in the Linux system are implemented in several ways. And with type you can find out which one is involved.




Source link