Introduction to Linux command learning

Table of contents

1 What is a linux command

2 type command


1 What is a linux command

The linux command is   a command to manage the Linux system. For the Linux system, whether it is the central processing unit, memory, disk drive, keyboard, mouse, or user, etc. are all files, the  commands managed by the Linux system are the core of its normal operation, similar to the previous DOS commands. There are two types of linux commands in the system: built-in  Shell  commands and Linux commands.

First introduce a term "console (console)", which is the man-machine interface that we usually see using the character interface, such as dos. When we say console commands, we mean the commands that can be used to operate the system input through the character interface. For example, the dos command is a console command. What we want to understand is the basic console commands based on the Linux operating system. One thing to note is that unlike dos commands, Linux commands (including file names, etc.) are case sensitive, that is, if the case of the command you enter is wrong, the system will not will respond as you expect.

2 type command

First of all, the first command to learn is the type command. The type command can check the type of a command, which are divided into `alias', `keyword', `function', `builtin', `file'. You can see a few examples:

parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type cd
cd is a shell builtin
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type which
which is hashed (/usr/bin/which)
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type apt
apt is /usr/bin/apt

If you only want to get a simple type of command, you can add the -t parameter. For example:

parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t cd
builtin
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t which
file
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t apt
file

So what's the use of getting the type of a command. After getting the type of a command, you can use and help or man to view the help manual of the command. If it is a builtin command, use the help command to view the help manual of the command, and if it is a file command, use the man command to view the help manual of the command. for example:

parallels@ubuntu-linux-20-04-desktop:~/C_test1$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.
    
    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.
    
    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.
    
    Options:
      -L	force symbolic links to be followed: resolve symbolic
    		links in DIR after processing instances of `..'
      -P	use the physical directory structure without following
    		symbolic links: resolve symbolic links in DIR before
    		processing instances of `..'
      -e	if the -P option is supplied, and the current working
    		directory cannot be determined successfully, exit with
    		a non-zero status
      -@	on systems that support it, present a file with extended
    		attributes as a directory containing the file attributes
    
    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.
    
    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

This way we get a way to learn linux commands. For example, we want to learn the which command. From the above type query, the which command is a file command, so we can use man which to query the usage method of this command.

WHICH(1)                                                                             General Commands Manual                                                                             WHICH(1)

NAME
       which - locate a command

SYNOPSIS
       which [-a] filename ...

DESCRIPTION
       which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell.  It
       does this by searching the PATH for executable files matching the names of the arguments. It does not canonicalize path names.

OPTIONS
       -a     print all matching pathnames of each argument

EXIT STATUS
       0      if all specified commands are found and executable

       1      if one or more specified commands is nonexistent or not executable

       2      if an invalid option is specified

From the above manual, you can know that the which command can locate the position of a command, and the -a parameter can be used to print the positions of all matching commands.

parallels@ubuntu-linux-20-04-desktop:~/C_test1$ which ls
/usr/bin/ls
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ which -a ls
/usr/bin/ls
/bin/ls

In fact, the type command can also give the location of a command, and the type command gives more information than the which command. 

×

Guess you like

Origin blog.csdn.net/daida2008/article/details/124717426