Command Line Resources

Command Line Article List (Under Construction)

awesome command line

The linux command line中文版书

The Unix Chainsaw - Gary Bernhardt

IBM - Introduction to text manipulation on UNIX-based systems


Unix text process


cat is short for concatenate.

Shell 脚本学习指南

; is to separate commands in the same line & run the first command in background. Continue following commands (don’t wait the completion) Options with no arguments can be combined -l -t abc.c => -lt abc.c Echo \f 清屏

Command < file ( < change stdin)

will create the file if not exist. If exist, will override

Pipe: faster x10 than temp file Use the command that would decrease the data first

不关心命令输出,只关心命令退出状态:> /dev/null

read password < /dev/tty 从终端读入密码 stty-echo / echo 关闭/打开 自动打印输入字符 PATH: 用:分开的一系列目录 用于查找命令 永久修改:加入bashrc PATH=$PATH:$HOME/bin

命令行参数 $1 ${10}

Who 显示所有用户

chapter2 Cc File.c | grep -v ^$ > file.c 删除空行并储存 -i 忽略大小写 -r 查找所有文件 -n 显示行数 -C5 显示上下文 5行


{n} {n,} {n,m} ^ 在方括号内表示取反

替换 sed



$ cd / # to the root $ cd ~ # to /User/davidfeng (home directory)


ls -R show all files in the subfolders. ls -lah [name of file] # see the permissions

whoami # show the current user

chmod +rw # change mode: add/subtract permissions $ chmod u+x # u is user (myself)

$ which grep # where the command grep is installed? $ history # shows history of commands

move to the front/end of a command: ctrl +a/e

A better Mac Terminal experience


=> Unix shell fundamentals 9h command line programs including ls vi grep etc.

Shell十三问 Linux C编程

learn enough command line Ten things I wish I knew about bash shellcheck safe way to do things in bash

bat is a better version of cat ack is a better version of grep

CLI improved 中文

Learn Enough command line $ echo 1 > afile create a file named “afile” with content 1. If afile already exist, it overrides the content. echo 2 >> afile (append 2)

find .git/objects # find subfolders find .git/objects -type f # only find files, exclude directories yes command: can take optional argument, output confirm messages until killed. man: manual space bar: turn to next page in a long doc. (man, cat, etc) q: quit ^: ctrl ^A: move to beginning of a line ^E: move to end of line ^U: clear the line from cursor to beginning option + left click: move the cursor move forward/backward by one word: mac terminal: option + left/right; iTerm2: esc + b/f

random source ~/.bashrc source can be replaced with a . => . ~/.bashrc

wc filename word count

kill a process kill -options id kill -15 12345 -15: gental kill. Give the process a chance to clean up temp files other options: 2, 1, 9

make a new bash command “ekill”: Listing 21: A custom escalating kill script. ~/bin/ekill 1 #!/bin/bash 2 3 # Kill a process as safely as possible. 4 # Tries to kill a process using a series of signals with escalating urgency. 5 # usage: ekill 6

If the number of argument is less than 1, exit with a usage statement.

if [[ $# -lt 1 ]]; then echo "usage: ekill " exit 1 fi 7 # Assign the process id to the first argument. 8 pid=$1 9 kill -15 $pid || kill -2 $pid || kill -1 $pid || kill -9 $pid

To make ekill work: ~/bin is on the system path. echo $PATH if /Users/davidfeng/bin is not listed, edit bashrc export PATH="~/bin:$PATH" # sometimes $HOME works instead of ~ make the script itself executable chmod +x ~/bin/ekill confirm: which ekill => gives the full path to the script

ps aux: show all processes tail: get a hanging process

curl -0L url/filename #download unzip

grep -n Waldo * #-n for line number use grep in vim: -n is added automatically. -i: ignore case.