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

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

例如:

# novel-git begin

alias 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() 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 anything

case $- in

    *i*) ;;

      *) return;;

esac

# don't put duplicate lines or lines starting with space in the history.

# See bash() for more options

HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it

shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash()

HISTSIZE=

HISTFILESIZE=

# 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()

[ -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 ]; then

    debian_chroot=$(cat /etc/debian_chroot)

fi

# set a fancy prompt (non-color, unless we know we "want" color)

case "$TERM" in

    xterm-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=yes

if [ -n "$force_color_prompt" ]; then

    if [ -x /usr/bin/tput ] && tput setaf  >&/dev/null; then

# We have color support; assume it's compliant with Ecma-48

# (ISO/IEC-). (Lack of such support is extremely rare, and such

# a case would tend to support setf rather than setaf.)

color_prompt=yes

    else

color_prompt=

    fi

fi

if [ "$color_prompt" = yes ]; then

    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

else

    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

    ;;

*)

    ;;

esac

# enable color support of ls and also add handy aliases

if [ -x /usr/bin/dircolors ]; then

    test -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 aliases

alias ll='ls -alF'

alias la='ls -A'

alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:

#   sleep ; alert

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[-]\+\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_aliases

fi

# 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; then

  if [ -f /usr/share/bash-completion/bash_completion ]; then

    . /usr/share/bash-completion/bash_completion

  elif [ -f /etc/bash_completion ]; then

    . /etc/bash_completion

  fi

fi

# novel-git begin

alias 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

Linux(Ubuntu)使用日记------自定义命令的使用的更多相关文章

  1. Linux(Ubuntu)使用日记------markdown文档转化为word文档

    Linux(Ubuntu)使用日记------markdown文档转化为word文档

  2. Linux(Ubuntu)使用日记------Mysql编码(utf-8)的设置

    Mysq版本:5.7.21 操作系统:Linux(Ubuntu) 整个操作的基本思路如下(包括问题的解决思路,想要直接解决问题的可以先看最后的命令总结) 检查mysql编码 找到Mysql的配置文件 ...

  3. Linux Ubuntu 常见的压缩命令

    小知识: Linux上常见的压缩命令就是gzip与bzip2,compress已经不再流行.gzip是有GNU计划所开发出来的压缩命令,该命令已经替换了compress命令.后来GNU又开发出bzip ...

  4. Linux(Ubuntu)使用日记(零)------使用Linux的理由

    我为什么要使用Linux呢,也许在某些人看来或许是装B,但是我的原因有点复杂,简单做下总结(以事情的发展历程为顺序) 升级后开机慢关机慢,崩溃.最近刚刚升级了windows,自己原来的win10其实是 ...

  5. Linux(Ubuntu)使用日记------部署JavaWeb项目到服务器

    0.前言 本博文内容是建立在你可以通过SSH连接到远程服务器的基础上的,如果你还没有用SSH连接到远程服务器,请参考此文(腾讯云服务器): http://www.cnblogs.com/hwtblog ...

  6. Linux(Ubuntu)使用日记------Mongodb的安装与使用

    1.安装 Linux下安装mongodb还是比较容易的 直接使用apt-get安装即可,命令如下: sudo apt-get install mongodb 安装完成之后进行检验, “mongo sh ...

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

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

  8. Linux(Ubuntu)使用日记(三)------git安装使用

    1. 安装 首先,确认你的系统是否已安装git,可以通过git指令进行查看,如果没有,在命令行模式下输入sudo apt-get install git命令进行安装. 2.  配置 git confi ...

  9. Linux(Ubuntu)使用日记(四)------印象笔记相关使用

    在Ubuntu系统下没有印象笔记官方的客户端,但是这并不能阻拦我们使用印象笔记. 我们一般的的使用习惯: 印象笔记客户端 印象笔记剪藏 Linux下也可以使用两个工具,剪藏的话安装比较简单,印象笔记客 ...

随机推荐

  1. Spring中BeanFactory的对象注册与依赖绑定方式

    概念 BeanFactory是spring的基础类型IOC容器,提供完整的IOC服务支持 默认采用延迟初始化策略,当客户端对象访问受管对象时,才对其进行初始化和依赖注入 理解 BeanFactory将 ...

  2. 都2019年了,还问GET和POST的区别

    摘要: 对比GET与POST. 原文:都9102年了,还问GET和POST的区别 作者:程淇铭 Fundebug经授权转载,版权归原作者所有. 1. 前言 最近看了一些同学的面经,发现无论什么技术岗位 ...

  3. React的组件模式

    组件是 React 的核心,因此了解如何利用它们对于创建优秀的设计结构至关重要. 什么是组件 根据 React 官网的介绍,"组件让你可以将 UI 分割成独立的.可重用的部分,并独立管理每个 ...

  4. loj#6073. 「2017 山东一轮集训 Day5」距离(费用流)

    题意 题目链接 Sol 我们可以把图行列拆开,同时对于行/列拆成很多个联通块,然后考虑每个点所在的行联通块/列联通块的贡献. 可以这样建边 从S向每个行联通块连联通块大小条边,每条边的容量为1,费用为 ...

  5. 从零学习Fluter(二):win10上环境搭建以及模拟器和真机调试

    今天呢,又继续看了flutter 弗拉特 的东西,绝的这个东西绝对是比ReactNative更高一层次的,在2018年12月5好,flutter的第一个stale1.0发布了,我们在GitHub上可以 ...

  6. 自动的自动化:EvoSuite 自动生成JUnit的测试用例

    EvoSuite简介 EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行.得到了Google和Y ...

  7. 英语口语练习系列-C22-吃东西

    基础词汇 1. bill [bɪl] n. 账单:钞票:法案:鸟嘴 Bill (人名)比尔 pay the bill 付账单 telephone bill 话费单 electricity bill 电 ...

  8. Scheme来实现八皇后问题(1)

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/9768105.html 作者:窗户 Q ...

  9. vue 组件开发、vue自动化工具、axios使用与router的使用(3)

    一. 组件化开发 1.1 组件[component] 在网页中实现一个功能,需要使用html定义功能的内容结构,使用css声明功能的外观样式,还要使用js定义功能的特效,因此就产生了一个功能先关的代码 ...

  10. KERBEROS PROTOCOL TUTORIAL

    KERBEROS PROTOCOL TUTORIAL   This tutorial was written by Fulvio Ricciardi and is reprinted here wit ...