Basic Linux Learning and configuration

Source: Internet
Author: User
Tags aliases lowercase uppercase letter

1. Aliases, internal commands, hash tables, external commands, priority levels when running commands, with PWD as an example

1. First compare the precedence of aliases and internal commands

    • Run alias enable= ' pwd ', enable is an internal command, now we name the PWD alias to enable, if an internal command list appears, then the internal command priority is higher than the alias, if the current path is displayed, the alias priority is higher than the alias.

2. Then compare internal commands and external commands, hash table priority

    • The command pwd is run first, then the command type is viewed through the type command, and if a hash index is present, it indicates that the hash table has a high priority and that if the PWD is displayed as an internal command, the internal command has the highest precedence, and if an absolute path occurs, the external command has the highest precedence.

By doing so we can see that the precedence level of internal commands is higher than for external commands and hash tables.

3. Now let's compare the precedence of hash tables and external commands

    • View environment variables through the echo $PATH.
    • Run enable-n pwd Disable internal command pwd, run type pwd view command type, display a path,/usr/bin/pwd

    • Run the PWD command, and then run the type PWD to see that the command is displayed in the hash table and points to the absolute path of the command.
    • This seems to prove that the priority of the hash table is higher than the external command, but this is not certain. What happens when we cancel the PWD's enable alias and then disable the internal command pwd through enable-n pwd hash-r empty the hash table and then execute PWD?
    • We find that this is still a path through the type command, so we need to test it in a different way.
    • Because TTY is an external command, we can test it with a TTY and run the type TTY to get the TTY types, which is also a path/usr/bin/tty.
    • Perform the PWD first, and we want this command to load the PWD into a hash table.
    • We can copy the TTY command to/usr/local/bin, and named PWD, the command is sudo cp/usr/bin/tty/usr/local/bin/pwd.
    • The PWD command is executed because the TTY was previously copied to/usr/local/bin and named Pwd, so the TTY is higher than PWD on the absolute path, and if the hash table has precedence over the external command, the result of the execution should be the result of the PWD execution. If the external command has precedence over the hash table, the execution result should be the result of the TTY execution.
    • This way we can see that the execution result is the result of the PWD execution instead of the TTY execution result, which indicates that the hash table has precedence over the external command. At this point we need to restore the disabled PWD command through the Enable PWD command, and then delete the TTY command that just copied past through Rm-f/usr/local/bin/pwd.
    • Let's clear the hash table by Hash-r and run PWD again to see what happens.

4. Through the above experiment, we can get aliases, internal commands, external commands, hash table priority order from high to Low is alias, internal command, Hashtable, external command, as long as the hash tables are loaded with the external command hash index .

2. Install some packages that may be needed later

1. Install Man's Chinese bag

  • 1. How to use the network installation *
    The first thing to download is the man Chinese compress package on the network, the command is as follows:
    weget http://manpages-zh.googlecode.com/files/manpages-zh-1.5.1.tar.gz
    Then unzip the command as follows:
    tar zxvf manpages-zh-1.5.1.tar.gz
    Then open with the CD command:
    cd manpages-zh-1.5.1.tar.gz
    Then run the make command to install:
    make install
    If you do not have the GCC compiler installed, you need to install GCC first, we use the local Yum source method, the command is as follows:
    sudo yum install gcc
    Then run make install to complete the installation. But then run man, found no Chinese package, because, we did not add the path of the Chinese package to the man command. Then you need to modify the configuration file:
    vim /usr/bin/zhman
    Then append the following code
    #!/bin/bash         #name=zhman         export LANG=zh_CN         man -M /usr/local/zhman/share/man/zh_CN $1
         如果希望所有用户都能执行man命令,就需要修改权限为,所有人可执行如下     `chmod 777 /usr/bin/zhman`
  • 2. Install with local CD
    The CD-ROM installation requires a CD with a man software package and mounts it with the following command:
    mount /dev/cdrom media
    Then install the package command as follows:
    rpm -ivh /media/man-pages-zh-CN-1.5.2-4.el7.noarch.rpm
    Then, as above, add the Chinese package path, modify the permissions can be.

  • 3 using the Yum source installation, the command is as follows:
    yum install manpages-zh
    If you can't find a Chinese package, you can search for it using the following command:
    yum list |grep man.*zh
    If not, you can update the local Yum source with the following command:
    yum -y update
    Then execute the following installation command
    sudo yum install 加中文包名

2. Install the tree

    • 1. Install with Yum
      sudo yum -y install tree
      2. Install the same method as the man through the network.
3. Operation of some basic commands
  • Displays a file or directory that starts with a non-letter in the/etc/directory followed by a letter and any other character of any length
    ls -d /etc/[a-Z][a-Z]*
  • Displays all numbers in the/etc/directory that begin with RC, followed by 0-6, and other files or directories of any character
    ls -d /etc/rc[0-6]*
  • Displays all files or directories ending with. D in the/etc directory
    ls -d /etc/*.d
  • Displays files or directories with the. conf ending with the/etc directory and beginning with m,n,r,p
    ls -d /etc/[m,n,r,p]*.conf
  • Show only hidden files and directories under/root
    ls -d .* /root
  • Show only non-hidden directories in/etc
    ls -d /etc/*/
  • Displays all files or directories that start with K, end with a lowercase letter, and have at least one digit in the middle of the/etc directory
    ls -d /etc/k*[0-9]*[[:lower:]]
  • Displays a file or directory with any three-digit name in the/proc directory
    ls -d /proc/*[0-9]*[0-9]*[0-9]*
  • Displays the file or directory with the symbol and number of the file name in the/var/log directory
    ls -d /var/log/*[[:punct]]*[0-9]*
  • Displays all files or directories starting with M and ending with a number and x in the/usr/share/man directory
    ls -d /usr/share/man/m*[0-9]*
  • Displays all files or directories that start with an uppercase letter and end with two digits in the/etc directory
    ls -d /etc/[[:upper:]]*[0-9][0-9]
  • Displays files or directories with a file name that contains at least one lowercase letter and a number and ends with. conf in the/etc directory
    ls -d /etc/*[[:lower:]]*[0-9].conf
  • Show only non-hidden directories in the user's home directory
    ls -d ~/*/
  • Define alias command baketc,/etc/all files in the directory, back up to/testdir separate subdirectories, and require a subdirectory format of BACKUPYYYY-MM-DD, the backup process is visible
    alias baketc=‘mkdir -p /testdir/backup$(date +%F);cp -av /etc/*/testdir/backup$(date +%F)‘
  • Create the/testdir/rootdir directory and copy all the files under/root to that directory, requiring the original permissions to be retained
    alias opp=‘mkdir -p /testdir/rootdir;cp -ar /root/* /testdir/rootdir‘
  • How to create/TESTDIR/DIR3,/TESTDIR/DIR4,/TESTDIR/DIR5,/TESTDIR/DIR5/DIR6,/TESTDIR/DIR5/DIR7
    mkdir -p /test/{3,4} 5/{6,7}
  • Use a command to create/testdir/dir8/x,/testdir/dir8/y,/testdir/dir8/x/a,/testdir/dir8/x/b,/testdir/dir8/x/c,/testdir/dir8/y/ A,/testdir/dir8/y/b
    mkdir -p /testdir/dir8/{x/{a,b,c},y/{a,b}}
  • Use a command to create/testdir/dir9/x,/testdir/dir10/y,/testdir/dir9/x/a,/testdir/dir10/y/b
    mkdir -p /testdir/dir{11,12,13}
  • Use a command to create/TESTDIR/DIR11,/testdir/dir12,/testdir/dir13,/testdir/dir12/dir14,/testdir/dir13/dir15
    mkdir -p /testdir/{11,12/14,13/15}

Basic Linux Learning and configuration

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.