Basic command operation
- One.shell
-
- 2. Classification of linux commands
-
- 3. Linux command line format
-
- Four. Edit Linux command line auxiliary operation
-
- V. Ways to get command help
-
- 1. Internal command help:
- 2. Command "- -help" option
- 3. Use the man (manual manual) command to read the man page
- 4. Baidu
- 6. View the current working directory pwd
- Seven. Switch working directory cd
- 8. Relative path, absolute path
- Nine. List the contents of the directory -ls
- 10. Set alias-alias
- 11. Statistic directory and file space occupation-du
- 12. Create a new empty directory-mkdir
- 13. Create an empty file-touch
- 14. Create a link file -ln
- 15. Copy files or directories-cp
One.shell
1. A special program running in the Linux system
2. Acting as a "translator" between the user and the kernel
3. When the user logs in to the Linux system, a Shell program
is automatically loaded 4. Bash is the shell used by default in the Linux system program
The file is located in /bin/bash
2. Classification of linux commands
Internal command | External instructions |
---|---|
Some special instructions integrated in the shell interpreter program, also known as built-in instructions | A script file or binary program that can complete the specified function in the linux system |
Part of Shell | Commands other than Shell interpreter programs |
There is no separate corresponding system file | Each external command corresponds to a file in the system |
Automatically load into memory, can be used directly | The corresponding file location must be known, and /bin, /usr/bin, etc. can be executed after being loaded by Shell |
3. Linux command line format
命令字 [选项] [参数] 英文字符区分大小写
●Command word: Operation
is the most critical part of the entire command, the
only command is determined
●Option: Function
- Short format options: use the "-" symbol to guide (multiple single-character options can be combined together)
- Long format option: use the "–" symbol to guide (the complete word follows)
●Parameter: the object to be executed The
processing object of the command word
can be a file name, a directory (path) name or a user name, etc. The
number can be zero or more
Four. Edit Linux command line auxiliary operation
button | effect |
---|---|
Tab键 | Autocomplete |
Backslash "\" | Force line break |
Ctrl+U key combination | Empty to the beginning of the line |
Ctrl+K | Empty to the end of the line |
Ctrl+L | Clear the screen, or clear |
Ctrl+C | Cancel this command edit |
Ctrl+a | Switch to the beginning of the line |
Ctrl+e | Switch to end of line |
V. Ways to get command help
1. Internal command help:
查看Shell内部命令的帮助信息
[root@localhost data]# help
GNU bash, 版本 4.2.46(2)-release (x86_64-redhat-linux-gnu)
这些 shell 命令是内部定义的。请输入 `help' 以获取一个列表.
输入 `help 名称' 以得到有关函数`名称'的更多信息.
使用 `info bash' 来获得关于 shell 的更多一般性信息
使用 `man -k' 或 `info' 来获取不在列表中的命令的更多信息.
名称旁边的星号 (*) 意味着该命令被禁用.
job_spec [&] history [-c] [-d 偏移量] [n] 或 h>
(( 表达式 )) if 命令; then 命令; [ elif 命令>
. 文件名 [参数] jobs [-lnprs] [任务声明 ...] 或 >
: kill [-s 信号声明 | -n 信号编
[ 参数... ] let 参数 [参数 ...]
[[ 表达式 ]] local [option] 名称[=值] ...
alias [-p] [名称[=值] ... ] logout [n]
bg [任务声明 ...] mapfile [-n 计数] [-O 起始序号]>
bind [-lpvsPVS] [-m 键映射] [-f 文> popd [-n] [+N | -N]
break [n] printf [-v var] 格式 [参数]
builtin [shell 内嵌 [参数 ...]] pushd [-n] [+N | -N | 目录]
caller [表达式] pwd [-LP]
case 词 in [模式 [| 模式]...) 命> read [-ers] [-a 数组] [-d 分隔符>
cd [-L|[-P [-e]]] [dir] readarray [-n 计数] [-O 起始序卾
command [-pVv] 命令 [参数 ...] readonly [-aAf] [name[=value] ...] or>
compgen [-abcdefgjksuv] [-o 选项] [> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] [> select NAME [in 词语 ... ;] do 命
compopt [-o|+o 选项] [-DE] [名称 .> set [-abefhkmnptuvxBCHP] [-o option-n>
continue [n] shift [n]
coproc [名称] 命令 [重定向] shopt [-pqsu] [-o] [选项名 ...]
declare [-aAfFgilrtux] [-p] [name[=val> source 文件名 [参数]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [任务声明 ...] test [表达式]
echo [-neE] [参数 ...] time [-p] 管道
enable [-a] [-dnps] [-f 文件名] [厾 times
eval [参数 ...] trap [-lp] [[参数] 信号声明 ...>
exec [-cl] [-a 名称] [命令 [参数> 真
exit [n] type [-afptP] 名称 [名称 ...]
export [-fn] [名称[=值] ...] 或 ex> typeset [-aAfFgilrtux] [-p] name[=val>
伪 ulimit [-SHacdefilmnpqrstuvx] [限制>
fc [-e 编辑器名] [-lnr] [起始] [> umask [-p] [-S] [模式]
fg [任务声明] unalias [-a] 名称 [名称 ...]
for 名称 [in 词语 ... ] ; do 命乾 unset [-f] [-v] [名称 ...]
for (( 表达式1; 表达式2; 表达㼠 until 命令; do 命令; done
function 名称 {
命令 ; } 或 name > variables - 一些 shell 变量的名>
getopts 选项字符串 名称 [参数> wait [编号]
hash [-lr] [-p 路径名] [-dt] [名祾 while 命令; do 命令; done
help [-dms] [模式 ...] {
命令 ; }
[root@localhost data]#
2. Command "- -help" option
适用于大多数Linux外部命令
[root@localhost data]# 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'
[root@localhost data]#
3. Use the man (manual manual) command to read the man page
●Use the "⬆" and "⬇" (ENTER) arrow keys to scroll a line of text
● Use the Page Up and Page Down (space) keys to turn pages
● Press the Q or q key to exit the reading environment
● Press the "/" key to find the content, the n key Find down, N key to find up
4. Baidu
6. View the current working directory pwd
pwd ---显示用户当前所在的工作目录位置
Seven. Switch working directory cd
cd ---将用户的工作目录更改到其他位置
cd switch to the target location
cd or cd If the target location is not specified, switch to the current user's home directory
cd-switch to the directory where the cd command was executed last time
8. Relative path, absolute path
●绝对路径:以/开头,根目录为起点
●相对路径:以当前目录为起点
Relative path expression:
Nine. List the contents of the directory -ls
ls ----显示目录中内容,包括子目录和文件相关属性信息
ls【文件】【文件或目录…】
Option l | effect |
---|---|
-l | Display a list of files and directories in long format (Long), including detailed information such as permissions, sizes, and last update time. The ll command has the same function as ls -l |
-a | Display information of all (All) subdirectories and files, including hidden directories and hidden files whose names start with a dot "." |
-A | The function is basically similar to the -a option, but there are two special hidden directories that will not be displayed, namely "." for the current directory and "..." for the parent directory |
-d | Display the attributes of the directory (Directory) itself, instead of displaying the contents of the directory |
-h | Display the size of the directory or file in a more human way. The default size unit is byte (B). After using the -h option, it will be displayed in units of KB, MB, etc. This option needs to be used in conjunction with the -l option. |
-R | Display all contents in the specified directory and its subdirectories in a recursive manner. |
-color | In the character mode, different files are distinguished by color. It is turned on by default. (Usually, dark blue indicates directories, white indicates general files, green indicates executable files, yellow indicates device files, red indicates compressed files, and light blue indicates file shortcuts.) |
-i | Display the inode numbers of files and directories |
●Combined wildcard
"?": represents any character, and at least one
"*": represents any number of characters, which can be 0 or 1 or more
"[]": means that any character in the character group can be matched
10. Set alias-alias
alias
●通过别名机制简化常用的、比较长的命令
alias命令别名=‘命令’
例:alias myls=‘ls-alh’
●取消别名:unalias 命令别名
11. Statistic directory and file space occupation-du
du
-a | Count the disk space occupied by all files and directories (including this directory) |
---|---|
-h | Display the statistical results in a more user-friendly way (the default count is KB, but the unit is not displayed) |
-s | Only count the size of the occupied space, not the size of each subdirectory and file |
- -max-depth=n | Count the total size of all directories less than or equal to the nth level |
Note: Options -a and -s cannot be used at the same time
12. Create a new empty directory-mkdir
●创建新的空目录
mkdir [Options] Directory location and name
Example:
create a subdirectory named public_html in the current directory
mkdir public_html
create directory /aa, create subdirectory bb under /aa directory, create subdirectory cc
mkdir under /aa/bb directory -p aa/bb/cc
13. Create an empty file-touch
●更新文件的时间标记
●经常用于创建多个新的空文件
touch 文件…
例:
touch {aa,bb}.txt = touch aa.txt touch bb.txt
14. Create a link file -ln
●为文件或目录建立链接文件,类似于Windows系统的快捷方式
Link file type:
Link files are divided into soft links (symbolic links) and hard links
15. Copy files or directories-cp
●将需要复制的文件或目录(源)重建一份,并保存为新的文件或目录
●cp 【选项】…源文件或目录…目标文件或目录…
-f | No reminder when overwriting the target file or directory with the same name, just force copy |
---|---|
-i | Remind the user to confirm when overwriting the target file or directory with the same name |
-p | Keep the permissions, owner and time stamp of the source file unchanged when copying |
-r | Must be used when copying directories, which means that all files and subdirectories are recursively copied |
Note: When copying multiple files or directories, the target location must be a directory, and the target directory must already exist