#17 Linux 输出样式
Linux 命令行 终端 2016-05-13在命令行中输出颜色文字。
coding in a complicated world
在命令行中输出颜色文字。
关于 DNF 的更多信息,参考:2016/05/03 CentOS DNF
.rpm 包,和 .deb 包是 Linux 生态中两种最主要的包格式。bash-4.2.46-35.el7_9.x86_64.rpm
其中:
名称 :bash
架构 :x86_64
版本 :4.2.46
发布 :31.el7
大小 :3.5 M
源 :installed
来自源:anaconda
简介 : The GNU Bourne Again shell
网址 :http://www.gnu.org/software/bash
协议 : GPLv3+
描述 : The GNU Bourne Again shell (Bash) is a shell or command language
: interpreter that is compatible with the Bourne shell (sh). Bash
: incorporates useful features from the Korn shell (ksh) and the C shell
: (csh). Most sh scripts can be run by bash without modification.
yum help list # 查看帮助
yum search <package> # 搜索包
yum list
yum list installed
rpm -qa
yum list --upgradable
yum info <package>
rpm -qi <package>
rpm -ql <package> # 已安装包的文件列表
rpm -qd <package> # 已安装包的文件列表中的文档部分
rpm -qc <package> # 已安装包的文件列表中的配置部分
yum repolist
# repoquery 是 yum-utils 包提供的命令
repoquery -l <package> # 文件列表
repoquery -f <filepath> # 查看文件属于哪个包, 比如: `repoquery -f "*/repoquery"`
repoquery --location <package> # 查看包的下载地址
yum deplist <package> # 依赖
rpm -qR <package> # 已安装包的依赖
rpm -q --whatrequires <package> # 反向依赖
rpm -q --whatprovides <filepath>
rpm -qf <filepath>
yum provides <pattern>
yum whatprovides <patter>
yum check-update
yum updateinfo
yum update [package]
yum upgrade [package]
yum update-minimal
yum upgrade-minimal # 和 yum update-minimal 相同
yum downgrade <package>
yum install <package>
yum install <package-rpm-filepath>
yum reinstall
yum makecache
yum clean
yum erase
yum remove
yum autoremove
# list, info, summary, repeat, redo, undo, new, rollback, addon, addon-info, stats, statistics, sync, synchronizepkg, pkgs, pkg-list, pkgs-list, package, package-list, packages, packages-list, pkg-info, pkgs-info, package-info, packages-info
yum history
yum history list
yum history list all
yum versionlock <package>
RedHat 系列提供的,安装组(Group)的概念非常好。
安装组就是为了某一个目的需要的一组包,比如 gnome-desktop 组是安装一个完整的 gnome 桌面环境,web-server 组是安装 apache 和相关的几个包。
$ yum help groups
groups [list|info|summary|install|upgrade|remove|mark] [GROUP]
显示或使用、组信息
别名:group, grouplist, groupinfo, groupinstall, groupupdate, groupremove, grouperase
yum grouplistyum group list ids 附带组 IDyum group list hidden 列出所有组yum groupinfoyum groupinstall <group>yum install @<group>yum install @^<environment-group>yum --setopt=group_package_types=mandatory,default,optional groupinstall "Web Server"yum groupupdateyum groupremoveyum grouperase/etc/yum.conf/etc/yum.repos.d//etc/yum//etc/rpm 目录不知道是干什么的。
比如最常见的 fastestmirror,用于自动选择最快的镜像源。所以我们使用 CentOS 时,一般不需要去配置镜像源。
复制指定 URL 路径下的所有文件到本地目录 HTML 下:
wget -m -p -k -np -P <HTML> <URL>
# 时间清零
touch -amt 197001010000.00 <file>
sudo apt install -y xattr
xattr -l <file>
# 删除所有附加属性
xattr -c <file>
File Descriptor
“一切皆文件” 设计思想来自早期 Unix,这是现在 Unix/Linux 界的一个非常重要的概念(根据 Plan9 操作系统的相关资料,这一条没有得到彻底的贯彻)。
cat /proc/sys/fs/file-nr
# 17781 0 9223372036854775807
# 已分配, 已使用, 最大值
cat /proc/sys/fs/file-max
# 9223372036854775807
sudo sysctl -a | grep file
# fs.file-max = 9223372036854775807
# fs.file-nr = 17813 0 9223372036854775807
修改:
echo 100000000 > /proc/sys/fs/file-max
sysctl fs.file-max 100000000
# ulimit 是一个 Shell 内建命令
ulimit -a # 输出所有的相关限制
ulimit -n # 当前进程的最大打开文件数
ulimit -n 10240 # 修改当前进程的最大打开文件数
ps -ef | grep sshd | grep -Fv 'grep '
root 1080 1 0 10月16 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
sudo ls -l /proc/`pgrep sshd`/fd
总用量 0
lr-x------ 1 root root 64 10月 17 12:04 0 -> /dev/null
lrwx------ 1 root root 64 10月 17 12:04 1 -> 'socket:[25487]'
lrwx------ 1 root root 64 10月 17 12:04 2 -> 'socket:[25487]'
lrwx------ 1 root root 64 10月 17 12:04 3 -> 'socket:[28674]'
lrwx------ 1 root root 64 10月 17 12:04 4 -> 'socket:[28676]'
echo "* soft nofile 65535" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65535" | sudo tee -a /etc/security/limits.conf
系统会根据 /etc/pam.d/login 中的 PAM 配置来为登录用户设置,
如果配置了 session required /lib/security/pam_limits.so, 就会加载 /etc/security/limits.conf 设置用户的各种限制值。
<domain> <type> <item> <value>
@group syntax*, for default entry%, can be also used with %group syntax, for maxlogin limitcore - limits the core file size (KB)data - max data size (KB)fsize - maximum filesize (KB)memlock - max locked-in-memory address space (KB)nofile - max number of open file descriptorsrss - max resident set size (KB)stack - max stack size (KB)cpu - max CPU time (MIN)nproc - max number of processesas - address space limit (KB)maxlogins - max number of logins for this usermaxsyslogins - max number of logins on the systempriority - the priority to run user process withlocks - max number of file locks the user can holdsigpending - max number of pending signalsmsgqueue - max memory used by POSIX message queues (bytes)nice - max nice priority allowed to raise to values: [-20, 19]rtprio - max realtime prioritychroot - change root to directory (Debian-specific)先说明一下 Linux 的运行级别,然后使用 runlevel、init、chkconfig 等几个命令实现开机启动任务的管理。
可能这是 Linux 命令行使用频率最高的一个计算器工具了。
其语法可以说比较复杂,可以定义变量,有各种逻辑控制语句,甚至可以定义函数,简直可以拿来做程序设计了。但是我们一般可能用不了这么多功能,就用来做一些简单计算就行。
PS:奇怪的是,有这么多复杂的功能,竟然没有包含位运算。
bc <<< "1 + 3 + 5 + 7 + 9"
26
bc <<< "scale=3; 1 / 3"
.333
bc <<< "obase=2; 14"
1110
bc <<< "ibase=16;obase=2; FF - 1A"
11100101
long_string="line 1
line 2
line 3"
# bash ========
# readarray -t lines <<< "$long_string"
# IFS=$'\n' lines=($long_string)
# zsh =========
# lines=("${(@f)long_string}")
setopt sh_word_split
for line in "${lines[@]}"
do
echo "$line =="
done
cat /proc/versionuname -a,-r 参数可以只查看内核版本号lsb_release -acat /etc/redhat-release(CentOS)rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -ivh https://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-lt -y # long-term 长期支持版本
# yum --enablerepo=elrepo-kernel install kernel-ml -y # mainline 主线版本
col 命令删除退格符
如果通过定向符号输出 man 文档到文件,然后通过 vi 打开会看到很多蓝色的 ^H 符号。
如果是用 cat 或 less、more 等命令查看(输出到屏幕)就不会看到。