zoukankan      html  css  js  c++  java
  • Linux历史命令和命令别名

    历史命令--history
    history -c 清空历史命令

    history -w 把缓存中的历史命令写入历史命令保存文件,默认文件为~/.bash_history

    历史命令默认会保存1000条,可以在环境变量配置文件/etc/profile中进行修改

    历史命令的调用方法
    1.使用上下箭头可以调用历史命令
    2.使用"!n" 重新执行第n条命令
    3.使用"!!"重新执行上一条命令
    4.使用"!xxx" 重新执行最后一条以字符串"xxx"开头的命令

    命令别名--alias
    1.自定义一个别名
    alias 别名="原命令"
    如下所示:

     1 [root@LAMP ~]# alias netstat="netstat -anpt"  //定义一个别名
     2 [root@LAMP ~]# alias
     3 alias cp='cp -i'
     4 alias l.='ls -d .* --color=auto'
     5 alias ll='ls -l --color=auto'
     6 alias ls='ls --color=auto'
     7 alias mv='mv -i'
     8 alias netstat='netstat -anpt'  //别名定义成功可使用alias查看
     9 alias rm='rm -i'
    10 alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    11 [root@LAMP ~]# netstat
    12 Active Internet connections (servers and established)
    13 Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    14 tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2036/sshd           
    15 tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1926/cupsd 

    使用命令alias定义的别名只是临时生效,重启后失效,
    如果要让别名永久生效需要写入配置文件中

    vim ~/.bashrc 使用vim编辑当前用户的.bashrc文件,将别名定义写到文件中可永久生效

     1 删除别名
     2 [root@LAMP ~]# unalias netstat
     3 [root@LAMP ~]# alias      //查看别名netstat已被删除
     4 alias cp='cp -i'
     5 alias l.='ls -d .* --color=auto'
     6 alias ll='ls -l --color=auto'
     7 alias ls='ls --color=auto'
     8 alias mv='mv -i'
     9 alias rm='rm -i'
    10 alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    11 
    12 查看当前环境命令查找路径
    13 [root@LAMP ~]# echo $PATH
    14 /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
  • 相关阅读:
    C#磁吸屏幕窗体类库
    准备
    我写的诗
    How to turn off a laptop keyboard
    How to tell which commit a tag points to in Git?
    Why should I care about lightweight vs. annotated tags?
    How to get rid of “would clobber existing tag”
    Facebook, Google and Twitter threaten to leave Hong Kong over privacy law changes
    The need for legislative reform on secrecy orders
    Can a foreign key be NULL and/or duplicate?
  • 原文地址:https://www.cnblogs.com/iaknehc/p/6918605.html
Copyright © 2011-2022 走看看