Using type on linux

type Command in Linux | Explained

The “type” command line tool is generally used for finding the information of any Linux command. It allows the users to quickly know about the command type, whether it is an “alias”, “keyword”, “shell built-in”, or a “function”. In addition, it also provides the absolute path of the mentioned command by using its supported options.

This guide provides a deep insight into the purpose, working, and usage of the “type” Linux command.

The content of this guide is written below:

Let’s start with the working of the “type” command.

How to Use type Command in Linux?

The generalized syntax of the “type” command is defined below on which it is dependent:

Syntax

$ type [Options] command names

The above syntax contains the following components:

  • type: Main keyword that represents the “type” command.
  • options: Supported options of “type” command.
  • command names: Specific command names whose type needs to be found with the help of the “type” command.

The “type” command offers a list of important supported options that can easily get through its

help” command:

Scroll down the page to get more pieces of information.

Now, look at the practical implementation of the “type” command using these options.

Example 1: Display Command Type

The “type” command without any argument or options displays the specified command type in a single line as shown in the screenshot:

The output displays that “pwd is a shell builtin”.

Example 2: Return a Specific Output

The “type” command shows the mentioned file type in a single word with the help of the “-t” option. Suppose execute the “time” command along the “-t” option to get the file type of “ls” utility:

The output shows that the “ls” file type is “alias

Run the file “type” command to view the “while” type in Linux:

The “while” is just a “keyword”.

Similarly, check the type of the “cd(change directory)” command using the “type -t” command:

The output displays that “cd” is a “builtin” command line utility.

Type the below command in the terminal to get the type of “cp”:

Here, it is verified that “cp” is a “file”.

Example 3: Check the Absolute Path

The “-p” argument of the “type” command provides the absolute path of the specified command. Suppose to check the absolute path of the “mkdir” command, use the “type” command in the following way:

Читайте также:  Расширение для линукс минт

The output displays the absolute path of “mkdir” that is “/usr/bin/mkdir”.

Example 4: Display all Information of the command

The “-a” flag of the “type” command prints all the information of the Linux command, such as its type and absolute path.

In this example, the “type” command with its “-a” flag is executed to display all the information of the “pwd” command.

Here, the output contains the “pwd” command type “shell built-in” and its absolute path “/usr/bin/pwd”.

It’s all about the basics and workings of Linux’s “type” command.

Conclusion

In Linux, the “type” command tells the type of the specified Linux command in the console. In addition, it also displays the “absolute path” of any Linux command with the help of its unique flags. This guide has demonstrated the main objective, working, and usage of the “type” command with the support of practical examples.

Источник

Команда type в Linux

Команда type используется для отображения информации о типе команды. Он покажет вам, как данная команда будет интерпретироваться, если ввести ее в командной строке.

В этой статье мы объясним, как использовать команду type Linux.

Как использовать команду типа

type — это оболочка, встроенная в Bash и другие оболочки, такие как Zsh и Ksh. Его поведение может немного отличаться от оболочки к оболочке. Мы рассмотрим встроенную в Bash версию type .

Синтаксис команды type следующий:

Например, чтобы найти тип команды wc , вы должны ввести следующее:

Результат будет примерно таким:

Вы также можете предоставить более одного аргумента команде type :

Вывод будет включать информацию о командах sleep и head :

sleep is /bin/sleep head is /usr/bin/head 

Типы команд

Параметр -t указывает type напечатать одно слово, описывающее тип команды, которое может быть одним из следующих:

  • псевдоним (псевдоним оболочки)
  • функция (функция оболочки)
  • встроенный (встроенный в оболочку)
  • файл (файл на диске)
  • ключевое слово (зарезервированное слово оболочки)

Показать все местоположения, содержащие команду

Чтобы распечатать все совпадения, используйте параметр -a :

Вывод покажет вам, что pwd — это встроенная оболочка, но она также доступна как автономный исполняемый файл /bin/pwd :

pwd is a shell builtin pwd is /bin/pwd 

Когда используется опция -a , команда type будет включать псевдонимы и функции, только если опция -p не используется.

Опции команд другого типа

Параметр -p заставит type вернуть путь к команде, только если команда является исполняемым файлом на диске:

Например, следующая команда не будет отображать никаких выходных данных, потому что команда pwd является встроенной оболочкой.

В отличие от -p , опция -P в верхнем регистре указывает type искать по PATH исполняемого файла на диске, даже если команда не является файлом.

Когда используется опция -f , type не будет искать функции оболочки, как со встроенной командой.

Выводы

Команда type покажет вам, как будет интерпретироваться конкретная команда, если она используется в командной строке.

Если у вас есть вопросы или отзывы, оставьте комментарий ниже.

Источник

Get Information About a Command With Type Command in Linux

The type command tells you whether a Linux command is built-in shell command, where is its executable located and whether it is aliased to some other command. Here’s how to use the type command in Linux.

Читайте также:  Jdk 8 arch linux

The type command is a built-in bash shell command that can provide the type of a specified command.

What does it mean by the “type of a command”? It means that you can get information like whether a Linux command is built-in shell command, where its executable is located and whether it is aliased to some other command.

It may seem like it’s not of much use but believe me it could come handy while investigating why a command is behaving in a certain way.

Using type command in Linux

The syntax for the type command is simple:

To get started, let’s use the type command without options on the well-known echo command:

[email protected]:~$ type echo echo is a shell builtin

It tells us that echo is a shell built-in command. This is the type of command that would run if the name echo is interpreted by the command line.

[email protected]:~$ type mkdir mkdir is /usr/bin/mkdir

In the above case, it locates the executable of the mkdir command. This is similar to the which command but type is faster because it is a built-in shell command.

If you use it with something that is not a command, it gives a not found error.

[email protected]:~$ type no_command bash: type: no_command: not found

Type of an aliased command

You’re probably already familiar with aliases in Linux. To quickly recall, these are pseudo commands that work like shortcuts. They can be set in your shell profile.

Let’s see what kind of information type command finds when you use it on an aliased command:

[email protected]:~$ type ll ll is aliased to `ls -alF'

As you can see, it shows the real command behind the aliased one.

Get the type of multiple commands

You can also use type with multiple commands and get the results echoed back to us.

[email protected]:~$ type ls ll ls is aliased to `ls --color=auto' ll is aliased to `ls -alF'

On Ubuntu and some other distributions, ls is aliased to show you a colorful output. This helps you in distinguishing the symlinks, hard links, directories, executable and other different type of files.

Force type to return the path of the commands

If you want to locate the executable of a command and type keeps giving output like built-in shell and alias information, you can force to get the path with -P option.

This will return the path name even if it is an alias, built-in, or function.

Get all information of the commands

We can get the most complete information using option -a.

[email protected]:~$ type -a ls ls is aliased to `ls --color=auto' ls is /usr/bin/ls ls is /bin/ls

This shows us both the type information and every location on the system path with the file.

Return only the type of command, not path

Here’s different type you can get:

You can prompt for only the type with the -t option. Here are a few examples:

[email protected]:~$ type -t ls alias [email protected]:~$ type -t echo builtin [email protected]:~$ type -t sort file [email protected]:~$ type -t _mac_addresses function [email protected]:~$ type -t if keyword

Bonus: Why do you see “command is hashed”?

Sometimes you see an output like «command is hashed» along with the path to the executable:

[email protected]:~$ type man man is hashed (/usr/bin/man)

To avoid spending too much time on searching the path of an executable, the shell often keeps a list of programs it has found in the past. This list is called ‘hash’.

Читайте также:  Kivy installation on linux

When you see an output liked ‘command is hashed’, it means that the type command is returning the result from the already performed searches. You can use hash -r to force the shell to search from scratch.

Conclusion

I hope you learned something new today with this introduction of the type command in Linux. I find it similar to the file command which is used for getting information about files.

If you like this guide, please share it on social media. If you have any comments or questions, leave them below. If you have any suggestions for topics you’d like to see covered, feel free to leave those as well. Thanks for reading.

Источник

Type Command in Linux with Examples

Linux Type Command

The type command is used to show information about the command type and how its argument would be interpreted if typed on the command line. It is also used to find out whether it is built-in or external binary file. In this article, we will explain how to use the Linux type command.

How to Use the type Command#

Below is the basic syntax for the type command:

For example, to find the type of the cd command, you would type the following:

It will show output as following:

You can pass the multiple arguments to the type command by space separated:

sleep is /bin/sleep cd is a shell builtin

Command Options#

Use the option -t with type to find out whether it is an alias, keyword or a function, it can be one of the following single word output:

Following are the examples:

Here ls is aliased to ls —color=auto :

rvm is a tool (function) for installing, managing, and working with multiple Ruby environments:

cd is a shell builtin in Bash and other shells like Zsh and Ksh:

while is a reserved word in Bash:

Display all locations that contain the command#

Option -a is used to display all matches and the path of an executable, if available.

pwd is a shell builtin pwd is /bin/pwd

In above output showing that pwd is shell builtin and it is also available as a standalone /bin/pwd executable.

Other type command options#

Use the -p option with to force type command to print the path to the command if the command is an executable file on the disk:

For example, the following command will not display any output because the pwd command is a shell builtin.

The uppercase -P option tells type to search the PATH for an executable file on the disk even if the command is not file.

Type command will not look up for shell functions when the -f option is used.

Conclusion#

The type command will show you information about specific command type and how it will interpreted if used on the command line.

If you have any questions or feedback, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Источник

Оцените статью
Adblock
detector