Linux命令
定义:
- 在 Linux 操作系统中,凡是在字符操作界面中输入能够完成特定操作和任务的字符串都
可以称为命令。 - 严格来说,命令通常只代表实现某一类功能的程序的名称。
格式:
命令字+空格+[选项]+空格+[参数]
- 命令字
是整条命令中最关键的一部分
唯一确定 - 选项
短格式选项:使用“-”符号引导 通常 一个字母
长格式选项:使用“--”符号引导 通常完整的单词 - 参数
命令字的处理对象
可以是文件名、目录(路径)名或用户名等内容
个数可以是零到多个
;可以隔开命令,执行多个命令
编辑Linux命令行的辅助操作(扩展)
快捷键 | 功能 |
---|---|
Tab 键 | 自动补齐(两次可以显示所有选项) |
反斜杠“\” | 强制换行或转义 |
Ctrl+e 或 end 键 | 光标移到最后 |
Ctrl+U | 清空至行首不包括当前光标处的 字符 |
Ctrl+K | 清空至行尾包括当前光标处的字符 |
Ctrl+a | 光标移到最前 |
Ctrl+w | 从当前光标删除到开头 |
ALT+d | 从当前光标删除末尾 |
Ctrl+l | 清屏 |
Ctrl+c | 取消本次命令编辑 |
Ctrl+s/Ctrl+q | 锁屏/解锁 |
向上下箭头 | 回看执行过的命令 |
格式说明(扩展)
- []表示可选项
- CAPS或<>表示可变化的数据
- ...表示一个列表可加多个一个或多个
- x|y|z 表示或的意思
- -abc 是-a -b -c (有些命令选项有先后顺序) 多个 -abc 一般而言是没有顺序先后 (绝大多数是没有的,只有少数分先后)
帮助命令
help
help用于内部命令
[root@localhost ~]# help cd
cd: cd [-L|[-P [-e]]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.
Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
links
-e if the -P option is supplied, and the current working directory
cannot be determined successfully, exit with a non-zero status
The default is to follow symbolic links, as if `-L' were specified.
Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
--help用于外部命令
ls --help
用法:ls [选项]... [文件]...
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 不隐藏任何以. 开始的项目
-A, --almost-all 列出除. 及.. 以外的任何项目
--author 与-l 同时使用时列出每个文件的作者
-b, --escape 以八进制溢出序列表示不可打印的字符
--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 '*'
--format=WORD across -x, commas -m, horizontal -x, long -l,
single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g 类似-l,但不列出所有者
--group-directories-first
group directories before files;
can be augmented with a --sort option, but any
use of --sort=none (-U) disables grouping
-G, --no-group 以一个长列表的形式,不输出组名
-h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小
(例如 1K 234M 2G)
--si 同上面类似,但是使用1000 为基底而非1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN
(overridden by -a or -A)
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k, --kibibytes default to 1024-byte blocks for disk usage
-l 使用较长格式列出信息
-L, --dereference 当显示符号链接的文件信息时,显示符号链接所指示
的对象而并非符号链接本身的信息
-m 所有项目以逗号分隔,并填满整行行宽
-n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号
-N, --literal 输出未经处理的项目名称 (如不特别处理控制字符)
-o 类似 -l,但不列出有关组的信息
-p, --indicator-style=slash 对目录加上表示符号"/"
-q, --hide-control-chars print ? instead of nongraphic characters
--show-control-chars show nongraphic characters as-is (the default,
unless program is 'ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always, c, escape
-r, --reverse 逆序排列
-R, --recursive 递归显示子目录
-s, --size 以块数形式显示每个文件分配的尺寸
-S sort by file size
--sort=WORD sort by WORD instead of name: none (-U), size (-S),
time (-t), version (-v), extension (-X)
--time=WORD with -l, show time as WORD instead of default
modification time: atime or access or use (-u)
ctime or status (-c); also use specified time
as sort key if --sort=time
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, or +FORMAT;
FORMAT is interpreted like in 'date'; if FORMAT
is FORMAT1<newline>FORMAT2, then FORMAT1 applies
to non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with 'posix-', STYLE
takes effect only outside the POSIX locale
-t sort by modification time, newest first
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time;
with -l: show access time and sort by name;
otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
--lcontext Display security context. Enable -l. Lines
will probably be too wide for most displays.
-Z, --context Display security context so it fits on most
displays. Displays only mode, user, group,
security context and file name.
--scontext Display only security context and file name.
--help 显示此帮助信息并退出
--version 显示版本信息并退出
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
使用色彩来区分文件类型的功能已被禁用,默认设置和 --color=never 同时禁用了它。
使用 --color=auto 选项,ls 只在标准输出被连至终端时才生成颜色代码。
LS_COLORS 环境变量可改变此设置,可使用 dircolors 命令来设置。
退出状态:
0 正常
1 一般问题 (例如:无法访问子文件夹)
2 严重问题 (例如:无法使用命令行参数)
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告ls 的翻译错误
要获取完整文档,请运行:info coreutils 'ls invocation'
man
格式:man [选项](不写默认1) [对象]
查看man指令手册
[root@localhost ~]# man man
[选项]
该清单是一组用冒号分隔的欲查找的手册清单。此选项将覆盖 MANSECT 环境变量。
有些指令或程序可能有一个以上的主题,它们位于不同的区段中。因此,要查看较后的区
段,你可以在此指定 man 查找区段的顺序。具体区段划分如下所示:
区段1:用户指令
区段2:系统调用
区段3:程序库调用
区段4:设备
区段5:文件格式
区段6:游戏
区段7:杂项
区段8:系统指令
区段9:内核内部指令
区段n:Tcl或Tk指令
目录命令
cd
cd 目标位置 change directory
[root@localhost ~]# cd ..
[root@localhost /]# cd /mnt
[root@localhost mnt]# cd -
/
[root@localhost /]# cd ~sa
~saber/ ~saslauth
[root@localhost /]# cd ~sa
~saber/ ~saslauth
[root@localhost /]# cd ~saber
[root@localhost saber]#
命令 | 效果 |
---|---|
cd cd ~ | 若不指定目标位置,切换到当前用户的宿主目录(家目录) |
cd - | 到前一次目录 |
一个点号“.”开头(自己) | 表示以当前的工作目录作为起点(已点开头的是) |
两个点号“..”开头(上一级) | 表示以当前目录的上一级目录(父目录)作为起点 |
“~用户名”形式开头 | 表示以指定用户的宿主目录(家目录)作为起点 |
"."开头文件 | 表示隐藏文件 |
~ky18 (有个用户叫ky18 家目录为起点) | 表示以指定用户的宿主目录作为起点 |
目录
七类常见的linux的文件
- d 目录文件directory
- b 块设备文件block 块设备文件,就是保存大块数据的设备,比如最常见的硬盘。
- c 字符设备character 这些文件通常隐藏在 /dev/ 目录下,当进行设备读取或外设交互时才会被使用
- l 符号链接文件link
- p 管道文件pipe 主要用于进程间通信单向传输 一个发一个输管道文件
- s 套接字文件socket 套接字文件一般隐藏在 /var/run/ 目录下,用于进程间的网络通信
- -普通文件 普通文件,包括纯文本文件、二进制文件、各种压缩文件等
第一个字符 | 文件类型 |
---|---|
- | 普通文件,包括纯文本文件、二进制文件、各种压缩文件等。 |
d | 目录,类似 Windows 系统中的文件夹。 |
b | 块设备文件,就是保存大块数据的设备,比如最常见的硬盘。 |
c | 字符设备文件,例如键盘、鼠标等。 |
s | 套接字文件,通常用在网络数据连接,可以启动一个程序开监听用户的要求,用户可以通过套接字进行数据通信。 |
p | 管道文件,其主要作用是解决多个程序同时存取一个文件所造成的错误。 |
l | 链接文件,类似 Windows 系统中的快捷方式。 |