Shell 可以看作是一个命令解释器,为我们提供了交互式的文本控制台界面。我们可以 通过终端控制台来输入命令,由 shell 进行解释并最终交给内核执行。
部分基础命令:
type 其他命令,查看命令的信息manual单词。

[root@yhx system]# man ls
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 '*'
--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 like -l, but do not list owner
--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
in a long listing, don't print group names
-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 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 use a long listing format
-L, --dereference
when showing file information for a symbolic link, show information for the file the link references rather than for the link itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid
like -l, but list numeric user and group IDs
-N, --literal
print raw entry names (don't treat e.g. control characters specially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-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
reverse order while sorting
-R, --recursive
list subdirectories recursively
-s, --size
print the allocated size of each file, in blocks
-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 FORMAT1FORMAT2, 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 display this help and exit
--version
output version information and exit
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).
Using color to distinguish file types is disabled both by default and with --color=never. With --color=auto, ls emits color codes only when standard output is connected to a terminal. The LS_COLORS environment
variable can change the settings. Use the dircolors command to set it.
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
GNU coreutils online help: Report ls translation bugs to
AUTHOR
Written by Richard M. Stallman and David MacKenzie.
COPYRIGHT
Copyright ? 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for ls is maintained as a Texinfo manual. If the info and ls programs are properly installed at your site, the command
info coreutils ' ls invocation'
should give you access to the complete manual.
一部分基础功能的系统命令是直接内嵌在 shell 中的,系统加载启动之后会随着 shell 一起加载,常驻系统内存中。这部分命令被称为“内置(built-in)命令”;相应的其它命令 被称为“外部命令”
help 命令:获得 shell 内置命令的帮助信息[root@yhx system]# 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.
[root@yhx system]#
外部命令:
[root@yhx system]# ls --help
....
pwd[root@yhx system]# pwd
/usr/lib/systemd/system
# 如果是链接,可使用-P查看原始路径
[root@yhx bin]# pwd
/bin
[root@yhx bin]# pwd -P
/usr/bin
ls [选项] [目录或是文件]ll(常用)。[root@yhx jdk-17.0.2]# ls
bin conf include jmods legal lib LICENSE man README release
[root@yhx jdk-17.0.2]# ls -i
393809 bin 393838 conf 393860 include 393870 jmods 393941 legal 394183 lib 393807 LICENSE 394244 man 393808 README 394279 release
# 每行列出的信息依次是:
#文件类型与权限 链接数 文件属主 文件属组 文件大小用byte 来表示 建立或最近修改的时间 名字
[root@yhx jdk-17.0.2]# ls -l
total 36
drwxr-xr-x 2 root root 4096 Mar 18 15:43 bin
drwxr-xr-x 5 root root 4096 Mar 18 15:43 conf
drwxr-xr-x 3 root root 4096 Mar 18 15:43 include
drwxr-xr-x 2 root root 4096 Mar 18 15:43 jmods
drwxr-xr-x 72 root root 4096 Mar 18 15:43 legal
drwxr-xr-x 5 root root 4096 Mar 18 15:43 lib
lrwxrwxrwx 1 10668 10668 23 Dec 8 2021 LICENSE -> legal/java.base/LICENSE
drwxr-xr-x 3 root root 4096 Mar 18 15:43 man
-rw-r--r-- 1 10668 10668 290 Dec 8 2021 README
-rw-r--r-- 1 10668 10668 1231 Dec 8 2021 release
[root@yhx jdk-17.0.2]# ls -a
. .. bin conf include jmods legal lib LICENSE man README release
[root@yhx jdk-17.0.2]#
其中:
cd 目录名 (绝对路径都是以 / 开头,相对路径,对于当前目录改如何寻找 …/…/)
[root@yhx ~]# cd / 当前目录
[root@yhx /]# cd .. 返回上一级目录

mkdir [选项] 要创建的目录[root@yhx java]# mkdir name
[root@yhx java]# mkdir name/name1
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]# cd name/
[root@yhx name]# ls
name1
[root@yhx name]# cd ..
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]# mkdir key/key1/key2
mkdir: cannot create directory ‘key/key1/key2’: No such file or directory
[root@yhx java]# mkdir -p key/key1/key2
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz key name
[root@yhx java]#
rmdir 要删除的空目录[root@yhx java]# rmdir key
rmdir: failed to remove ‘key’: Directory not empty
[root@yhx java]# rmdir name/
rmdir: failed to remove ‘name/’: Directory not empty
[root@yhx java]# rmdir name/name1/
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz key name
[root@yhx java]# cd name/
[root@yhx name]# ls
[root@yhx name]# cd ..
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz key name
[root@yhx java]# rmdir -p key/
rmdir: failed to remove ‘key/’: Directory not empty
[root@yhx java]# rmdir -p key/key1/key2/
[root@yhx java]# ls
jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]#
touch 文件名称[root@yhx home]# touch 123.txt
[root@yhx home]# ls
123.txt docker-study java mysql nginx redis studyDockerfile
cp [选项] source dest,复制source到dest[root@yhx home]# cp 123.txt 1234.txt
[root@yhx home]# ls
1234.txt 123.txt docker-study java mysql nginx redis studyDockerfile
[root@yhx home]# cp 123.txt 1234.txt
cp: overwrite ‘1234.txt’? y
[root@yhx home]# ls
1234.txt 123.txt docker-study java mysql nginx redis studyDockerfile
# 原始命令复制(强制覆盖)
[root@yhx home]# \cp 123.txt 1234.txt
[root@yhx home]# ls
1234.txt 123.txt docker-study java mysql nginx redis studyDockerfile
[root@yhx home]# cp java/ java1
cp: omitting directory ‘java/’
[root@yhx home]# ls
1234.txt 123.txt docker-study java mysql nginx redis studyDockerfile
# 递归复制文件夹
[root@yhx home]# cp -r java/ java1
[root@yhx home]# ls
1234.txt 123.txt docker-study java java1 mysql nginx redis studyDockerfile
[root@yhx home]#
rm [选项] deleteFile[root@yhx home]# rm 123.txt
rm: remove regular empty file ‘123.txt’? y
[root@yhx home]# rm -f 1234.txt
[root@yhx home]# ls
docker-study java java1 mysql nginx redis studyDockerfile
[root@yhx home]# rm -f java1
rm: cannot remove ‘java1’: Is a directory
[root@yhx home]# rm -rf java1
[root@yhx home]# ls
docker-study java mysql nginx redis studyDockerfile
[root@yhx home]#
mv oldNameFile newNameFilemv /temp/movefile /targetFolder[root@yhx home]# ls
docker-study java1 mysql nginx redis studyDockerfile
[root@yhx home]# mv java1/ java
[root@yhx home]# ls
docker-study java mysql nginx redis studyDockerfile
[root@yhx home]# touch 123.txt
[root@yhx home]# mv 123.txt java/
[root@yhx home]# ls
docker-study java mysql nginx redis studyDockerfile
[root@yhx home]# cd java/
[root@yhx java]# ls
123.txt jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]#
cat [参数] fileName [ | grep 关键字]| 参数 | 说明 |
|---|---|
| grep 关键字 | 搜索关键字附近的日志 |
| -n 或 --number | 由 1 开始对所有输出的行数编号 |
| -b 或 --number-nonblank | 和 -n 相似,只不过对于空白行不编号 |
| -s 或 --squeeze-blank | 当遇到有连续两行以上的空白行,就代换为一行的空白行 |
| -v 或 --show-nonprinting | 使用 ^ 和 M- 符号,除了LFD 和 TAB 之外 |
| -E 或 --show-ends | 在每行结束处显示$ |
| -T 或 --show-tabs | 将TAB 字符显示为 ^I |
| -A, --show-all | 等价于-vET |
| -e | 等价于"-vE"选项 |
| -t | 等价于"-vT"选项 |
more 要显示文件| 操作 | 功能 |
|---|---|
| 空白键 (space) | 向下翻一页 |
| Enter | 向下翻一行 |
| q | 立刻离开 more ,不再显示该文件内容 |
| Ctrl+F | 向下滚动一屏 |
| Ctrl+B | 返回上一屏 |
| = | 输出当前行的行号 |
| :f | 输出文件名和当前行的行号 |
less 要显示的文件| 操作 | 功能 |
|---|---|
| 空白键 | 向下翻动一页 |
| pagedown | 向下翻动一页 |
| pageup | 向上翻动一页 |
| /字串 | 向下搜寻『字串』的功能;n:向下查找;N:向上查找 |
| ?字串 | 向上搜寻『字串』的功能;n:向上查找;N:向下查找 |
| q | 立刻离开 less 这个程序 |
echo [选项] [输出内容][root@yhx java]# echo "hello world"
hello world
[root@yhx java]# echo "hello world" >> 1234.txt
[root@yhx java]# ls
1234.txt 123.txt jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]# cat 1234.txt
hello world
# 查看系统环境变量
[root@yhx java]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@yhx java]#
head [选项] 文件| 选项 | 说明 |
|---|---|
| -n <行数> | 指定显示前n行的内容 |
head -n 10 test.log 查询日志文件中的头10行日志;
head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;
tail [选项] 文件| 选项 | 说明 |
|---|---|
| -n <行数> | 指定显示后n行的内容 |
| -f | 显示文件最新追加的内容,可用来监视文件变化 |
tail -n 10 test.log 查询日志尾部最后10行的日志;
tail -n +10 test.log 查询10行之后的所有日志;
tail -f test.log 实时监控日志
tail -100f test.log 实时监控100行日志
一个>是覆盖,2个>是追加。
ls -l > 文件:列表的内容写入文件 a.txt 中(覆盖写)ls -al >> 文件:列表的内容追加到文件 aa.txt 的末尾cat 文件 1 > 文件 2:将文件 1 的内容覆盖到文件 2echo “内容” >> 文件实操:
[root@yhx java]# echo "hello world"
hello world
[root@yhx java]# echo "hello world" >> 1234.txt
[root@yhx java]# ls
1234.txt 123.txt jdk-17.0.2 jdk-17_linux-x64_bin.tar.gz name
[root@yhx java]# cat 1234.txt
hello world
[root@yhx java]# ll > 123.txt
[root@yhx java]# cat 123.txt
total 176852
-rw-r--r-- 1 root root 12 Aug 5 16:23 1234.txt
-rw-r--r-- 1 root root 0 Aug 5 16:45 123.txt
drwxr-xr-x 9 root root 4096 Mar 18 15:43 jdk-17.0.2
-rw-r--r-- 1 root root 181083410 Jan 4 2022 jdk-17_linux-x64_bin.tar.gz
drwxr-xr-x 2 root root 4096 Aug 3 17:56 name
[root@yhx java]# ll >> 1234.txt
[root@yhx java]# cat 1234.txt
hello world
total 176856
-rw-r--r-- 1 root root 12 Aug 5 16:23 1234.txt
-rw-r--r-- 1 root root 304 Aug 5 16:45 123.txt
drwxr-xr-x 9 root root 4096 Mar 18 15:43 jdk-17.0.2
-rw-r--r-- 1 root root 181083410 Jan 4 2022 jdk-17_linux-x64_bin.tar.gz
drwxr-xr-x 2 root root 4096 Aug 3 17:56 name
[root@yhx java]#
A—B,假设B是A的硬链接,那么他们两个指向了同一个文件!允许一个文件拥有多个路径,用户可以通过这种机制建立硬链接到一些重要文件上,防止误删!
软链接也称为符号链接,类似于 windows 里的快捷方式,有自己的数据块,主要存放 了链接其他文件的路径
ln -s [原文件或目录] [软链接名] :给原文件创建一个软链接rm -rf 软链接名/ 删除,会把软链接对应的真实目录下内容删掉# 链接到目录
root@yhx home]# ln -s /home/mysql /rootmyMysql
[root@yhx home]# ls
docker-study java mysql nginx redis studyDockerfile
[root@yhx home]# cd ..
[root@yhx /]# ls
bin boot data dev etc home java lib lib64 lost+found media mnt opt proc root rootmyMysql run sbin srv sys tmp usr var zzyyuser
[root@yhx /]# cd rootmyMysql/
[root@yhx rootmyMysql]# ls
conf data log
[root@yhx rootmyMysql]# pwd
/rootmyMysql
[root@yhx rootmyMysql]# pwd -p
-bash: pwd: -p: invalid option
pwd: usage: pwd [-LP]
[root@yhx rootmyMysql]# pwd -P
/home/mysql
# 链接文件
[root@yhx ~]# echo "hello" >> 123.txt
[root@yhx ~]# ls
123.txt redis.tar
[root@yhx ~]# cd /home/
[root@yhx home]# ln -s /root/123.txt myTxt
[root@yhx home]# ls
docker-study java mysql myTxt nginx redis studyDockerfile
[root@yhx home]# cat myTxt
hello
[root@yhx home]#

date [OPTION]... [+FORMAT]date -s 字符串时间[root@yhx home]# date
Fri Aug 5 17:38:23 CST 2022
[root@yhx home]# date +%Y
2022
[root@yhx home]# date +%m
08
[root@yhx home]# date +%d
05
[root@yhx home]# date +%Y-%m-%d-%H:%M:%S
2022-08-05-17:40:10
[root@yhx home]# date +%Y-%m-%d %H:%M:%S
date: extra operand ‘%H:%M:%S’
Try 'date --help' for more information.
[root@yhx home]# date "+%Y-%m-%d %H:%M:%S"
2022-08-05 17:40:22
[root@yhx home]# date +%s
1659692431
[root@yhx home]# date +%S
33
[root@yhx home]# date +%s
1659692438
[root@yhx home]# date +%s
1659692442
[root@yhx home]# date -d "1 days ago"
Thu Aug 4 17:41:20 CST 2022
[root@yhx home]# date -d "-1 days ago"
Sat Aug 6 17:41:23 CST 2022
[root@yhx home]# date -d "-1 hour ago"
Fri Aug 5 18:41:35 CST 2022
[root@yhx home]#
Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统。
用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪,并控制他们对系统资源的访问;另一方面也可以帮助用户组织文件,并为用户提供安全性保护。
每个用户账号都拥有一个唯一的用户名和各自的口令。
用户在登录时键入正确的用户名和口令后,就能够进入系统和自己的主目录
useradd 选项 用户名useradd -g 组名 用户名:添加新用户到某个组/etc/paswd查看[root@yhx home]# useradd lisi
[root@yhx home]# ls
docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile zhangsan
[root@yhx home]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
ecs-assist-user:x:1000:1000::/home/ecs-assist-user:/sbin/nologin
zhangsan:x:1001:1001::/home/zhangsan:/bin/bash
lisi:x:1002:1002::/home/lisi:/bin/bash
userdel 选项 用户名[root@yhx home]# userdel -r zhangsan
[root@yhx home]# ls
docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile
[root@yhx home]# useradd zhangsan
[root@yhx home]# ls
docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile zhangsan
[root@yhx home]# userdel zhangsan
[root@yhx home]# ls
docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile zhangsan
usermod 选项 用户名passwd 用户名[root@yhx home]# passwd lisi
Changing password for user lisi.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@yhx home]#
passwd 选项 用户名id 用户名[root@yhx home]# id zhangsan
id: zhangsan: no such user
[root@yhx home]# id lisi
uid=1002(lisi) gid=1002(lisi) groups=1002(lisi)
[root@yhx home]#
su单词:swith user

su 选项 用户名称[root@yhx home]# su lisi
# $代表普通用户,#代表超级用户
[lisi@yhx home]$
whoami:显示自身用户名称who am i:显示登录用户的用户名以及登陆时间[root@yhx home]# whoami
root
[root@yhx home]# who am i
[root@yhx home]#
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
zhangsan ALL=(ALL) ALL
每个用户都有一个用户组,系统可以对一个用户组中的所有用户进行集中管理。不同 Linux 系统对用户组的规定有所不同, 如Linux下的用户属于与它同名的用户组,这个用户组在创建用户时同时创建。 用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对 /etc/group文件的更新
groupadd 选项 用户组[root@yhx home]# groupadd group1
[root@yhx home]# cat /etc/group
......
group1:x:1003:
[root@yhx home]# groupadd -g 1010 group2
[root@yhx home]# cat /etc/group
......
group1:x:1003:
group2:x:1010:
groupdel 用户组groupmod 选项 组名[root@yhx home]# groupmod -g 1004 -n group3 group1
[root@yhx home]# cat /etc/group
........
group2:x:1010:
group3:x:1004:
[root@yhx home]#
cat /etc/groupLinux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限。 为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做 了不同的规定。在Linux中我们可以使用ll或者ls -l命令来显示一个文件的属性以及文件所属 的用户和组。
[root@yhx home]# ll
total 40
drwxr-xr-x 2 root root 4096 Mar 15 20:46 docker-study
drwx------ 2 ecs-assist-user ecs-assist-user 4096 Aug 8 14:07 ecs-assist-user
-rw-r--r-- 1 root root 12 Aug 5 17:15 f1
lrwxrwxrwx 1 root root 7 Aug 5 17:16 f2 -> 123.txt
drwxr-xr-x 2 root root 4096 Aug 5 16:58 java
drwx------ 2 lisi lisi 4096 Aug 8 14:15 lisi
drwxr-xr-x 5 root root 4096 Mar 16 10:57 mysql
lrwxrwxrwx 1 root root 13 Aug 5 17:01 myTxt -> /root/123.txt
drwxr-xr-x 4 root root 4096 Mar 24 16:36 nginx
drwxr-xr-x 4 root root 4096 Mar 30 14:26 redis
drwxr-xr-x 2 root root 4096 Mar 18 16:34 studyDockerfile
drwx------ 2 1003 1003 4096 Aug 8 14:29 zhangsan

如果没有权限,就会出现减号[ - ]而已。从左至右用0-9这些数字来表示:
chmod [-R] xyz 文件或目录chmod [{ugoa}{+-=}{rwx}] 文件或目录chmod [mode=421 ] [文件或目录][root@yhx java]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 8 16:22 123.txt
[root@yhx java]# chmod g+w 123.txt/
[root@yhx java]# ll
total 4
drwxrwxr-x 2 root root 4096 Aug 8 16:22 123.txt
[root@yhx java]# chmod u-w,g-w,o+w 123.txt/
[root@yhx java]# ll
total 4
dr-xr-xrwx 2 root root 4096 Aug 8 16:22 123.txt
[root@yhx java]# chmod 777 123.txt/
[root@yhx java]# ll
total 4
drwxrwxrwx 2 root root 4096 Aug 8 16:22 123.txt
[root@yhx java]# chmod 764 123.txt/
[root@yhx java]# ll
total 4
drwxrw-r-- 2 root root 4096 Aug 8 16:22 123.txt
[root@yhx java]# mkdir test
[root@yhx java]# ll
total 8
drwxrw-r-- 2 root root 4096 Aug 8 16:22 123.txt
drwxr-xr-x 2 root root 4096 Aug 8 16:24 test
[root@yhx java]# cd test/
[root@yhx test]# mkdir test1
[root@yhx test]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 8 16:24 test1
[root@yhx test]# cd ..
[root@yhx java]# chmod 777 test/
[root@yhx java]# ll
total 8
drwxrw-r-- 2 root root 4096 Aug 8 16:22 123.txt
drwxrwxrwx 3 root root 4096 Aug 8 16:24 test
[root@yhx java]# cd test/
[root@yhx test]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 8 16:24 test1
[root@yhx test]# cd ..
[root@yhx java]# chmod -R 777 test/
[root@yhx java]# ll
total 8
drwxrw-r-- 2 root root 4096 Aug 8 16:22 123.txt
drwxrwxrwx 3 root root 4096 Aug 8 16:24 test
[root@yhx java]# cd test/
[root@yhx test]# ll
total 4
drwxrwxrwx 2 root root 4096 Aug 8 16:24 test1
[root@yhx test]#
chown [选项] [最终用户] [文件或目录]chgrp [选项] [最终用户组] [文件或目录]find 指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件显示在终端
find [搜索范围] [选项][root@yhx /]# find /home -name test
/home/java/test
[root@yhx /]# find /home -user lisi
/home/lisi
/home/lisi/.bash_profile
/home/lisi/.bash_logout
/home/lisi/.bashrc
[root@yhx /]# find /home -size +204800
/home/studyDockerfile/jdk-17_linux-x64_bin.tar.gz
[root@yhx /]#
locate 指令利用事先建立的系统中所有文件名称及路径的 locate 数据库实现快速定位给 定的文件。Locate 指令无需遍历整个文件系统,查询速度较快。为了保证查询结果的准确 度,管理员必须定期更新 locate 时刻
locate 搜索文件管道符,“|”,表示将前一个命令的处理结果输出传递给后面的命令处理
grep 选项 查找内容 源文件[root@yhx home]# ls
docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile zhangsan
[root@yhx home]# ls | grep java
java
[root@yhx home]# ls | grep -n java
5:java
[root@yhx home]#
root@yhx java]# ls
123.txt
[root@yhx java]# gzip 123.txt
[root@yhx java]# ls
123.txt.gz
[root@yhx java]# gunzip 123.txt.gz
[root@yhx java]# ls
123.txt
[root@yhx java]#
zip [选项] 压缩后名称 压缩的内容unzip [选项] XXX.zip[root@yhx java]# zip 1.zip 123.txt
adding: 123.txt (stored 0%)
[root@yhx java]# ls
123.txt 1.zip
[root@yhx java]# unzip 1.zip
Archive: 1.zip
replace 123.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: u
error: invalid response [u]
replace 123.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
extracting: 123.txt
[root@yhx java]# ls
123.txt 1.zip
[root@yhx java]# unzip 1.zip -d /home/
Archive: 1.zip
extracting: /home/123.txt
[root@yhx java]# cd /home/
[root@yhx home]# ls
123.txt docker-study ecs-assist-user f1 f2 java lisi mysql myTxt nginx redis studyDockerfile zhangsan
[root@yhx home]#
tar [选项] XXX.tar.gz 将要打包进去的内容[root@yhx java]# ls
123.txt
[root@yhx java]# tar -zcvf 1.tar.gz 123.txt
123.txt
[root@yhx java]# ls
123.txt 1.tar.gz
[root@yhx java]# tar -zxvf 1.tar.gz
123.txt
[root@yhx java]# ls
123.txt 1.tar.gz
[root@yhx java]# tar -zxvf 1.tar.gz -C /home/lisi/
123.txt
[root@yhx java]# cd /home/lisi/
[root@yhx lisi]# ls
123.txt
[root@yhx lisi]#
df命令参数功能:检查文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息
df含义:disk free 空余磁盘
df [选项] [目录或文件名][root@yhx java]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 496644 0 496644 0% /dev
tmpfs 507232 0 507232 0% /dev/shm
tmpfs 507232 452 506780 1% /run
tmpfs 507232 0 507232 0% /sys/fs/cgroup
/dev/vda1 41152812 7521104 31728000 20% /
tmpfs 101448 0 101448 0% /run/user/0
[root@yhx java]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 486M 0 486M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 452K 495M 1% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/vda1 40G 7.2G 31G 20% /
tmpfs 100M 0 100M 0% /run/user/0
[root@yhx java]#
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的,这里介绍Linux du命令
du含义:disk usage 磁盘占用情况
du [选项] 文件或目录名称[root@yhx java]# ls
123.txt 1.tar.gz
[root@yhx java]# du -a
0 ./123.txt
4 ./1.tar.gz
8 .
[root@yhx java]# du -sh
8.0K .
[root@yhx java]# du
8 .
[root@yhx java]#
lsblk