#69 Ubuntu 快捷键

2020-03-31

全局

Win / Win + S 窗口概览
Win + A 程序搜索,或者 Win 双击
Win + D 显示桌面
Win + L 锁定窗口
Win + V / Win + M 打开日历和事件
Win + 数字 打开左侧菜单上的程序
Win + Left 将窗口移动到左侧
Win + Right 将窗口移动到右侧
Win + Up 最大化
Win + Down 还原
Win + Home 切换到第一个 Workspace
Win + PageUp 切换到上一个 Workspace
Win + PageDown 切换到上一个 Workspace
Alt + F2 运行一个命令
Alt + F4 关闭当前窗口
Alt + F6
Alt + F10 窗口最大化 / 还原
Ctrl + Alt + T 打开终端

Win + Space 切换输入法
Alt + Space 窗口菜单
Win + C 计算器 自定义
Win + F 文件浏览器 自定义

切换

Alt + Tab 切换窗口
Win + Tab 切换程序
Alt + ~ / Win + ~ 同一个程序的不通窗口切换

截图

屏幕截图并保存:PrntScr
Shift 选区截屏,加 Alt 窗口截屏,加 Ctrl 截屏到剪切板

PS:Ubuntu 22.04 之后,截图的逻辑调整了。
交互式截屏:PrntScr
Shift 屏幕截图并保存,同时复制到剪切板
Alt 窗口截屏并保存,同时复制到剪切板
Ctrl 没有任何效果

终端

Ctrl + Shift + N new window
Ctrl + Shift + Q quit window

Ctrl + Shift + T 打开新标签
Ctrl + Shift + W close tab

Ctrl + Shift + PageUp Tab 左移
Ctrl + Shift + PageDown Tab 右移

Ctrl + Shift + C 复制
Ctrl + Shift + V 粘贴

Ctrl + / 清空

其他

F9 打开 CopyQ 自定义

#68 Linux 磁盘使用情况检查

2020-03-14

我们一般使用 du 命令,不正是做这个用的么(Disk Usage)?

du -hsc          # 当前目录占用空间大小
du -hsc *.log*   # 查看文件大小
du -hsc a b c d  # 查看指定几个目录的大小

#67 Linux 相关标准

2020-03-09
  • Linux Standard Base (LSB)
  • Filesystem Hierarchy Standard (FHS)
  • Application Programming Interface (API) Standards
  • Single UNIX Specification version 4, The Open Group
  • Single UNIX Specification version 3, The Open Group
  • Single UNIX Specification version 2, The Open Group
  • DWARF Standards
  • DWARF Version 4
  • DWARF Version 3
  • DWARF Version 2.0
  • ELF and ABI Standards
  • Tool Interface Standard (TIS) Portable Formats Specification, version 1.1
  • Tool Interface Standard (TIS) Portable Formats Specification, version 1.2
  • System V ABI Edition 4.1
  • System V ABI - DRAFT 24 April 2001
  • Processor Specific ELF documents
  • System V Application Binary Interface Intel386 Architecture Processor Supplment, Fourth Edition
  • Intel Itanium Processor specific ABI
  • System V Application Binary Interface x86-64 Architecture Processor Supplement Draft Version 0.95 | v0.98 | v0.99
  • System V Application Binary Interface MIPS RISC Processor Supplment, 3rd Edition
  • System V Application Binary Interface PowerPC Processor Supplment. This is one of two known PPC ELF standards. This one was developed by SunSoft. The two versions are not identical, and applications can only conform to one or the other, while it seems possible for an implementation to support both simulaneously.
  • ARM Processor Supplment
  • Processor-Specific ELF Supplement for PA-RISC
  • Motorola 8 and 16 bit Embedded ABI
  • Application Binary Interface (ABI) Specifications/Standards
  • gLSB v1.2, Linux Standard Base
  • archLSB-IA32 v1.2, Linux Standard Base
  • archLSB-PPC32 v1.2, Linux Standard Base
  • 3DNow! (AMD K6 & Athlon), AMD
  • AMD Extensions to the 3DNow1 and MMX Instruction Set, AMD
  • Linux for S/390 (32bit) ELF ABI Supplement, IBM
  • Linux for zSeries (64bit) ELF ABI Supplement, IBM
  • C++ ABI for Itanium, v1.86
  • C++ ABI for Itanium, v1.83
  • C++ ABI for Itanium, v1.75
  • Intel Itanium Processor-Specific ABI
  • Related ABI Projects
  • Moblin 1.9.0 spec
  • Moblin 1.9.1 spec

参考资料与拓展阅读

#66 Shell 历史

2020-01-07

参考: https://en.wikipedia.org/wiki/Comparison_of_command_shells

Linux Shell

  • Thompson shell (sh), 1971, Unix v1 - v6
    只存在历史中
    在 Bourne shell 之前,贝尔实验室还出了一个 Mashey shell,只出现在 1976 年的 PWB UNIX 中(所以又叫 PWB shell),没有大范围使用
  • Bourne shell (sh), 1977, Unix v7
  • C shell (csh), 1978 img
  • TENEX C shell (tcsh), 1983 img
    是 TENEX 系统开发的 csh 兼容 Shell
  • Korn shell (ksh), 1983 img
  • Bash, 1989 img
  • Almquist shell (ash), 1989 img
  • zsh, 1990 img
  • Debian Almquist shell (dash), an ash fork, 1997
    主体随 ash 是 BSD 协议,不过,可能是为了保持对 bash 的兼容,采用了 bash 项目的一个文件
  • fish, 2005 img

分类

  • ksh, bash, zsh, ash, dash 都是 Bourne shell 兼容。
  • csh, tcsh 就是 csh 兼容。
  • fish

说明

  1. Unix 上的 sh 有版权问题, 所以 BSD 和 Linux 上的 /bin/sh 都指向某一种兼容 Shell (一般是默认 Shell)
  2. RHEL/CentOS 上,默认 Shell 是 Bash
  3. Debian/Ubuntu 上,默认 Shell 是 Dash
  4. FreeBSD 上默认采用 tcsh, 基于 FreeBSD 的 GhostBSD 采用 fish
  5. OpenBSD 上默认采用 pdksh (pd: Public Domain), 不知道和 tsh 什么关系。可能是 OpenBSD 维护的 tsh 兼容 Shell。
  6. NetBSD 上默认采用 ash
  7. 由于 ash 非常轻量级,BusyBox 采用了 dash fork
    然后 BusyBox 被 Alpine Linux, Tiny Core Linux 或者其他嵌入式 Linux (比如 OpenWrt) 采用,所以这些系统的默认 Shell 应该就是 ash

所以可能使用最广泛的 Shell 是 ash 和 bash。

其他:MacOS 上曾经默认采用 bash, 后来专向了 zsh

Windows 平台

  • command.com, 1980
  • cmd.exe, 1993
  • PowerShell, 2006

#64 GNU/Linux 上如何快速创建一个大文件?「from StackOverflow」

2019-12-25

StackOverflow 上看到好些种快速创建文件的命令,逐个测试,在 Ubuntu 下可用的方法有以下几种:

time dd if=/dev/zero of=test.img bs=10M iflag=fullblock,count_bytes count=10G
# 0.00s user 0.45s system 1% cpu 39.144 total

# 在 xfsprogs 包中:
# -n 表示不写入数据
time xfs_mkfile -n 10g test.img
# 0.01s user 0.01s system 2% cpu 0.669 total

# 在 VBox 挂载的虚拟磁盘上执行时遇到 “不支持的操作” 错误
# 在 EXT4 磁盘上没有遇到问题,速度很快
time fallocate -l 10G test.img

time truncate -s 10G test.img
# 0.00s user 0.00s system 46% cpu 0.005 total

time dd if=/dev/zero of=test.img bs=1 count=0 seek=10G
# 0.00s user 0.00s system 77% cpu 0.002 total

最后看到的 dd seek 方案深得征信深得朕心。

根据这个思路,Python 创建 10G 的文件应该这么写(也是我一直以来的写法):

GB = 1 << 30
with open('test.img', 'w') as _file:
    _file.seek(10 * GB - 1)
    _file.write(chr(0))

#63 Systemd 相关命令

2019-12-21
apt-file list systemd | grep bin/
systemd: /bin/journalctl
systemd: /bin/loginctl
systemd: /bin/networkctl
systemd: /bin/systemctl
systemd: /bin/systemd
systemd: /bin/systemd-ask-password
systemd: /bin/systemd-escape
systemd: /bin/systemd-inhibit
systemd: /bin/systemd-machine-id-setup
systemd: /bin/systemd-notify
systemd: /bin/systemd-sysext
systemd: /bin/systemd-sysusers
systemd: /bin/systemd-tmpfiles
systemd: /bin/systemd-tty-ask-password-agent
systemd: /usr/bin/bootctl
systemd: /usr/bin/busctl
systemd: /usr/bin/hostnamectl
systemd: /usr/bin/kernel-install
systemd: /usr/bin/localectl
systemd: /usr/bin/resolvectl
systemd: /usr/bin/systemd-analyze
systemd: /usr/bin/systemd-cat
systemd: /usr/bin/systemd-cgls
systemd: /usr/bin/systemd-cgtop
systemd: /usr/bin/systemd-cryptenroll
systemd: /usr/bin/systemd-delta
systemd: /usr/bin/systemd-detect-virt
systemd: /usr/bin/systemd-id128
systemd: /usr/bin/systemd-mount
systemd: /usr/bin/systemd-path
systemd: /usr/bin/systemd-resolve
systemd: /usr/bin/systemd-run
systemd: /usr/bin/systemd-socket-activate
systemd: /usr/bin/systemd-stdio-bridge
systemd: /usr/bin/systemd-umount
systemd: /usr/bin/timedatectl
  • journalctl
  • loginctl
  • networkctl
  • systemctl
  • systemd
  • systemd-ask-password
  • systemd-escape
  • systemd-inhibit
  • systemd-machine-id-setup
  • systemd-notify
  • systemd-sysext
  • systemd-sysusers
  • systemd-tmpfiles
  • systemd-tty-ask-password-agent
  • bootctl
  • busctl
  • hostnamectl
  • kernel-install
  • localectl
  • resolvectl
  • systemd-analyze
  • systemd-cat
  • systemd-cgls
  • systemd-cgtop
  • systemd-cryptenroll
  • systemd-delta
  • systemd-detect-virt
  • systemd-id128
  • systemd-mount
  • systemd-path
  • systemd-resolve
  • systemd-run
  • systemd-socket-activate
  • systemd-stdio-bridge
  • systemd-umount
  • timedatectl
ps -ef | grep -E "systemd|systemd|dns|dhcp|udevd" | grep -Fv grep
root         333       1  0 10:00 ?        00:00:05 /lib/systemd/systemd-journald
root         419       1  0 10:00 ?        00:00:01 /lib/systemd/systemd-udevd
systemd+     546       1  0 10:00 ?        00:00:07 /lib/systemd/systemd-oomd
systemd+     547       1  0 10:00 ?        00:00:00 /lib/systemd/systemd-resolved
systemd+     548       1  0 10:00 ?        00:00:00 /lib/systemd/systemd-timesyncd
message+     573       1  0 10:00 ?        00:00:04 @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root         680       1  0 10:00 ?        00:00:00 /lib/systemd/systemd-logind
root         682       1  0 10:00 ?        00:00:00 /usr/sbin/thermald --systemd --dbus-enable --adaptive
markjour     2508       1  0 10:05 ?        00:00:01 /lib/systemd/systemd --user
markjour     2523    2508  0 10:05 ?        00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
markjour     5461    2508  0 10:11 ?        00:00:00 /usr/libexec/gnome-session-binary --systemd-service --session=ubuntu
root        6630       1  0 10:15 ?        00:00:00 systemd-tty-ask-password-agent --wall

#62 Systemd 子命令

2019-12-21
Unit Commands:
  list-units [PATTERN...]             List units currently in memory
  list-sockets [PATTERN...]           List socket units currently in memory,
                                      ordered by address
  list-timers [PATTERN...]            List timer units currently in memory,
                                      ordered by next elapse
  is-active PATTERN...                Check whether units are active
  is-failed PATTERN...                Check whether units are failed
  status [PATTERN...|PID...]          Show runtime status of one or more units
  show [PATTERN...|JOB...]            Show properties of one or more
                                      units/jobs or the manager
  cat PATTERN...                      Show files and drop-ins of specified units
  help PATTERN...|PID...              Show manual for one or more units
  list-dependencies [UNIT...]         Recursively show units which are required
                                      or wanted by the units or by which those
                                      units are required or wanted
  start UNIT...                       Start (activate) one or more units
  stop UNIT...                        Stop (deactivate) one or more units
  reload UNIT...                      Reload one or more units
  restart UNIT...                     Start or restart one or more units
  try-restart UNIT...                 Restart one or more units if active
  reload-or-restart UNIT...           Reload one or more units if possible,
                                      otherwise start or restart
  try-reload-or-restart UNIT...       If active, reload one or more units,
                                      if supported, otherwise restart
  isolate UNIT                        Start one unit and stop all others
  kill UNIT...                        Send signal to processes of a unit
  clean UNIT...                       Clean runtime, cache, state, logs or
                                      configuration of unit
  freeze PATTERN...                   Freeze execution of unit processes
  thaw PATTERN...                     Resume execution of a frozen unit
  set-property UNIT PROPERTY=VALUE... Sets one or more properties of a unit
  bind UNIT PATH [PATH]               Bind-mount a path from the host into a
                                      unit's namespace
  mount-image UNIT PATH [PATH [OPTS]] Mount an image from the host into a
                                      unit's namespace
  service-log-level SERVICE [LEVEL]   Get/set logging threshold for service
  service-log-target SERVICE [TARGET] Get/set logging target for service
  reset-failed [PATTERN...]           Reset failed state for all, one, or more
                                      units
Unit File Commands:
  list-unit-files [PATTERN...]        List installed unit files
  enable [UNIT...|PATH...]            Enable one or more unit files
  disable UNIT...                     Disable one or more unit files
  reenable UNIT...                    Reenable one or more unit files
  preset UNIT...                      Enable/disable one or more unit files
                                      based on preset configuration
  preset-all                          Enable/disable all unit files based on
                                      preset configuration
  is-enabled UNIT...                  Check whether unit files are enabled
  mask UNIT...                        Mask one or more units
  unmask UNIT...                      Unmask one or more units
  link PATH...                        Link one or more units files into
                                      the search path
  revert UNIT...                      Revert one or more unit files to vendor
                                      version
  add-wants TARGET UNIT...            Add 'Wants' dependency for the target
                                      on specified one or more units
  add-requires TARGET UNIT...         Add 'Requires' dependency for the target
                                      on specified one or more units
  edit UNIT...                        Edit one or more unit files
  get-default                         Get the name of the default target
  set-default TARGET                  Set the default target

Machine Commands:
  list-machines [PATTERN...]          List local containers and host

Job Commands:
  list-jobs [PATTERN...]              List jobs
  cancel [JOB...]                     Cancel all, one, or more jobs

Environment Commands:
  show-environment                    Dump environment
  set-environment VARIABLE=VALUE...   Set one or more environment variables
  unset-environment VARIABLE...       Unset one or more environment variables
  import-environment VARIABLE...      Import all or some environment variables

Manager State Commands:
  daemon-reload                       Reload systemd manager configuration
  daemon-reexec                       Reexecute systemd manager
  log-level [LEVEL]                   Get/set logging threshold for manager
  log-target [TARGET]                 Get/set logging target for manager
  service-watchdogs [BOOL]            Get/set service watchdog state

System Commands:
  is-system-running                   Check whether system is fully running
  default                             Enter system default mode
  rescue                              Enter system rescue mode
  emergency                           Enter system emergency mode
  halt                                Shut down and halt the system
  poweroff                            Shut down and power-off the system
  reboot                              Shut down and reboot the system
  kexec                               Shut down and reboot the system with kexec
  exit [EXIT_CODE]                    Request user instance or container exit
  switch-root ROOT [INIT]             Change to a different root file system
  suspend                             Suspend the system
  hibernate                           Hibernate the system
  hybrid-sleep                        Hibernate and suspend the system
  suspend-then-hibernate              Suspend the system, wake after a period of
                                      time, and hibernate

#61 Systemd 的问题

2019-12-20

开源中国上看到 Debian 正在投票是否支持非 systemd 初始化系统

  1. 2014 年素来混乱的 Debian 社区,经过了一番激烈争论之后(甚至是生命安全威胁),终于决定支持 systemd。
    PS: 这场争议导致部分核心人员离开,主要是对 Debian 社区的管理机制(混乱 “民主”)产生质疑。
  2. 2015 年 5 月发布的 Debian 8.0 (Jessie) 开始使用 Systemd 当默认的初始化系统。
    但是关于 Systemd 的争论从未停止,甚至有部分开发者独自维护了一个拒绝 Systemd 的分叉:Devuan

Systemd 真是闹出好大争议,和 GNOME3 一样。也正是有 GNOME3 的例子(社区总体来说,或者说大多数人,最后还是拥抱了变化,接纳 GNOME3),而且我只是一个实用主义的使用者,我觉得 Systemd 挺好的,能提升性能、使用又方便,为什么不呢。

#60 PowerShell 在 Ubuntu 下的安装和试用

2019-08-22

PowerShell 的最近的一次更新修复了其作为 SSH 的登录 Shell 的一些问题。
Win 10 对 NFS,SSH 的支持推进也是有目共睹。
随着 MS 对 Windows 的策略调整,估计以后 Windows 服务器也会变多。

# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Enable the "universe" repositories
sudo add-apt-repository universe

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

PS 常用命令

# 获取本地 IP
(invoke-webrequest -uri "http://ifconfig.me/ip").content

get-nettcpconnection | where-object {$_.State -eq "Listen"}
get-nettcpconnection -localport 49667
get-process -id (get-nettcpconnection -localport 49667).owningprocess
stop-process -id (get-nettcpconnection -localport 11).owningprocess

"# README" | out-file README.md
type README.md