linux进入环境变量目录,linux下环境变量PATH的用法

echo $PATH

可以查看系统的环境变量PATH的值,使用which命令可以查看某个命令所在的绝对路径;[root@localhost ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@localhost ~]# whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

[root@localhost ~]# which cat

/bin/cat

执行命令PATH=$PATH:/tmp  可以把/tmp目录加到PATH里面

这样我们可以使用/tmp/下面的可执行文件作为命令让PATH永久生效的,需要把它加入到/etc/profile 最后一行里,重启生效,或者直接运行命令生效: source  /etc/profile = . /etc/profile

[root@localhost ~]# PATH=$PATH:/tmp

[root@localhost ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

[root@localhost ~]# cp /bin/cat /tmp/yong

[root@localhost ~]# ls /tmp/

yong  yum.log

[root@localhost ~]# yong /tmp/passwd | head -1

root:x:0:0:root:/root:/bin/bash

#加入PATH后/tmp下面的命令可以直接运行。yong相当于cat

关于alias别名

查询别名,只在当前窗口生效。

[root@localhost /]# 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 which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

自定义alias别名

[root@localhost /]# alias aming='ls /tmp/'

[root@localhost /]# aming

yum.log

[root@localhost /]# ls /tmp/

yum.log

alias设置命令的别名,例如 alias aming='ls -lt'  只是临时使用,重启不存在。

解除别名使用 unalias  aming  让别名永久生效,需要把设置别名的命令,加入到 /root/.bashrc 里[root@localhost ~]# cat /root/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

alias yo='ls -l'

yo=‘ls -l' 这一条为新增的;

[root@localhost~]#source /root/.bashrc

#别名生效需要执行此命令,等同于. /root/.bashrc ,或者重启后生效。

[root@localhost ~]# yo

total 24

-rw-------. 1 root root      1090 Nov 13 09:29 anaconda-ks.cfg

-rw-r--r--. 1 root root      9119 Nov 13 09:29 install.log

-rw-r--r--. 1 root root      3091 Nov 13 09:28 install.log.syslog

yo别名生效,yo=ls -l 命令;

查看用户家目录的命令    ehco $HOME

[root@localhost tmp]# echo $HOME

/root

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值