归档
善良比聪明更重要
11
15
获取 Shell 脚本所在目录的绝对路径 获取 Shell 脚本所在目录的绝对路径
写脚本时经常需要引用脚本同目录下的其他文件(配置、日志目录、依赖脚本等)。这时很多人的第一反应是用 pwd 或者 $0,但这两种做法都有陷阱。总结一下,最可靠的做法其实就是一条命令: root_path=$(cd $(dirname ${B
2020-11-15
08
history:让历史命令显示执行时间 history:让历史命令显示执行时间
Linux 下用 history 查看历史命令时,默认只显示序号和命令本身,看不到这条命令是什么时候执行的,排查问题时很不方便。其实只要设置 HISTTIMEFORMAT 环境变量,就能让 history 显示每条命令的执行时间。 临时生效
2020-11-08
01
Shell 快捷键速查 Shell 快捷键速查
在终端里熟练使用快捷键,能大幅减少手在键盘和鼠标之间来回移动的时间。本文按功能对 Bash 中常用的 Ctrl 快捷键进行分组整理,方便速查。特别提醒:Ctrl+D 在不同语境下有两种完全不同的含义,文末会单独说明。 光标移动 快捷键
2020-11-01
10
25
Shell 脚本条件判断详解 Shell 脚本条件判断详解
条件判断是 Shell 脚本流程控制的基石。本文系统整理 if 语句的基本语法、[ ] 中的各类测试条件,以及 (( )) 和 [[ ]] 这两种高级写法,并附上常见用法示例。 基本语法if [ command ]; then 符合
2020-10-25
18
Shell 基础语法:变量、条件、循环与函数 Shell 基础语法:变量、条件、循环与函数
Shell 脚本是 Linux 运维和日常开发中最常用的自动化工具。本文整理 Shell 最基础的语法知识:变量的定义与引用、字符串操作、条件判断、循环、函数,以及一个脚本究竟有哪几种执行方式、它们之间有什么区别。 变量的定义与引用变量名由
2020-10-18
11
A Guided Tour A Guided Tour
A Guided TourIt’s time to take our tour. The table below lists some interesting places to explore. This is by no means a
2020-10-11
04
Looking Around Looking Around
Looking AroundNow that you know how to move from working directory to working directory, we’re going to take a tour of y
2020-10-04
09
27
Navigation Navigation
NavigationIn this lesson, I will introduce your first three commands: pwd (print working directory), cd (change director
2020-09-27
20
Learning the Shell Learning the Shell
Why Bother?Why do you need to learn the command line anyway? Well, let me tell you a story. A few years ago we had a pro
2020-09-20
13
What is the Shell? What is the Shell?
What Is “The Shell”?Simply put, the shell is a program that takes commands from the keyboard and gives them to the opera
2020-09-13
08
20
Linux 一切皆文件 Linux 一切皆文件
Unix 有一条著名的哲学——「一切皆文件」(everything is a file)。但严格来说,socket 和 pipe 并不完全符合这一点:它们虽然能被当作文件描述符来读写,却没有被纳入统一的目录树命名空间。本文从这一点出发,探讨
2020-08-20
08
glibc 内存分配器原理 glibc 内存分配器原理
内存管理是 C 程序员日常编码中最常见的技术点,能否用得 glibc 内置的内存管理函数,是衡量 C 程序员水平的重要标准。本文从几个 C 语言中常见的例子出发,深入剖析 malloc/free 这两个最常见内存管理函数的实现机制,并总结如
2020-08-08
18 / 24