linux添加变量

[root@xclinux ~]# alias
alias cp=’cp -i’
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mv=’mv -i’
alias rm=’rm -i’
alias s=’ls -alt /var/’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’

[root@xclinux ~]# vi .bashrc
并且写入alias s=’ls -alt /var/’
定以后可在其他终端实现alias s=’ls -alt /var/’

[root@xclinux ~]# which ls 显示ls的绝对路径
alias ls=’ls –color=auto’
/bin/ls

[root@xclinux ~]# ls
111 12.txt 12.txz~ 222 anaconda-ks.cfg install.log.syslog
123.txt 12.txt~ 1q 234 install.log xingcheng
[root@xclinux ~]# which ls install.log
alias ls=’ls –color=auto’
/bin/ls
/usr/bin/which: no install.log in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
intall不在/usr/local/sbin:/usr/local/bin:/sbin:/bin:等路径下

[root@xclinux ~]# echo $PATH 查看PATH变量
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@xclinux ~]# cp install.log /usr/bin 拷贝install.log至/usr/bin/目录下
[root@xclinux ~]# which install.log
/usr/bin/which: no install.log in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@xclinux ~]# chmod +x /usr/bin/install.log 赋予install.log可执行权限
[root@xclinux ~]# which install.log
/usr/bin/install.log

[root@xclinux ~]# mv /bin/ls /tmp/ 将bin/目录下的ls移动到 /tmp目录下
[root@xclinux ~]# ls
-bash: /bin/ls: 没有那个文件或目录
[root@xclinux ~]# /tmp/ls 使用绝对路运行ls
111 12.txt 12.txz~ 222 anaconda-ks.cfg install.log.syslog
123.txt 12.txt~ 1q 234 install.log xingcheng
[root@xclinux ~]# PATH=$PATH:/tmp/ 重新定义/tmp/的PATH环境(只在当前终端生效)
[root@xclinux ~]# ls
111 12.txt 12.txz~ 222 anaconda-ks.cfg install.log.syslog
123.txt 12.txt~ 1q 234 install.log xingcheng

[root@xclinux ~]# which ls
alias ls=’ls –color=auto’
/tmp/ls 发现ls的路径为变动后的路径

[root@xclinux ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
发现/tmp/目录已加入PATH环境

[root@xclinux ~]# vi /etc/profile
底部输入 PATH=$PATH:/tmp/ 可在其他终端下实现 ls

重启后生效

[root@xclinux ~]# source /etc/profile 即时生效

重新登录终端
login as: root
Authenticating with public key “xingchenglinux.com”
Passphrase for key “xingchenglinux.com”:
Last login: Fri Dec 11 15:28:07 2015 from 192.168.205.1
[root@xclinux ~]# ls
111 12.txt 12.txz~ 222 anaconda-ks.cfg install.log.syslog
123.txt 12.txt~ 1q 234 install.log xingcheng
[root@xclinux ~]# which ls
alias ls=’ls –color=auto’
/tmp/ls

未经允许不得转载: » linux添加变量
微信公众号:这是个测试
关注我们,每天分享更多有趣的事儿,有趣有料!
12000人已关注
分享到:
赞(0) 打赏

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏