[linux]mark-tool

简介: [linux]mark-tool

前言

在远程连接到linux进行操作时,经常要切换目录,有些目录切换频次较高,因此写了个shell工具,用于收藏目录、切换目录等。也不需要安装,直接添加脚本即可。

配置

首先声明脚本是基于bash shell,zsh和fish未经测试。

  1. 编辑文件~/.bash_custom_functions,添加以下内容
mark(){
    local markfile="$HOME/.mark"
    if [ ! -f ${markfile} ]; then
        echo "${markfile} is not exist, create it."
        touch ${markfile}
    fi
    case $1 in
        l)
            cat -n ${markfile}
            ;;
        d)
            # delete
            if [ "x" == "x$2" ]; then
                echo "need a sequence number"
                return 1
            fi
            if [ $2 -lt 0 ] || [ $2 -gt $(wc -l < ${markfile}) ]; then
                echo "invalid sequence number"
                return 1
            fi
            sed -i "$2d" ${markfile}
            ;;
        a)
            # add / append
            local new_mark=$(pwd)
            local tmp_grep=$(grep ${new_mark} ${markfile})
            if [ "x" == "x${tmp_grep}" ]; then
                echo "mark current dirname: ${new_mark}"
                echo ${new_mark} >> ${markfile}
            else
                echo "Warning! Duplicate mark"
            fi
            ;;
        c)
            # cd
            if [ "x" == "x$2" ]; then
                echo "need a sequence number"
                return 1
            fi
            if [ $2 -lt 0 ] || [ $2 -gt $(wc -l < ${markfile}) ]; then
                echo "invalid sequence number"
                return 1
            fi
            local target_dir=$(sed -n "$2p" ${markfile})
            if [ ! -d ${target_dir} ]; then
                echo "${target_dir} not found"
                return 1
            fi
            cd ${target_dir}
            ;;
        *)
            echo "Options: l(ist), a(dd), d(elete), c(hange)"
    esac
}
  1. ~/.bashrc中追加以下内容以引入上一步的文件
if [ -f ~/.bash_custom_functions ]; then
    . ~/.bash_custom_functions
fi
  1. source生效,或者重建shell会话
source ~/.bashrc
相关文章
|
Ubuntu Linux 虚拟化
LinuxUbuntu安装VMware tools Segmentation fault (core dumped)怎么解决
更新操作系统和内核:使用apt-get或apt命令更新你的Ubuntu操作系统和内核。运行以下命令更新软件包:
1371 0
|
7月前
|
Linux
Linux Section
Linux Section
70 2
|
9月前
|
Linux 数据处理 数据库
深入探索Linux的package-cleanup命令
`package-cleanup`是Linux(尤其是RPM系统如CentOS)中的实用工具,用于清理和管理已安装的RPM包。它列出依赖问题、重复包,删除旧内核,并找出孤立软件包。关键参数包括`--problems`, `--dupes`, `--cleandupes`, `--leaves`, `--orphans`和`--oldkernels`。使用时注意备份,谨慎操作,并可结合`yum`定期维护系统。例如,`package-cleanup --oldkernels --count=2`用于删除除最新两个内核外的旧内核。
|
9月前
|
Linux Shell 网络安全
Linux 命令 `clear` 详解
了解 Linux 的 `clear` 命令,用于清除终端屏幕,保持整洁。只需输入 `clear` 或使用 `Ctrl + L` 快捷键,也可尝试 `reset` 命令和 `printf &quot;\033c&quot;`。注意,`clear` 不会删除历史数据,仅清空屏幕显示。这个命令能提升终端使用体验和工作效率。
|
10月前
|
Ubuntu Linux 内存技术
Linux(14)Debain Make image and module configuration instructions
Linux(14)Debain Make image and module configuration instructions
45 0
|
10月前
|
网络协议 Unix Linux
linux note
linux note
|
XML 存储 监控
Linux - Sysstat [ All-in-One System Performance and Usage Activity Monitoring Tool For Linux]
Linux - Sysstat [ All-in-One System Performance and Usage Activity Monitoring Tool For Linux]
131 0
|
Unix Linux 开发工具
Linux Command diff 文件比较
Linux Command diff 文件比较
Linux Command diff 文件比较
|
Linux vr&ar NoSQL
Linux Debug tools
1. gdb attach [pid] -- debug a running process 2. valgrind-- a suite of tools for debugging and profiling programs Very powerful tool to debug linux program,just for x86 platform 3.
1122 0

相关课程

更多