包管理工具 Linux Ubuntu Debian APT
2017-12-25
搜索
apt search xxx
检索
apt list
apt list --installed
apt list --upgradable
升级
apt update
apt upgrade
apt-file
apt-file list youtube-dl
apt-file search bin/update-locale
其他
apt search
apt show
apt install
apt reinstall
apt remove
apt autoremove
apt full-upgrade
apt edit-sources
apt satisfy
apt-mark
apt-key
apt-config
apt-cache
apt-add-repository
Linux
2017-12-06
比较独特的命令 [
WebServer Apache Linux
2017-11-09
项目中有一个下载日志文件的功能,大致流程是 WEB 后端调用底层方法收集并压缩一些 .log 文件生成一个 zip 压缩包,放在 /tmp 目录下,前端访问指定路径下载。
之前系统环境用的 CentOS 6.5,现在升级到了 CentOS 7,结果测试时发现下载文件下载失败。
Linux awk LinuxTextProccessing
2017-10-15
awk 的文档写出来可能有一本很厚的书,里面甚至有一种内嵌的解释性编程语言在里面。但是我们普通人就把他当一个小工具,了解一下基础用法就好了,不用深入研究。它的基本功能是将字符串切割之后按照 $1 ... $n 来处理,$0 表示整个字符串(整行)。
Linux grep LinuxTextProccessing
2017-10-13
egrep = grep -E
fgrep = grep -F
# -G, --basic-regexp 基本正则, 默认
# -E, --extended-regexp 拓展正则
# -P, --perl-regexp Perl 正则
# -w 完全匹配字词
# -x 完全匹配整行
grep markjour /var/log/auth.log
grep -E markjour /var/log/auth.log
# -F, --fixed-strings
grep -F markjour /var/log/auth.log
tail -1000 /var/log/auth.log | grep -Ev 'gnome-keyring-daemon|CRON'
-r 目录
-R 目录,处理软链
-v 排除
-i 忽略大小写 (ignore-case)
-m 控制匹配次数
-a 包含二进制内容的文件当作纯文本处理
-
-I 包含二进制内容的文件跳过
-
-b 输出命中内容的偏移量
-n 输出行号
-o 仅输出匹配部分
-h 不输出文件名(匹配多个文件时默认输出文件名 -H)
-L, --files-without-match 仅输出没有匹配的文件名
-l, --files-with-matches 仅输出匹配文件名
-
-c, --count 仅输出文件名和匹配行数
-
--include=GLOB 只查找匹配 GLOB(文件模式)的文件
--exclude=GLOB 跳过匹配 GLOB 的文件
--exclude-from=FILE 跳过所有匹配给定文件内容中任意模式的文件
-
--exclude-dir=GLOB 跳过所有匹配 GLOB 的目录
-
-B, --before-context=NUM 打印文本及其前面NUM 行
-A, --after-context=NUM 打印文本及其后面NUM 行
-C, --context=NUM 打印NUM 行输出文本
-NUM 等同于 --context=NUM
Linux
2017-08-05
dd if=/dev/zero of=cdata.img bs=1G count=5
mkfs ext4 -F cdata.img
LANG=en fdisk -lu cdata.img
sudo mount -o loop cdata.img /mnt/iso
sudo umount /mnt/iso
Linux DNS dig
2017-06-02
dig(Domain Information Groper)是 DNS 查询与诊断工具,功能比 nslookup 更强大,是 Linux 运维、网络工程和 DNS 管理中最常用的调试工具。它能够查询各种 DNS 记录、追踪完整解析过程、指定 DNS 服务器、查看权威应答和调试 DNSSEC 信息,是分析域名解析问题的标准工具。
| 命令 |
作用 |
| dig qq.com |
查询域名 A 记录 |
| dig AAAA qq.com |
查询 IPv6 地址记录 |
| dig MX qq.com |
查询邮件服务器记录 |
| dig NS qq.com |
查询名称服务器记录 |
| dig TXT qq.com |
查询 TXT 记录(SPF、DKIM 等) |
| dig CNAME qq.com |
查询 CNAME 记录 |
| dig -x 8.8.8.8 |
IP 反向解析(PTR 查询) |
| dig qq.com @8.8.8.8 |
使用指定 DNS 服务器查询 |
| dig +short qq.com |
仅输出结果,便于脚本处理 |
| dig +trace qq.com |
从根服务器开始追踪完整解析链路 |
| dig ANY qq.com |
查询所有可返回的记录(很多 DNS 已限制) |
| dig +noall +answer qq.com |
仅显示 Answer 区域 |
| dig +dnssec qq.com |
查询 DNSSEC 相关信息 |
| dig SOA qq.com |
查询 SOA(区域授权)记录 |
dig -h 输出太多参数了,我就不贴出来了。
Linux
2017-05-11
命名空间是什么
对内核资源进行分区,为进程隔离提供支持。
命名空间类型
| Namespace |
CloneFlag |
Version |
Year |
| Mount (mnt) |
CLONE_NEWNS |
2.4.19 |
2002 |
| UTS |
CLONE_NEWUTS |
2.6.19 |
2006 |
| Inter-process Communication (ipc) |
CLONE_NEWIPC |
2.6.19 |
2006 |
| Process ID (pid) |
CLONE_NEWPID |
2.6.24 |
2008 |
| Network (net) |
CLONE_NEWNET |
2.6.29 |
2009 |
| User ID (user) |
CLONE_NEWUSER |
3.8 |
2013 |
| Control group (cgroup) |
CLONE_NEWCGROUP |
4.6 |
2016 |
| Time |
CLONE_NEWTIME |
5.6 |
2020 |
Mount
挂载点可以在不同命名空间之间共享。
UTS
UNIX Time-Sharing
不知道为什么叫这个名字。作用是隔离主机名和域名。
IPC
不同 IPC 命名空间的进程不能通过 shm 系列方法共享内存。
PID
Network
每个网络命名空间都有一组自己的网络资源,包括 IP 地址、路由表、套接字列表、连接跟踪表、防火墙等等。
User
主要作用是权限的隔离。
Cgroup
进程控制组。
Time
时间的隔离。
系统调用
参考资料与拓展阅读
Linux
2017-03-29
atime:access time,访问时间
mtime:change time,修改时间,内容修改
ctime:modify time,变更时间,内容修改,或者元数据修改
crtime:create time / birth time,创建时间,部分文件系统支持(Ext4,btrfs,xfs)
[root@localhost]# stat abc.txt
File: `abc.txt'
Size: 11214 Blocks: 24 IO Block: 4096 regular file
Device: fc10h/64528d Inode: 3153180 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-07-09 19:35:42.321279859 +0800
Modify: 2016-07-09 19:35:42.321279859 +0800
Change: 2016-07-09 19:35:42.321279859 +0800
[root@localhost]# cat abc.txt > /dev/null
[root@localhost]# stat abc.txt
File: `abc.txt'
Size: 11214 Blocks: 24 IO Block: 4096 regular file
Device: fc10h/64528d Inode: 3153180 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-07-09 19:35:42.321279859 +0800
Modify: 2016-07-09 19:35:42.321279859 +0800
Change: 2016-07-09 19:35:42.321279859 +0800
[root@localhost]# mount
/dev/vda1 on / type ext4 (rw,noatime,errors=remount-ro)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/vdb on /data type ext4 (rw,noatime)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
重点是 noatime 选项,表示文件系统忽略 atime 的变更,因为频繁的 atime 变更对性能有影响。
Linux 开发工具 压缩 CheatSheet
2017-03-22
rar
rar a xxx.rar files...
rar e xxx.rar ./
rar a -p123456 xxx.rar files...
rar e -p123456 xxx.rar ./
rar a -v20m xxx.rar files...
tar
常用的参数说明(grep "^ \-[a-zA-Z0-9]" <(tar --help) | sort):
vf 分别表示输出详细信息、指定压缩包名称
x 解压
c 压缩
t 列出压缩包里面的文件列表
- 压缩文件类型(Linux 下最常用的两种):
z:gz
j:bz2
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/
# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz
# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/
# To list the content of an .gz archive:
tar -ztvf /path/to/foo.tgz
# To extract a .bz2 archive:
tar -xjvf /path/to/foo.tgz
# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/
# To list the content of an .bz2 archive:
tar -jtvf /path/to/foo.tgz
# To create a .gz archive and exclude all jpg,gif,... from the tgz
tar czvf /path/to/foo.tgz --exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/
# To use parallel (multi-threaded) implementation of compression algorithms:
tar -z ... -> tar -Ipigz ...
tar -j ... -> tar -Ipbzip2 ...
tar -J ... -> tar -Ipixz ...
zip
# Create zip file
zip archive.zip file1 directory/
# To list, test and extract zip archives, see unzip
cheat unzip
# Extract archive
unzip archive.zip
# Windows 下创建的压缩包放到 Ubuntu 下解压可能会有编码问题
unzip archive.zip -O gbk
# Test integrity of archive
unzip -tq archive.zip
# List files and directories in a file
unzip -l archive.zip
7z
sudo apt install p7zip-full
dpkg -L p7zip-full p7zip | grep bin/
# /usr/bin/7z
# /usr/bin/7za
# /usr/bin/7zr
# /usr/bin/p7zip
文档中说是支持 7z,xz,tar,gz,zip,bz2,iso,rpm,deb 等等等等格式,不过没用过。
# 压缩
7z a xxxx.7z files...
# 解压
7z e xxxx.7z
# 查看文件列表
7z l xxxx.7z
参考
man
--help
cheat / tldr