读书笔记_鸟哥的Linux私房菜_基础学习篇_第4版_第4章

命令行模式下的命令执行

命令格式

command [-options] parameter1 parameter2 ...
命令格式元素 描述
command 命令或可执行文件
options 命令可选设置,前面可以是-, --, 或+符号
parameter 命令或可执行文件的参数

示例

[root@VM-8-3-centos ~]# ls -al ~ # 查询`~`目录下的所有文件和相关的文件属性
total 60
dr-xr-x---. 7 root root 4096 Jan 4 23:26 .
dr-xr-xr-x. 20 root root 4096 Jan 8 02:06 ..
-rw------- 1 root root 7738 Jan 8 00:51 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r-- 1 root root 125 Jan 1 10:38 .bashrc
drwxr-xr-x 4 root root 4096 Jan 1 10:23 .cache
drwxr-xr-x 3 root root 4096 Jan 4 23:26 code
drwxr-xr-x 3 root root 4096 Jan 1 10:23 .config
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwxr-xr-x 2 root root 4096 Jul 25 17:53 .pip
-rw-r--r-- 1 root root 73 Jan 1 10:00 .pydistutils.cfg
drwx------ 2 root root 4096 Jan 1 09:59 .ssh
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
[root@VM-8-3-centos ~]#

基础命令

命令 描述 示例
date 显示当前日期与时间 查看示例
cal 显示日历 查看示例
bc 计算器 查看示例

date示例

# 显示当前日期和时间
[root@VM-8-3-centos ~]# date
Sun Jan 8 09:56:46 CST 2023
[root@VM-8-3-centos ~]#
# `+%Y/%m/%d`为`date`命令的参数功能,用来格式化日期时间输出,一些参数前可加`+`,也可以是`-`
[root@VM-8-3-centos ~]# date +%Y/%m/%d
2023/01/08
[root@VM-8-3-centos ~]#

cal示例

# 显示这个月份的日历
[root@VM-8-3-centos ~]# cal
January 2023
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
[root@VM-8-3-centos ~]#
# cal 的用法
# 显示某年某月的日历
cal [month] [year]

bc示例

# 进入bc(计算器)这个程序,可进行基本的运算操作
[root@VM-8-3-centos ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
# 输入`1 + 2`再按回车,得出结果,其余运算操作类似
1 + 2
3

热键

热键 描述 示例
[TAB] 命令补全或文件补齐 查看示例
[Ctrl]-c 中断当前程序 查看示例
[Ctrl]-d 键盘输入结束(EOF)或直接离开命令行(相当于exit) 查看示例

[TAB]示例

# 命令补全
# 输入`ca`后按下2次TAB键会呈现所有以`ca`为前缀的命令
[root@VM-8-3-centos ~]# ca[TAB][TAB]
cacertdir_rehash cache_metadata_size cache_writeback cal callgrind_annotate captoinfo catchsegv
cache_check cache_repair cagent_tools ca-legacy callgrind_control case catman
cache_dump cache_restore cairo-sphinx caller capsh cat
[root@VM-8-3-centos ~]# ca
# 文件名补齐
# 在命令后一个字段里按下两次TAB键会将所有以`li`为开头的文件名列出来
[root@VM-8-3-centos code]# ls li[TAB][TAB]
li_learning/ linux_learning/
[root@VM-8-3-centos code]# ls li

[Ctrl]-c示例

[root@VM-8-3-centos ~]# find /
... # 很多行,而且命令没有很快结束,按下[Ctrl]-c结束当前命令
[Ctrl]-c
[root@VM-8-3-centos ~]#

[Ctrl]-d示例

有一份C代码,里面有while语句判断输入是否EOF, 这个就是在这个代码编译出来运行时,我们从命令行中输入数据时是否输入了[Ctrl]-d的一个判断语句, 输入之后就会跳出循环,执行后续程序

命令求助

方法 描述 示例
--help options中的一种, 命令的可选设置, 用来查看命令的大致用法 查看示例
man manual的简写,即操作说明手册 查看示例

--help示例

# linux `find` 命令的用法
[root@VM-8-3-centos ~]# find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:
operators (decreasing precedence; -and is implicit where no others are given):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2
positional options (always true): -daystart -follow -regextype
normal options (always true, specified before other expressions):
-depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
--version -xautofs -xdev -ignore_readdir_race -noignore_readdir_race
tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
-readable -writable -executable
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls]
-context CONTEXT
actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
-fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
-exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
-execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;
Report (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to <bug-findutils@gnu.org>.
[root@VM-8-3-centos ~]#

man示例

# man是manual(操作说明)的缩写
# -f 是man的可选设置
[root@VM-8-3-centos ~]# man -f ls # 将所有操作说明中有关`ls`的page列出来(1-9,共9个page)
ls (1) - list directory contents
[root@VM-8-3-centos ~]#
page 内容
1 用户在shell中可以操作的命令或执行文件
2 系统内核可调用的函数与工具
3 一些常用的函数或函数库,大部分为C的函数库(libc)
4 设备文件说明,通常在/dev目录下的文件
5 配置文件或是某些文件的格式
6 游戏(games)
7 惯例与协议等,例如Linux文件系统、网络协议、ASCII代码等的说明
8 系统管理员可用的管理命令
9 跟内核有关的文件
[root@VM-8-3-centos ~]# man 1 ls
# 执行 man 1 ls后跳转到的man page,提供了ls命令的说明和用法
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below
-B, --ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest
first
-C list entries by columns
--color[=WHEN]
colorize the output; WHEN can be 'never', 'auto', or 'always' (the default); more info below
-d, --directory
list directories themselves, not their contents
-D, --dired
generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify
append indicator (one of */=>@|) to entries
--file-type
likewise, except do not append '*'
Manual page ls(1) line1 (press h for help or q to quit) # 按h帮助,按q退出man page返回命令行
posted @   只会走路的兔子  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示