Linux basic command and command history

Source: Internet
Author: User

(i) Types of files on Linux systems

In the result of using the LS command, the leftmost one represents the file type:

    • -: Regular file, in other programs with F, you can continue to use the file command to view the general file type
    • D: Catalog file/directory
    • B: Block device file/block device, support random access in "block" units
    • C: Character device file/character device, support for linear access in "character" units
      • When the LS command queries the device file, the result is not the size, but the two numbers, called the main number and the second number, which are usually represented by a 8-bit binary, separated by commas
      • Main Number: Major number/main device number, which identifies the device type and then determines which driver to load
      • Number: Minor number/secondary device number, used to identify different specific devices under the same type
    • L: Symbolic Link file/symbolic link
    • P: Named pipe/pipe
    • S: Socket file/socket

(ii) Basic orders

    • Command type
      • External command: Each command has a corresponding file, the command name is the filename
      • Internal commands: Shell commands such as bash have many commands, so internal commands are internal to the shell, and the shell itself is an external command
      • The method for viewing the command type is: Type command. In the result, the external command displays the file path (but not always, because some commands have aliases), and the internal command displays builtin.
      • Note: The command can have aliases, aliases can be the same as the original name, at this time is hidden, can be added to use the former command backslash, such as LS is actually LS--color=auto, when the original LS is hidden, you can use/ls call the original LS
      • Use the alias command to view a list of command aliases
      • Aliases are defined by the alias alias = ' command '; if there are no spaces in the middle of the command, you can do so without quotation marks, which is only valid for the current shell and is invalidated after logout (with time limit and range limit). If you want to work permanently, you need to add it to the configuration file.
      • The method for revoking aliases is: Unalias aliases;
    • which command
      • Displays the full path of the command
    • Whereis command
      • Displays the location of the command's binaries, source files, and manual pages
      • -B: Search only for binary file paths
      • -M: Search the manual page path only
    • Who command
      • Display the user information of the login system, for example, the following indicates that there are two users logged in through the pseudo terminal, one through the virtual terminal. Display format: User name, terminal, time, remote login host IP (native login does not show IP)

Root pts/0 2015-12-10 09:25 (172.16.100.100)

Root PTS/1 2015-12-10 09:25 (172.16.100.100)

Root Tty1 2015-12-10 09:25

      • Who-b: Displays the time the system was started
      • Who-r: Display System RunLevel
    • W command
      • The enhanced who, not only can display the user information of the login system, but also show what they are doing now

(iii) Bash's underlying features

  • Command history: The shell process saves commands that were previously executed by the user in its session
    • Use the history command to view command histories
    • Custom history features can be implemented with environment variables
      • Histsize:shell the number of commands history that the process can keep
      • Histfile: A file that persists the history of the command. There is a hidden file in each user's home directory. Bash_history, every time the user log out, the in-memory command history is written into the file. The history command displays two parts, both in the file and in the current memory.
      • Histfilesize: The number of history bars the file can hold
    • History N: Show the last n command histories
    • -C: Empty the memory of the command history
    • -D offset N: Clears the specified command history
    • -r: Read command history from file to memory
    • -W: Append in-memory commands to the history file
    • To invoke a command in the command history list:
      • ! #: Once again execute the # command in the History list
      • !! : Executes the previous command again
      • ! String: Once again the last command in the history list that starts with string
    • Call the last parameter of the previous command:
      • Press the ESC key first, then press "." Number key
      • or enter "!$" in the position of the parameter
    • Control the way the command history is logged:
      • Environment variable: Histcontrol
      • There are three kinds of values to take:
        • Default ignoredups: Ignore duplicates, only adjacent are considered duplicates
        • Ignorespace: Ignores commands that start with whitespace characters, so we can put a space in front of a command to keep it from being logged
        • Ignoreboth: Both of these take effect at the same time
        • The way to change the Histcontrol value: Histcontrol=ignorespace, because there are no spaces in the value, so do not need to quote. Valid only for the current shell session.

Linux basic command and command history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.