Shell command, alias, wildcard, redirect

Source: Internet
Author: User
Tags aliases egrep

The shell is a command interpreter that provides interaction between the user and the machine
Supports specific syntax, logical judgments, loops
Each user can have their own specific shell
Centos7 default shell is bash
and Zsh and Ksh.
Yum List|grep zsh
Yum List|grep Ksh

Command history

History command
. bash_history
LS/user home directory/.bash_history view History, where historical records are stored

[Email protected] yum.repos.d]# echo $HISTSIZE #查看最大保存历史记录数
1000

[Email protected] yum.repos.d]# history-c #清楚历史记录
[Email protected] yum.repos.d]# history #再次验证, only the one you just used
1 history

Modify History Save Maximum value

Modify in/etc/profile

Soure/etc/profile make the modified number effective

Modify History Command Display time

[Email protected] ~]# histtimeformat= "%y/%m/%d%h:%m:%s"
[Email protected] ~]# echo $HISTTIMEFORMAT
%y/%m/%d%h:%m:%s
Temporary entry into force
[Email protected] ~]# history
1 2018/01/11 05:47:08history
2 2018/01/11 05:47:58ls-l. bash_history
3 2018/01/11 05:48:01CD.
4 2018/01/11 05:48:07CD.
5 2018/01/11 05:48:08pwd
6 2018/01/11 05:48:11cd/root/
7 2018/01/11 05:49:29cat/etc/profile
8 2018/01/11 05:49:44vim/etc/profile
9 2018/01/11 05:49:48vi/etc/profile
Ten 2018/01/11 05:54:50echo $HISTTIMEFORMAT = "%y/%m/d%%h:%ym:%s"
2018/01/11 05:55:18histtimeformat= "%y/%m%d%h:%m:%s"
2018/01/11 05:55:29echo $HISTTIMEFORMAT
2018/01/11 05:55:44histtimeformat= "%y/%m/%d%h:%m:%s"
2018/01/11 05:55:45echo $HISTTIMEFORMAT
2018/01/11 05:56:25history

Permanently active
Vim/etc/profile
histsize=1000
Add: histtimeformat= "%y/%m/%d%h:%m:%s"

Re-login to history verification
2018/01/11 05:48:11cd/root/
331 2018/01/11 05:49:29cat/etc/profile
332 2018/01/11 05:49:44vim/etc/profile
333 2018/01/11 05:49:48vi/etc/profile
334 2018/01/11 05:54:50echo $HISTTIMEFORMAT = "%y/%m/d%%h:%ym:%s"
335 2018/01/11 05:55:18histtimeformat= "%y/%m%d%h:%m:%s"
336 2018/01/11 05:55:29echo $HISTTIMEFORMAT
337 2018/01/11 05:55:44histtimeformat= "%y/%m/%d%h:%m:%s"
338 2018/01/11 05:55:45echo $HISTTIMEFORMAT
339 2018/01/11 05:56:25history
340 2018/01/11 05:56:56yum Install vim
341 2018/01/11 06:00:06vim/etc/profile
342 2018/01/11 06:01:57source $HISTTIMEFORMAT
343 2018/01/11 06:02:56source $!
344 2018/01/11 06:03:51source/etc/profile
345 2018/01/11 06:04:12echo $HISTTIMEFORMAT
346 2018/01/11 06:04:17exit
347 2018/01/11 06:04:25history
348 2018/01/11 06:04:49vim/etc/profile
349 2018/01/11 06:05:31history

Can be permanently saved after normal exit
Chattr +a ~/.bash_history

!! Previous command
! n Nth Command
! echo from the bottom to the last command to start with Echo

Command completion and aliases

tab to fill all the contents of the full command two
Centos7 under the parameters of the complete installation of bash-comletion, press 2 in addition to the command itself can be supplemented, but also to complement the full parameters

Alias aliases

Defining aliases
[[email protected] ~]# alias restartnet= ' systemctl restart Network.service '
[Email protected] ~]# restartnet
Job for Network.service failed. See ' systemctl status Network.service ' and ' journalctl-xn ' for details.
[[email protected] ~]# alias
Alias cp= ' Cp-i '
Alias egrep= ' Egrep--color=auto '
Alias fgrep= ' Fgrep--color=auto '
Alias grep= ' grep--color=auto '
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias mv= ' Mv-i '
Alias restartnet= ' systemctl restart Network.service '
Alias rm= ' Rm-i '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tild

Alias location
1, User home directory/.BASHRC
2,/etc/profile.d/

[Email protected] ~]# cd/etc/profile.d/
[[email protected] profile.d]# ls
256term.csh colorgrep.csh colorls.sh less.csh vim.sh
256term.sh colorgrep.sh lang.csh less.sh which2.csh
bash_completion.sh colorls.csh lang.sh vim.csh which2.sh
[Email protected] profile.d]#

To cancel a custom alias
Unalias aliases

Wildcard characters
    • Any one that satisfies the criteria

? One that satisfies a condition

Range of conditions within range [0-9a-za-z]

{,,,} One of the conditions within the scope that satisfies the

redirect

Output redirection

Correct output to target file
Cat 1.txt > 2.txt output 1.txt content to 2.txt while erasing the original 2.txt content

> Chasing heavier orientation
Cat 2.txt >>2.txt output 1.txt content to 2.txt, while retaining the 2.txt original content

2> Error REDIRECT Output
Output redirection, error output redirect separate
[[email protected] ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt
[email protected] ~]# cat 1.txt
1.txt
2.txt
[email protected] ~]# cat A.txt
LS: Unable to access aaa.txt: No file or directory

&> Error Redirection
[[email protected] ~]# ls [12].txt aaa.txt &> a.txt
[email protected] ~]# cat A.txt
LS: Unable to access aaa.txt: No file or directory
1.txt
2.txt

2>> Error Append redirect
[email protected] ~]# ls aaa.txt 2>>a.txt
[email protected] ~]# cat A.txt
LS: Unable to access aaa.txt: No file or directory
1.txt
2.txt
LS: Unable to access aaa.txt: No file or directory

< input redirection
[Email protected] ~]# wc-l 1.txt
2 1.txt
[Email protected] ~]# Wc-l < 1.txt
2
Only file to command, cannot file to file

Shell command, alias, wildcard, redirect

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.