Server - 优雅的配置服务器 Bash 环境(.bashrc)

欢迎关注我的CSDN:https://spike.blog.csdn.net/
本文地址:https://spike.blog.csdn.net/article/details/147335592

免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。


Bash

登录服务器默认显示简单的环境,需要重新设置 .bashrc,优雅的支持简化的 shell 命令与颜色显示。其中 .bashrc.bash_profile 都位于 /home/[your user name]/ 目录。

.bashrc.bash_profile 都是 Bash Shell 的配置文件,用于设置环境变量、别名等。

  • .bash_profile:在登录时,只被加载一次。
  • .bashrc:在打开新的终端窗口时,都被加载。
  • 在实际应用中,通过在 .bash_profile 中,添加 source ~/.bashrc ,确保在登录时直接加载 ~/.bashrc

自定义 .ssh/config

Host [简写名称] # 自定义别名(如 myserver)HostName [relay.xxx.com]       # 服务器IP或域名User [your name]              # 登录用户名ControlMaster autoControlPath ~/.ssh/controlmasters/%r@%h:%pControlPersist 600ControlPersist 1h  # 保持1小时空闲连接

同时创建 ~/.ssh/controlmasters/ 文件夹:

mkdir -p ~/.ssh/controlmasters
chmod 700 ~/.ssh/controlmasters

登录直接使用:

ssh [简写名称]

默认启动 .bashrc 脚本,需要配置 .bash_profile 文件:

if [ -f ~/.bashrc ]; then. ~/.bashrc
fi

其中 .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 ]; 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=fi
fiif [ "$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\$ '
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 ]; 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 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 10; alert
alias 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_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; thenif [ -f /usr/share/bash-completion/bash_completion ]; then. /usr/share/bash-completion/bash_completionelif [ -f /etc/bash_completion ]; then. /etc/bash_completionfi
fi

参考:GitHub - brtrndb/bashrc

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/80348.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用PyTorch实现图像增广与模型训练实战

本文通过完整代码示例演示如何利用PyTorch和torchvision实现常用图像增广方法,并在CIFAR-10数据集上训练ResNet-18模型。我们将从基础图像变换到复杂数据增强策略逐步讲解,最终实现一个完整的训练流程。 一、图像增广基础操作 1.1 准备工作 #matplotli…

解决Mac 安装 PyICU 依赖失败

失败日志: 解决办法 1、使用 homebrew 安装相关依赖 brew install icu4c 安装完成后,设置环境变量 echo export PATH"/opt/homebrew/opt/icu4c77/bin:$PATH" >> ~/.zshrcecho export PATH"/opt/homebrew/opt/icu4c77/sbin:$PATH…

Springboot后端查询参数接收

1.实现方式 假设前端发送的接口: /users?nameJohn&age30 后端怎么接收里面的name和age呢?以及再发别的参数后端怎么接收呢? 1.比较简单的方式 当控制器方法的参数类型是简单类型(如 String、Integer、Long 等&#xff09…

桌面应用中VUE使用新浏览器窗口打开页面

1、浏览器应用忽略此方式,可任意方式打开。针对桌面应用设置 newWindowClick(){try {this.fileUrl "";this.params.year ""this.params.date ""axios({method: post,url: /url/pdf/preview,data: this.params,}).then(res> {t…

华为手机怎么进行音频降噪?音频降噪技巧分享:提升听觉体验

在当今数字化时代,音频质量对于提升用户体验至关重要,无论是在通话、视频录制还是音频文件播放中,清晰的音频都能带来更佳的听觉享受。 而华为手机凭借其强大的音频处理技术,为用户提供了多种音频降噪功能,帮助用户在…

【数据可视化-22】脱发因素探索的可视化分析

🧑 博主简介:曾任某智慧城市类企业算法总监,目前在美国市场的物流公司从事高级算法工程师一职,深耕人工智能领域,精通python数据挖掘、可视化、机器学习等,发表过AI相关的专利并多次在AI类比赛中获奖。CSDN人工智能领域的优质创作者,提供AI相关的技术咨询、项目开发和个…

青少年编程与数学 02-018 C++数据结构与算法 06课题、树

青少年编程与数学 02-018 C数据结构与算法 06课题、树 一、树(Tree)1. 树的定义2. 树的基本术语3. 常见的树类型4. 树的主要操作5. 树的应用 二、二叉树(Binary Tree)1. 二叉树的定义2. 二叉树的基本术语3. 二叉树的常见类型4. 二叉树的主要操作5. 二叉树的实现代码说明输出示例…

【论文阅读】Visual Instruction Tuning

文章目录 导言1、论文简介2、论文主要方法3、论文针对的问题4、论文创新点总结 导言 本论文介绍了一个新兴的多模态模型——LLaVA(Large Language and Vision Assistant),旨在通过指令调优提升大型语言模型(LLM)在视觉…

【学习笔记】Cadence电子设计全流程(三)Capture CIS 原理图绘制(下)

【学习笔记】Cadence电子设计全流程(三)Capture CIS 原理图绘制(下) 3.16 原理图中元件的编辑与更新3.17 原理图元件跳转与查找3.18 原理图常见错误设置于编译检查3.19 低版本原理图文件输出3.20 原理图文件的锁定与解锁3.21 Orca…

js使用IntersectionObserver实现目标元素可见度的交互

文章目录 1、前言2、代码实现3、使用场景4、兼容性5、成熟的Hooks推荐 1、前言 IntersectionObserver 是浏览器原生提供的一个Api。可以"观察"我们的元素是否可见,原理是判断目标元素与可见区域的交叉比例,所以也被称为"交叉观察器"…

linux 中断子系统 层级中断编程

虚拟中断控制器代码&#xff1a; #include<linux/kernel.h> #include<linux/module.h> #include<linux/clk.h> #include<linux/err.h> #include<linux/init.h> #include<linux/interrupt.h> #include<linux/io.h> #include<linu…

虾皮(Shopee)商品详情 API 接口概述及 JSON 数据返回参考

前言 一、接口概述 Shopee 商品详情 API 接口是 Shopee 平台为开发者提供的&#xff0c;用于获取商品详细信息的接口服务。通过该接口&#xff0c;开发者可以获取商品的标题、价格、库存、描述、图片、规格参数、销量、评价等详细信息。这些数据为电商数据分析、商品比价工具…

three.js中的instancedMesh类优化渲染多个同网格材质的模型

three.js小白的学习之路。 在上上一篇博客中&#xff0c;简单验证了一下three.js中的网格共享。写的时候就有一些想法&#xff0c;如果说某个场景中有一万棵树&#xff0c;这些树共享一个geometry和material&#xff0c;有没有好的办法将其进行一定程度上的渲染优化&#xff0…

MySQL-自定义函数

自定义函数 函数的作用 mysql数据库中已经提供了内置的函数&#xff0c;比如&#xff1a;sum&#xff0c;avg&#xff0c;concat等等&#xff0c;方便我们日常的使用&#xff0c;当需要时mysql支持定义自定义的函数&#xff0c;方便与我们对于需用复用的功能进行封装。 基本…

ESP32上C语言实现JSON对象的创建和解析

在ESP32上使用C语言实现JSON对象的创建和解析&#xff0c;同样可以借助cJSON库。ESP-IDF&#xff08;Espressif IoT Development Framework&#xff09;本身已经集成了cJSON库&#xff0c;你可以直接使用。以下是详细的步骤和示例代码。 1. 创建一个新的ESP-IDF项目 首先&…

【FAQ】PCoIP 会话后物理工作站本地显示器黑屏

# 问题 工作人员从家里建立了到办公室工作站的 PCoIP 连接&#xff0c;该工作站安装了 HP Anyware Graphics Agent&#xff0c;并且还连接了本地显示器。然后&#xff0c;远程用户决定去办公室进行本地工作&#xff0c;工作站显示器显示黑屏&#xff08;有时没有信号&#xff…

el-table 目录树列表本地实现模糊查询

table目录树结构实现模糊查询 <el-form :model"queryParams" ref"queryForm" size"small" :inline"true" v-show"showSearch"><el-form-item label"名称:" prop"Name"><el-input v-mode…

力扣hot100 LeetCode 热题 100 Java 哈希篇

两数之和 1. 两数之和 - 力扣&#xff08;LeetCode&#xff09; 直接暴力 class Solution {public int[] twoSum(int[] nums, int target) {for(int i0;i<nums.length;i){for(int ji1;j<nums.length;j){long ans nums[i]nums[j];if(ans>target)continue;if(anstarg…

前后端部署

#在学习JavaWeb之后&#xff0c;进行了苍穹外卖的学习。在进行苍穹外卖的部署的时候&#xff0c;作者遇到了下面的问题# 1.前端工程nginx无法启动&#xff1a; 当我双击已经部署好的nginx工程中nginx.exe文件的时候&#xff0c;在服务中&#xff0c;并没有找到ngnix成功运行。…

基于 EFISH-SBC-RK3588 的无人机环境感知与数据采集方案

一、核心硬件架构设计‌ ‌高性能算力引擎&#xff08;RK3588 处理器&#xff09;‌ ‌异构计算架构‌&#xff1a;集成 8 核 CPU&#xff08;4Cortex-A762.4GHz 4Cortex-A551.8GHz&#xff09;&#xff0c;支持动态调频与多任务并行处理&#xff0c;单线程性能较传统四核方案…