From 45b4d0de7e129b3480b282f4ab72bd3cf7f1ded6 Mon Sep 17 00:00:00 2001 From: darksun Date: Tue, 20 Mar 2018 18:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E9=A2=98:=20The=20Type=20Command=20Tu?= =?UTF-8?q?torial=20With=20Examples=20For=20Beginners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nd Tutorial With Examples For Beginners.md | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 sources/tech/20180313 The Type Command Tutorial With Examples For Beginners.md diff --git a/sources/tech/20180313 The Type Command Tutorial With Examples For Beginners.md b/sources/tech/20180313 The Type Command Tutorial With Examples For Beginners.md new file mode 100644 index 0000000000..b1565efc7f --- /dev/null +++ b/sources/tech/20180313 The Type Command Tutorial With Examples For Beginners.md @@ -0,0 +1,80 @@ +The Type Command Tutorial With Examples For Beginners +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/03/Type-command-720x340.png) + +The **Type** command is used to find out the information about a Linux command. As the name implies, you can easily find whether the given command is an alias, shell built-in, file, function, or keyword using “type” command. Additionally, you can find the actual path of the command too. Why would anyone need to find the command type? For instance, if you happen to work on a shared computer often, some guys may intentionally or accidentally create an alias to a particular Linux command to perform an unwanted operation, for example **“alias ls = rm -rf /”**. So, it is always good idea to inspect them before something worse happen. This is where the type command comes in help. + +Let me show you some examples. + +Run the Type command without any flags. +``` +$ type ls +ls is aliased to `ls --color=auto' + +``` + +As you can see in the above output, the “ls” command has been aliased to “ls –color-auto”. It is, however, harmless. But just think of if the **ls** command is aliased to something dangerous. You don’t want that, do you? + +You can use **-t** flag to find only the type of a Linux command. For example: +``` +$ type -t ls +alias + +$ type -t mkdir +file + +$ type -t pwd +builtin + +$ type -t if +keyword + +$ type -t rvm +function + +``` + +This command just displays the type of the command, i.e alias. It doesn’t display what is aliased to the given command. If a command is not found, you will see nothing in the terminal. + +The another useful advantage of type command is we can easily find out the absolute path of a given Linux command. To do so, use **-p** flag as shown below. +``` +$ type -p cal +/usr/bin/cal + +``` + +This is similar to ‘which ls’ command. If the given command is aliased, nothing will be printed. + +To display all information of a command, use **-a** flag. +``` +$ type -a ls +ls is aliased to `ls --color=auto' +ls is /usr/bin/ls +ls is /bin/ls + +``` + +As you see, -a flag displays the type of the given command and its absolute path. For more details, refer man pages. +``` +$ man type + +``` + +Hope this helps. More good stuffs to come. Keep visiting! + +Cheers! + + + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/the-type-command-tutorial-with-examples-for-beginners/ + +作者:[SK][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/