5. Learning progress and task of self-study--linux "bash features in the shell"

Source: Internet
Author: User
Tags aliases create directory parent directory

Features of bash in the shell

Features of bash in the shell

One of the bash features: command line expansion

  The mechanism of automatically replacing a given special symbol of a command line with another string

Directory:

  Command: CD "Built-in command"  

Working directory: The directory that is currently located

Cd:change directory (switch directory)

CD target path (cannot be a file must be a directory)

All starting from root is absolute path:/file name

Base name: The name of the last file in the path

/x/y/z/m/n: Destination Path
/x/y/z/m: is the directory name or path name

Two commands:
Get the base name of the path: # basename
Get directory name for path:# DirName

Note: The file name can use any character except the/(path separator), but do not use special characters and the total length cannot exceed 255
Strictly case-sensitive

Note: ~ is equivalent to/home 

If you want to switch to a directory in the root directory specific actions:# CD /USERNAME (can be an empty file or directory)" Only Administrators can do this "

If you want to switch home directory specific actions:# CD or # cd ~

If you want to switch directories in the home directory specific operations:# CD ~USERNAME (can be an empty file or directory)" Only Administrators can do this "

  # CD- : return to the previous directory

   # CD. : Switch to current directory

  # CD: : Switch to Parent directory (if current directory is "/", then "/"; "..." after execution) Meaning for the parent directory)

  # CD: /.. : Switch on level two directory;

   # cd!$ : Use the parameters of the previous command as CD parameters

  

  {}: Can host a comma-delimited list of paths that can be expanded to a specified number of paths ;

For example:

/TMP/{A,B,C}/tmp/a/tmp/b/tmp/c

/tmp/{a,b}/z/tmp/a/z/tmp/b/z

# pwd: Show current directory   Print working directory
   # mkdir: Create directory make directory
-P: Create parent directory First
-V: Show more information

   # rmdir: Remove empty directory remove directory

   

   

   

   

   Command : LS

   # ls : View files (note: Other directories in one directory are files of that directory, all files

Bash feature two: Shell references

       ': strong reference, variable substitution will not be performed
" ": weak reference, ability to perform variable substitution
": Command Reference (substitution), the execution result of the reference command, another symbol of the command substitution: $ (command)

  Variable substitution: ${variable name}
         # echo : Echoing variable values

        


  Command Reference :

Feature three of bash: command history

      A list of commands that bash has saved in the past
The current shell process is saved in the buffer
The commands in the buffer are saved to the file when the shell exits. Bash_history
use the UP and DOWN ARROW keys to look at commands that have been executed before

     History Shortcuts:

        !#: #为命令历史列表中的命令编号, you can execute the # command
        !: Executes the previous command (repeated execution, executed command)
        !-#: Execute the penultimate # command in the command history list
      !string: Executes the most recent command in a command history list that starts with string
        !$: Refer to the last parameter of the previous command by pressing ESC first, and then pressing.

     History Common options:

         - C : Empty list

-d# : Delete the specified history command

            -A: Append the current session's command history to the history file

         - N   : reads all unread rows from the history file

-R : reads the history file and appends the contents to the History list /c16>



      Command history-related environment variables:

              histsize: The number of commands that can be saved in the command history

              histfile: Command history file

              histfilesize: The number of commands the command history file can hold

              histcontrol: Control command History generation

Ignoredups: Ignore record duplicate command, repeat same command for duplicate
Ignorespace: Do not log commands that begin with whitespace characters
Ignoreboth: Features with the above values at the same time

      Add: Another feature of the Linux file system: Files that start with a dot are hidden files: # ls-a: To view hidden files
# Cat View Text file contents

Variables in the shell are assigned values:
Variable name = value
Note: Variables cannot be used when assigning values, and $ is used only when variable substitution
Variable names can contain only letters, numbers, and underscores, and cannot start with a number
Variable names differ in case:

Features of Bash Four: command aliases (alias)

Alias: Displays all aliases defined in the current shell

      

        Naming aliases

          #   alias alias = ' original command '(no spaces can be unquoted)

        Revoke aliases

          # Unalias aliases

Bash feature five: globbing, file name wildcard

Wildcard characters:
      *: matches any character of any length
ABC ABB ABM Xab AB
ab*
*ab
*ab*

      ?: Matches any single character (full-text name exact match)

      []: matches any single character within the specified range of characters
A[xyz]b:
[A-z]
[A-z]
[0-9]
[0-9a-za-z] is case insensitive by default

[[: Upper:]] = [A-z] all uppercase letters

[[: Lower:]] all lowercase letters
[[: Alpha:]] All alphabets
[[:d Igit:]] All numbers
[[: Alnum:]] All alphabets + numbers
[[: Space:]] all whitespace characters
[[:p UNCT:]] all punctuation
[^]: matches any single character outside the specified range of characters
[^0-9]=[^[:d Igit:]]

 Practice :

Copy all the files or directories in the/var directory that start with L, end with a lowercase letter, and have one digit in the middle to/tmp

L*[0-9]*[[:lower:]]

1, copy/etc directory with the beginning of P, with any characters in the middle, and the end of D files to the/tmp directory:
2, copy the/etc/directory to start with P, the middle followed by 4 arbitrary characters, and the end of D files to the/tmp/a directory: If a does not exist, create it first
3. Copy the/etc/directory with any digit starting with a non-digital ending file to the/tmp/b directory
4, copy the/etc/directory to start with a non-letter, followed by a letter and any other length of the file into the/TMP/C directory

1, Cp-r/etc/p*d/tmp
2, cp-r/etc/p???? d/tmp/a
3, the cp-r/etc/[0-9]*[^0-9]/tmp/b directory
4, CP-R/ETC/[^[:ALPHA:]][[:AIPHA:]]*/TMP/C

5. Learning progress and task of self-study--linux "bash features in the shell"

Related Article

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.