Debian 终端Shell命令行长路径改为短路径的步骤

 更新时间:2023年12月06日 11:35:59   作者:izwmain  
要将Debian终端Shell的命令行长路径更改为较短路径,可以按照以下步骤进行操作,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧

需要修改bashrc

~/.bashrc

先备份一份

cp .bashrc bashrc.backup

编辑bashrc

vim ~/.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 anything
case $- in
    *i*) ;;
      *) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) 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(1)
HISTSIZE=1000
HISTFILESIZE=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 ]; 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 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=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 -l'
#alias la='ls -A'
#alias l='ls -CF'
# 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

别的都不用关心

找到这样一段代码

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

将其中的\w改为\W,也就是把小写w改为大写W

改完后保存退出

执行

source .bashrc

可以看到终端路径不论cd了多少层目录,都只会显示最后的文件夹名称

到此这篇关于Debian 终端Shell命令行长路径改为短路径的文章就介绍到这了,更多相关Shell命令行长路径改为短路径内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 详解Shell if else语句的具体使用方法

    详解Shell if else语句的具体使用方法

    这篇文章主要介绍了详解Shell if else语句的具体使用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • makefile中的shell变量语法及用法总结

    makefile中的shell变量语法及用法总结

    在 Makefile 中,变量的使用规则确实容易让人混淆,下面我来总结一下常见的几种用法及其含义,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧
    2026-02-02
  • jenkins 实现shell脚本化定时执行任务的方法

    jenkins 实现shell脚本化定时执行任务的方法

    这篇文章主要介绍了jenkins 实现shell脚本化定时执行任务,解决访问是jenkins构建好之后将jar远程推送到生产服务器,提前退出后台执行服务器远程脚本,脚本通过ngnx提前切走nginx代理auction sleep 1800s,半小时后执行更新重启,具体操作过程跟随小编一起看看吧
    2022-01-01
  • 利用Shell脚本循环读取文件中每一行的方法详解

    利用Shell脚本循环读取文件中每一行的方法详解

    读取文件是我们在日常工作中经常遇到的一个需求,下面这篇文章主要给大家介绍了关于利用Shell脚本循环读取文件中每一行的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习下吧。
    2017-09-09
  • 一些Hbase Shell的常用命令用法

    一些Hbase Shell的常用命令用法

    这篇文章主要介绍了一些Hbase的常用命令用法,文中说明了各个命令的用法,帮助小伙伴们更快熟悉运用,需要的朋友可以参考下
    2023-03-03
  • 一文掌握Linux命令lsscsi

    一文掌握Linux命令lsscsi

    想要弄明白lsscsi命令,首先我们必须搞清楚什么是SCSI,以及常见的硬盘接口,常用的硬盘参数,今天通过本文给大家介绍下Linux命令lsscsi,需要的朋友可以参考下
    2022-09-09
  • linux awk高级应用实例

    linux awk高级应用实例

    今天看到unix shell 范例精解上有道awk的题目 做了以后拿来和大家分享下
    2016-08-08
  • Linux 下vim使用教程

    Linux 下vim使用教程

    Vim是从 vi 发展出来的一个文本编辑器。这篇文章给大家介绍Linux 下vim使用教程,感兴趣的朋友跟随脚本之家小编一起看看吧
    2018-07-07
  • Shell脚本实现关闭多余的tty终端

    Shell脚本实现关闭多余的tty终端

    这篇文章主要介绍了Shell脚本实现关闭多余的tty终端,本文脚本适用centos6系统,请根据自己的服务器系统情况选择使用,需要的朋友可以参考下
    2014-12-12
  • linux上搭建solr的操作方法(用tomcat部署)

    linux上搭建solr的操作方法(用tomcat部署)

    下面小编就为大家分享一篇linux上搭建solr的操作方法(用tomcat部署),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2017-12-12

最新评论