Skip to content

Instantly share code, notes, and snippets.

View ibreathebsb's full-sized avatar

Isaac Young ibreathebsb

View GitHub Profile

alias

alias : 列出所有别名

isaac@hp:~/Notes/linux$ alias
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 egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

变量

  1. 变量命名时不能用=号两边不能有空格
  2. shell脚本中的的单引号和双引号作用不同,单引号会将特殊符号当作普通符号处理,而双引号会将变量替换为其真是内容:
isaac@hp:~/Playground$ echo "lang is $LANG"
lang is en_US.UTF-8
isaac@hp:~/Playground$ echo 'lang is $LANG'
lang is $LANG

vim

模式

  1. 常规模式
  2. 编辑模式
  3. 指令模式

三者的切换 编辑模式 <->常规模式<->指令模式

dump

文件和文件系统备份

dump -W 列出/etc/fstab中的文件系统备份情况

root@debian-gnu-linux-vm:/home/parallels/Playground# dump -W
Last dump(s) done (Dump '&gt;' file systems):

tar

将多个文件打包为一个文件

命令

tar -c -f archive.tar files/directories 将文件或目录打包为一个文件

tar -[r|u] -f archive.tar newfiles/newdirectoreis 将新的文件添加到当前包中,只对非压缩的archive有效, u与r的不同之处在于,u=update只有目标文件比archive中对应的文件新时才会更新

gzip

gzip 用于压缩解压查看文件

用法: gzip [opitions] file

-v: 显示压缩和解压缩信息

-k: 压缩和解压时保留原来的文件

配置文件

cat /etc/fstab

# filesystem | mount point | type | mount option | dump | fsck
/dev/loop15 /snap/gnome-logs/37 squashfs ro,nodev,relatime 0 0
/dev/nvme0n1p1 /boot/efi vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
/dev/nvme0n1p2 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0

df

df 列出文件系统的使用情况 df /somepath 会自动匹配该目录对应的文件系统并列出该文件系统的使用情况

du

du 列出文件大小

组成

  1. inode 用于记录文件的权限信息,以及对应的data block编号,每个文件占用一个inode
  2. data block 用于存放文件的内容,每个文件至少占用一个
  3. superblock 用于记录整个文件系统的inode block用量以及文件系统相关信息

索引式文件系统,inode和block都有自己的编号,可以根据inode直接获取所有data block 的编号并直接访问,访问效率高

filesystem = boot sector + block group * n

which

在用户的目录($PATH)下查找指定的可执行文件

~ which ifconfig
/sbin/ifconfig