Data Warehousing 002 - Review Linux shell command - echo bash_profile bashrc which commands understand alias history

 

 


1.echo print.

Echo effect is to print out the contents on the screen, and file and persistence can be understood as not the slightest relevance. Such as: print on the screen "echo effect is to print the text!"

    

   Example 1: The environment variable name of the output of the system $ PATH

[root@localhost ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# 

 

 Example 2: Path View command belongs where, first of all go to $ PATH to find, if you find the first result is returned and displayed

[root@localhost ~]# which ls
alias ls='ls --color=tty'
        /bin/ls
[root@localhost ~]#

 

 Examples 3: PATH = '' only clear the current session session variable $ PATH, and no global effect.

[root@localhost ~]# PATH=''
[root@localhost ~]# echo $PATH

[root@localhost ~]# which ls
LS Alias = ' LS --color TTY = ' 
[root @ localhost ~ ] # LS
 - bash: LS: No such file or directory
[root@localhost ~]# 

  Restore the current session session variable $ PATH:

[root@localhost ~]#  PATH='/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin'
[root@localhost ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# which ls
alias ls='ls --color=tty'
        /bin/ls
[root@localhost ~]# ls
anaconda-ks.cfg  install.log.syslog  password.txt
install.log      ntuser.pol          student.txt
[root@localhost ~]# 

 

 

2. environment variable.

  Global: / etc / profile     system-level environment variables, providing all users
  personal: ~ / .bash_profile        user level do not share an environment variable, but in the use of tools such as SecureCRT connection log, variables within the configuration file values , Some commands will not default load
       ~ .bashrc /                  user level shared environment variables, and other tools after use SecureCRT connection log, configuration variables within the file value is still valid

  

  Take effect file: Source xxxx
       ~ / .bashrc.

 

Understanding 3.which command.

  Action which command is specified in the PATH variable path, searches the position of a system command, and returns a search result first.

  In other words, the use of which command, you can see whether there is a system command, and in the end which is a position of command execution. 

  Command parameters:

    -n specify a file name length, must be specified length equal to or greater than the longest of all the file name of the file.

    -p and -n parameters the same, but here include the path to the file.

    -w Specifies the width of the output field.

    -V Display version information

 

4. alias.

  Aliases can be written in a manner vi .bash_profile, .bashrc or / etc / profile file, so that it has the defined alias persistent, it is to be noted that, depending on the written files will have different effects, particularly 2. the reference environment variable file specification.

[root@localhost ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhost ~]# alias l='cd /home/linux'
[root@localhost ~]# l
[root@localhost linux]# 

 

 

5. Delete

[root@localhost linux]# touch xxx.log
[root@localhost linux]# ll
总计28 
Drwxr -Xr-X 2 Linux Linux 4096  10 - 16  06 : 02 Desktop
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
-rw-r--r-- 1 root  root     0 11-22 01:01 xxx.log
[root@localhost linux]# rm -f xxx.log 
[root@localhost linux]# ll
总计24 
Drwxr -Xr-X 2 Linux Linux 4096  10 - 16  06 : 02 Desktop
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# cat /dev/null > xxx.log
[root@localhost linux]# ll
总计28 
Drwxr -Xr-X 2 Linux Linux 4096  10 - 16  06 : 02 Desktop
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
-rw-r--r-- 1 root  root     0 11-22 01:02 xxx.log
[root@localhost linux]# rm -f xxx.log 
[root@localhost linux]# ll
总计24 
Drwxr -Xr-X 2 Linux Linux 4096  10 - 16  06 : 02 Desktop
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# mkdir 1111
[root@localhost linux]# ll
总计32 
drwxr -xr-x 2 root root   4096  11 - 22  01 : 02  1111 
drwxr -xr-x 2 linux linux 4096  10 - 16  06 : 02 Desktop
 -rw-rw-r-- 1 linux linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# rm -rf 1111/
[root@localhost linux]# ll
总计24 
Drwxr -Xr-X 2 Linux Linux 4096  10 - 16  06 : 02 Desktop
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 04 File1.Txt
 -Rw-Rw-R-- 1 Linux Linux     0  10 - 16  07 : 07 File2.Txt
drwxrwxr-x 2 linux linux 4096 10-16 07:10 ml
[root@localhost linux]# 

  Wherein the file: touch xxx.log 

        CAT / dev / null> xxx.log              vi command will generate a new file

     Folder: mkdir

   rm -f rz.log11 delete a file
   -rf 1 rm delete folders

 

6.history

[root @ localhost Linux] # History
     1   History
     2    echo " effect echo is to print the text! " 
    3   the ping www.baidu.com
     4   History
[root @ localhost Linux] # ! 2 
 echo " effect echo is to print the text! "
Echo effect is to print the text!
[root@localhost linux]# 

  ! 2 said: implementation of Article 2 of the specified command history , since Linux does not recycle bin , so when the risk of high-risk command: rm -rf /, the result is a very serious very serious, but this instruction we tend to be inadvertently use the following is a typical case of shell script:  

= K ' / Home / Jepson ' 
K = ''
$ K command to determine whether there is
rm -rf $K/*

  

  Then, once such consequences how to do it? The answer of course is to remove the history of the record, using the history -c command to clear the history, but this is only a direct connection for the use of tools such as SecureCRT, or stepping stones, when used for the purposes of the fortress machine will record your actions or commands .

[root @ localhost Linux] # History
     1   History
     2    echo " effect echo is to print the text! " 
    3   the ping www.baidu.com
     4   History
[root @ localhost Linux] # ! 2 
 echo " effect echo is to print the text! "
Echo effect is to print the text!
[root@localhost linux]# history -c 
[root@localhost linux]# history
    1  history

 

 

 

Guess you like

Origin www.cnblogs.com/Raodi/p/11909415.html