Linux如何自定义自己的命令呢?修改 系统中的 ~/.bashrc 文件即可

在这个文件最后面使用alias命令重定义命令。

例如:

# novel-git beginalias n.r='less -s ${novel_path}/reading/`ls novel/reading`'alias n.g='${novel_path}/auto-git.sh'alias n.n='vim ${novel_path}/note'export novel_path=~/novel# nove-git end

修改完成之后要使用命令 source  ~/.bashrc 刷新

这个脚本是我的一个小说阅读器,左边阅读,右上笔记,右下使用git保存笔记到github

我的novel目录:

操作思路:

对于长的脚本,我们可以写一些脚本,放到特定的一个文件夹下,在bashrc文件中执行这个脚本,

对于短的命令,我们直接重命名即可。

附录

我的bashrc 文件

# ~/.bashrc: executed by bash(1) for non-login shells.# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)# for examples# If not running interactively, don't do anythingcase $- in*i*) ;;*) return;;esac# don't put duplicate lines or lines starting with space in the history.

# See bash(1) for more optionsHISTCONTROL=ignoreboth# append to the history file, don't overwrite it

shopt -s histappend# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)HISTSIZE=1000HISTFILESIZE=2000# check the window size after each command and, if necessary,# update the values of LINES and COLUMNS.shopt -s checkwinsize# If set, the pattern "**" used in a pathname expansion context will# match all files and zero or more directories and subdirectories.#shopt -s globstar# make less more friendly for non-text input files, see lesspipe(1)[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"# set variable identifying the chroot you work in (used in the prompt below)if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; thendebian_chroot=$(cat /etc/debian_chroot)fi# set a fancy prompt (non-color, unless we know we "want" color)case "$TERM" inxterm-color|*-256color) color_prompt=yes;;esac# uncomment for a colored prompt, if the terminal has the capability; turned# off by default to not distract the user: the focus in a terminal window# should be on the output of commands, not on the prompt#force_color_prompt=yesif [ -n "$force_color_prompt" ]; thenif [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then# We have color support; assume it's compliant with Ecma-48

# (ISO/IEC-6429). (Lack of such support is extremely rare, and such# a case would tend to support setf rather than setaf.)color_prompt=yeselsecolor_prompt=fifiif [ "$color_prompt" = yes ]; thenPS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 'elsePS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'fiunset color_prompt force_color_prompt# If this is an xterm set the title to user@host:dircase "$TERM" inxterm*|rxvt*)PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";;*);;esac# enable color support of ls and also add handy aliasesif [ -x /usr/bin/dircolors ]; thentest -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"alias ls='ls --color=auto'#alias dir='dir --color=auto'#alias vdir='vdir --color=auto'alias grep='grep --color=auto'alias fgrep='fgrep --color=auto'alias egrep='egrep --color=auto'fi# colored GCC warnings and errors#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'# some more ls aliasesalias ll='ls -alF'alias la='ls -A'alias l='ls -CF'# Add an "alert" alias for long running commands.  Use like so:#   sleep 10; alertalias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.# You may want to put all your additions into a separate file like# ~/.bash_aliases, instead of adding them here directly.# See /usr/share/doc/bash-doc/examples in the bash-doc package.if [ -f ~/.bash_aliases ]; then. ~/.bash_aliasesfi# enable programmable completion features (you don't need to enable

# this, if it's already enabled in /etc/bash.bashrc and /etc/profile

# sources /etc/bash.bashrc).if ! shopt -oq posix; thenif [ -f /usr/share/bash-completion/bash_completion ]; then. /usr/share/bash-completion/bash_completionelif [ -f /etc/bash_completion ]; then. /etc/bash_completionfifi# novel-git beginalias n.r='less -s ${novel_path}/reading/`ls novel/reading`'alias n.g='${novel_path}/auto-git.sh'alias n.n='vim ${novel_path}/note'export novel_path=~/novel# nove-git end

View Code

转载于:https://www.cnblogs.com/hwtblog/p/8466428.html

Linux(Ubuntu)使用日记------自定义命令的使用相关推荐

  1. linux使用vim复制文件内容,Linux(Ubuntu)使用日记------vim复制内容到其他应用

    1.用vim 打开一个文件,然后执行命令:reg 查看是否有 + 或者 × 号  或者执行:version 命令 查看是否有+clipboard 2.如果存在跳过此步骤.如果不存在:在终端输入 sud ...

  2. Linux/mac下的自定义命令alias,并保存别名使其永久生效(重启不会失效)

    linux/mac下的自定义命令alias,并保存别名使其永久生效(重启不会失效) 现在做开发每次提交代码的命令都是一长串参数,不想去记,于是可以使用alias命令来解决这个问题: alias aCo ...

  3. linux(ubuntu)查看硬件设备命令

    linux查看设备命令 系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # ...

  4. Linux/Ubuntu操作系统及常用命令

    一.概述 操作系统:是直接运行在计算机上的系统软件,是控制硬件和支持软件运行的计算机程序 常见操作系统:Windows.Linux.macOS.iOS.Android 虚拟机软件:是能够虚拟出计算机的 ...

  5. Linux(Ubuntu)内存查询top命令详解

    linux中的top命令详解 引言 top命令是UNIX/Linux系统中,用于查看系统详情的第一入口,一般我们查看机器运行状态的时候,总是第一个使用top命令,而实际上top命令展示的数据很多,对于 ...

  6. Linux(Ubuntu)使用日记------ssh远程登录腾讯云

    不知道是我自己电脑的问题还是其他的问题.总之在我的折腾之下算是用ssh连接上了我的腾讯云. 具体步骤: 1.生成密钥 ssh-keygen -t rsa 执行命令会出现这样,执行后让你输入东西的全部回 ...

  7. linux ubuntu 设置ip地址命令行,Ubuntu Linux上的IP地址管理

    如今,一切都在互联网上.说"互联网已经成为我们生活的基本必需品"是正确的.互联网是相互连接的网络的网络.要浏览互联网,应该了解网络的基本知识,即如何将本地网络连接到互联网.首先,连 ...

  8. ubuntu下alias自定义命令详解

    在linux环境下操作,经常涉及不同项目路径跳转的问题,每次cd就很麻烦,下面使用alias就可以缓解这类问题 alias命令用来设置命令的别名,从而将一些较长的命令进行简化.使用alias时,必须使 ...

  9. linux ubuntu配置ip地址命令,Ubuntu系统下配置IP地址方法介绍

    接到一客户的服务器,开机已启动发现是Ubuntu系统,当时有点郁闷了,心想没有配置过ubuntu系统,这客户还在旁边了,心里有点紧张了,于是开始上网寻找各种方法配置,最终将IP配置好,给客户上架调试通 ...

最新文章

  1. poj2409(纯Polya定理)
  2. 新浪股票接口AndroidSDK
  3. Microsoft Azure Express Route (专线直连)到云端数据中心(2)
  4. 大规模分布式消息中间件考虑点
  5. idea如何删除java里面工程,Java开发工具IntelliJ IDEA配置项目系列教程(七):卸载模块...
  6. 使用jquery文件上传控件Uploadify来异步上传图片
  7. 怎么取html网页中的样式,从建站到拿站 -- HTML和CSS基础
  8. pyqt5讲解8:容器QTabWidget,QStackedWidget,QDockWidget
  9. Spring Security with Spring Boot 2.0:密码编码器
  10. c#日期转换周几_Java时间与日期
  11. java反射随意值_Java反射总结
  12. 《Java 学习笔记》 第剩余章节阅读体验附书评。
  13. Sk32k144:生成hex文件和烧写(jflash)
  14. ftp 创建工具下载,三款ftp 创建工具下载-免安装版(亲测)
  15. Ubuntu20.04以及Ubuntu18.04修改键盘布局(法语键盘)
  16. 宝塔面板ftp空间连接失败解决方案汇总
  17. 又是一年双11,神棍节终于来啦
  18. Cartesian convention笛卡尔公约
  19. 淘口令解析api接口/淘口令解密还原api接口/淘口令短链接搜索商品详情接口,API接口获取方案
  20. java计算机毕业设计高校实习实训管理系统源码+mysql数据库+系统+lw文档+部署

热门文章

  1. python生成wps文件_使用Python操作XLS文件(wps中叫et)
  2. C#winform可视化(当主窗体不能拖动时)
  3. Flex布局实现筛子3
  4. Csrf漏洞概述及其原理
  5. 2018北京ICPC H. Approximate Matching(AC自动机+DP)
  6. bzoj 4319: cerc2008 Suffix reconstruction(构造)
  7. [Python+Anaconda] 查看Python、Anaconda下python、CUDA、函数库的版本
  8. [Python] 关键字 assert
  9. python网络爬虫系列教程——PhantomJS包应用全解
  10. Java中Link,set 和Map的区别,ArrayList,HashSet和HashMap的区别。