创建自定义命令和修改系统内置命令

我们知道ll命令文件大小列的单位是字节,但一些比较大的文件以字节为单位非常不方便阅读,加入-h参数可以把大于1024字节的数值转为以KB、MB、GB等为单位,但是每次都要手动输入-h参数很麻烦,这时就可以修改ll命令使其默认使用-h参数。
 
 
 
[root@localhost ~]# vim ~/.bashrc
# .bashrc
 
# User specific aliases and functions
 
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -ahl --time-style="+%Y年%m月%d日 %H:%M:%S"'
 
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
[root@localhost ~]# shutdown -r now # 重启生效
 
 
 
创建自定义命令可以帮我们简化命令从而方便记忆和输入,如下面的长命令:
[root@localhost ~]# /program/apache/bin/apachectl start   # 启动Apache
[root@localhost ~]# /program/apache/bin/apachectl stop    # 停止Apache
[root@localhost ~]# /program/apache/bin/apachectl restart # 重启Apache
 
只要在“~/.bashrc”文件里加入『alias apache='/program/apache/bin/apachectl'』就可以用下面的短命令:
[root@localhost ~]# apache stop    # 停止Apache
[root@localhost ~]# apache start   # 启动Apache
[root@localhost ~]# apache restart # 重启Apache

Copyright © 2024 码农人生. All Rights Reserved