修改时间

date -s 月/日/年 例如:date -s 07/31/2019

date -s 时:分:秒 例如:date -s 23:56:50

hwclock -w 将时间写到bois,防止重启机器时间配置失效

帮助命令

man 获得帮助信息

man 命令或配置文件

例如:man date 或 man ls 或 man systemctl

help 获得shell内置命令的帮助信息

命令 --help

例如:ls --help

[root@localhost112 ~]# ls --help
Usage: ls [OPTION]... [FILE]...
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

文件目录类

ls 查看文件或者目录
[root@localhost112 ~]# ls
aaa anaconda-ks.cfg openscap_data
[root@localhost112 ~]# ls -l
总用量 4
-rw-r--r--. 1 root root 0 7月 31 02:23 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# ls -a
. .. aaa anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .bbbb .cshrc .lesshst openscap_data .tcshrc
[root@localhost112 ~]# ls -lhi
总用量 4.0K
68977613 -rw-r--r--. 1 root root 0 7月 31 02:23 aaa
68972994 -rw-------. 1 root root 1.5K 8月 1 07:16 anaconda-ks.cfg
34706362 drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# ls -la
总用量 44
dr-xr-x---. 3 root root 4096 7月 31 02:23 .
dr-xr-xr-x. 17 root root 4096 8月 2 12:57 ..
-rw-r--r--. 1 root root 0 7月 31 02:23 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
-rw-------. 1 root root 5593 7月 31 02:17 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 0 8月 1 09:16 .bbbb
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
-rw-------. 1 root root 35 7月 31 23:54 .lesshst
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
cd 切换目录

cd .. 返回上级目录

cd ~ 返回家目录

cd /root/ 切换到指定目录

[root@localhost112 ~]# cd ..
[root@localhost112 /]# cd /root
[root@localhost112 ~]# cd ~
cp 复制文件和目录

cp 文件名 新路径地址 例如:cp test /root/testdir

cp -r source targetfile 递归复制文件到新地址

[root@localhost112 ~]# cp testdir /
cp: 略过目录"testdir"
[root@localhost112 ~]# cp aaa /
[root@localhost112 ~]# cp -r testdir /
[root@localhost112 ~]# ll
总用量 8
-rw-r--r--. 1 root root 14 8月 2 15:59 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 21 8月 2 15:44 testdir
lrwxrwxrwx. 1 root root 7 8月 2 15:54 testdir1 -> testdir
[root@localhost112 ~]# cd /
[root@localhost112 /]# ll
总用量 36
-rw-r--r--. 1 root root 14 8月 2 16:03 aaa
lrwxrwxrwx. 1 root root 7 8月 1 07:13 bin -> usr/bin
dr-xr-xr-x. 4 root root 4096 8月 1 07:17 boot
drwxr-xr-x. 20 root root 3160 8月 2 12:45 dev
drwxr-xr-x. 80 root root 8192 7月 31 03:12 etc
drwxr-xr-x. 5 root root 38 7月 31 02:50 home
lrwxrwxrwx. 1 root root 7 8月 1 07:13 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 8月 1 07:13 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 8月 12 2015 media
drwxr-xr-x. 2 root root 6 8月 12 2015 mnt
drwxr-xr-x. 2 root root 6 8月 12 2015 opt
dr-xr-xr-x. 354 root root 0 8月 2 12:45 proc
dr-xr-x---. 4 root root 4096 8月 2 15:54 root
drwxr-xr-x. 22 root root 620 8月 2 12:45 run
lrwxrwxrwx. 1 root root 8 8月 1 07:13 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 8月 12 2015 srv
dr-xr-xr-x. 13 root root 0 8月 2 12:45 sys
drwxr-xr-x. 2 root root 21 8月 2 16:03 testdir
drwxrwxrwt. 7 root root 4096 7月 31 02:24 tmp
drwxr-xr-x. 13 root root 4096 8月 1 07:13 usr
drwxr-xr-x. 19 root root 4096 8月 2 12:45 var
cat 从前到后查看文件内容
[root@localhost112 ~]# cat aaa
this is aaaa file1
this is aaaa file2
this is aaaa file3
this is aaaa file4
this is aaaa file5
this is aaaa file6
this is aaaa file7
this is aaaa file8
this is aaaa file9
this is aaaa file10
this is aaaa file11
this is aaaa file12
tac 从后到前查看文件内容
[root@localhost112 ~]# tac aaa
this is aaaa file12
this is aaaa file11
this is aaaa file10
this is aaaa file9
this is aaaa file8
this is aaaa file7
this is aaaa file6
this is aaaa file5
this is aaaa file4
this is aaaa file3
this is aaaa file2
this is aaaa file1
rm 删除文件或目录

rm -f 文件或目录名 删除文件或目录

rm -rf 文件或目录名 递归删除文件和目录

[root@localhost112 ~]# rm -f aaa
[root@localhost112 ~]# ll
总用量 4
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
mkdir 新建目录

mkdir 目录名

[root@localhost112 ~]# mkdir testdir
[root@localhost112 ~]# ll
总用量 4
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 6 8月 2 15:39 testdir
rmdir 删除空目录

rmdir 空目录名 不能删除非空目录;

[root@localhost112 ~]# cd testdir
[root@localhost112 testdir]# ll
总用量 0
-rw-r--r--. 1 root root 0 8月 2 15:44 testfile
[root@localhost112 testdir]# cd ..
[root@localhost112 ~]# rmdir testdir
rmdir: 删除 "testdir" 失败: 目录非空
touch 新建空文件

touch 文件名

[root@localhost112 ~]# ll
总用量 4
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 6 8月 2 15:39 testdir
[root@localhost112 ~]# cd testdir
[root@localhost112 testdir]# touch testfile
[root@localhost112 testdir]# ll
总用量 0
-rw-r--r--. 1 root root 0 8月 2 15:44 testfile
pwd 查看当前工作目录
[root@localhost112 testdir]# pwd
/root/testdir
more 查看文件内容

more +num 文件名 例如:more +5 aaa 从第五行开始显示内容

Enter:代表向下翻『一行』;

q:代表立刻离开 more ,不再显示该文件内容。

Ctrl+F 向下滚动一屏

Ctrl+B 返回上一屏

= 输出当前行的行号

:f 输出文件名和当前行的行号

[root@localhost112 ~]# more +5 aaa
this is aaaa file5
this is aaaa file6
this is aaaa file7
this is aaaa file8
this is aaaa file9
this is aaaa file10
this is aaaa file11
this is aaaa file12
less 查看文件内容

less 与 more 类似,都查看文件, 不打印在窗口上。

空白键 :向下翻动一页;

[pagedown]:向下翻动一页;

[pageup] :向上翻动一页;

/字串 :向下搜寻『字串』的功能;n:向下查找;N:向上查找;

?字串 :向上搜寻『字串』的功能;n:向上查找;N:向下查找;

q :离开这个程序;

[root@localhost112 ~]# less aaa
head 查看头部几行

head -n num 文件名 例如:head -n 4 aaa

[root@localhost112 ~]# head -n 5 aaa
hello bigdata1
hello bigdata2
hello bigdata3
hello bigdata4
hello bigdata5
mv 移动文件或重命名文件

mv oldname newname 重命名文件

mv oldfile /root/targetfile 移动文件或目录

[root@localhost112 ~]# ll
总用量 8
-rw-r--r--. 1 root root 14 8月 2 15:59 aaa1
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 21 8月 2 15:44 testdir1
[root@localhost112 ~]# mv aaa1 aaa
[root@localhost112 ~]# ll
总用量 8
-rw-r--r--. 1 root root 14 8月 2 15:59 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 21 8月 2 15:44 testdir1
[root@localhost112 ~]# mv testdir1 /
[root@localhost112 ~]# ll
总用量 8
-rw-r--r--. 1 root root 14 8月 2 15:59 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# cd /
[root@localhost112 /]# ll
总用量 32
lrwxrwxrwx. 1 root root 7 8月 1 07:13 bin -> usr/bin
dr-xr-xr-x. 4 root root 4096 8月 1 07:17 boot
drwxr-xr-x. 20 root root 3160 8月 2 12:45 dev
drwxr-xr-x. 80 root root 8192 7月 31 03:12 etc
drwxr-xr-x. 5 root root 38 7月 31 02:50 home
lrwxrwxrwx. 1 root root 7 8月 1 07:13 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 8月 1 07:13 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 8月 12 2015 media
drwxr-xr-x. 2 root root 6 8月 12 2015 mnt
drwxr-xr-x. 2 root root 6 8月 12 2015 opt
dr-xr-xr-x. 352 root root 0 8月 2 12:45 proc
dr-xr-x---. 3 root root 4096 8月 2 16:08 root
drwxr-xr-x. 22 root root 620 8月 2 12:45 run
lrwxrwxrwx. 1 root root 8 8月 1 07:13 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 8月 12 2015 srv
dr-xr-xr-x. 13 root root 0 8月 2 12:45 sys
drwxr-xr-x. 2 root root 21 8月 2 15:44 testdir1
drwxrwxrwt. 7 root root 4096 8月 2 16:08 tmp
drwxr-xr-x. 13 root root 4096 8月 1 07:13 usr
drwxr-xr-x. 19 root root 4096 8月 2 12:45 var
tail 查看文件内容

tail -F 文件名 实时监控文件内容

tail -n num 文件名 查看文件尾部num行

[root@localhost112 ~]# tail -n 6 aaa
hello bigdata16
hello bigdata17
hello bigdata18
hello bigdata19
hello bigdatai20 [root@localhost112 ~]# tail -F aaa
hello bigdata12
hello bigdata13
hello bigdata14
hello bigdata15
hello bigdata16
hello bigdata17
hello bigdata18
hello bigdata19
hello bigdatai20
echo 输出或者追加到某文件

echo 内容字符串 >> 目标文件 输出内容追加到目标文件 例如:echo 'test' >> /root/aaa

echo 内容字符串 > 目标文件 内容覆盖掉目标文件 例如: echo 'test' > /root/aaa

[root@localhost112 ~]# echo "hello world" >> aaa
[root@localhost112 ~]# cat aaa
this is aaaa file1
this is aaaa file2
this is aaaa file3
this is aaaa file4
this is aaaa file5
this is aaaa file6
this is aaaa file7
this is aaaa file8
this is aaaa file9
this is aaaa file10
this is aaaa file11
this is aaaa file12
hello world
[root@localhost112 ~]# echo "hello bigdata" > aaa
[root@localhost112 ~]# cat aaa
hello bigdata
history 查看输入的历史命令
[root@localhost112 ~]# history
1 netstat
2 netstat -help
3 cd /etc/sysconfig/network-scripts/
4 ls
5 vi ifcfg-eno16777736
6 cat ifcfg-eno16777736
7 service network restart
8 ping 192.168.1.1
9 ping 192.168.1.111
10 ping 192.168.1.113
11 date

重定向命令

ln 软链接

ln -s 源文件名 新链接名字 例如:ln -s test test1

[root@localhost112 ~]# ln -s testdir testdir1
[root@localhost112 ~]# ll
总用量 8
-rw-r--r--. 1 root root 231 8月 2 15:46 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
drwxr-xr-x. 2 root root 21 8月 2 15:44 testdir
lrwxrwxrwx. 1 root root 7 8月 2 15:54 testdir1 -> testdir

日期类

date [option] [format]

date 查看当前日期

date -s '2019-08-02 16:28:00' 设置系统时间

date -R 查看系统时区

date "+%Y-%m-%d %H:%M:%S" 查看格式化后的日期和时间

date -d "1 days ago" 1天前的日期

date -d "next day" 1天后的日期

date -d "next monday" 下个星期一的日期

[root@localhost112 ~]# date
2019年 08月 02日 星期五 16:27:06 CST
[root@localhost112 ~]# date -R
Fri, 02 Aug 2019 16:27:10 +0800
[root@localhost112 ~]# date "+%Y-%m-%d %H:%M:%S"
2019-08-02 16:27:37
[root@localhost112 ~]# date -d "2 days ago"
2019年 07月 31日 星期三 16:27:51 CST
[root@localhost112 ~]# date -d "next day"
2019年 08月 03日 星期六 16:28:11 CST
[root@localhost112 ~]# date -d "next monday"
2019年 08月 05日 星期一 00:00:00 CST
cal 查看日历

cal 查看当月日历

cal -3 查看前后三个月

cal 年份 显示某年的全年日历

[root@localhost112 ~]# cal
八月 2019
日 一 二 三 四 五 六
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@localhost112 ~]# cal -3
七月 2019 八月 2019 九月 2019
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
28 29 30 31 25 26 27 28 29 30 31 29 30 [root@localhost112 ~]# cal 2019
2019 一月 二月 三月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 1 2 1 2
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30
31
四月 五月 六月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
七月 八月 九月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
28 29 30 31 25 26 27 28 29 30 31 29 30 十月 十一月 十二月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 5 1 2 1 2 3 4 5 6 7
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31

用户管理命令

useradd 添加用户

useradd 用户名 例如:useradd test

userdel 删除用户

userdel -r 用户名 例如 : userdel -r test

passwd 给用户设置密码

passwd 用户名 例如 : passwd test

usermod 修改用户

usermod -g root test 将test加入到root组

id 查看用户是否存在

id 用户名 例如:id test

whoami 查看当前登录用户

whoami

su 切换用户

su 用户名 例如:su test

exit 退出当前用户

exit

/etc/passwd 查看有哪些用户

cat /etc/passwd

[root@localhost112 ~]# id test
uid=1001(test) gid=1001(test) 组=1001(test)
[root@localhost112 ~]# userdel -r test
[root@localhost112 ~]# id test
id: test: no such user
[root@localhost112 ~]# 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
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:997:995:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
ssrs:x:1000:1000:ssrs:/home/ssrs:/bin/bash
[root@localhost112 ~]# useradd testuser
[root@localhost112 ~]# passwd testuser
更改用户 testuser 的密码 。
新的 密码:
无效的密码: 密码包含用户名在某些地方
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码包含用户名在某些地方
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost112 ~]# su testuser
[testuser@localhost112 root]$ ll
ls: 无法打开目录.: 权限不够
[testuser@localhost112 root]$ exit
exit
[root@localhost112 ~]# id testuser
uid=1001(testuser) gid=1001(testuser) 组=1001(testuser)
[root@localhost112 ~]# whoami
root
[root@localhost112 ~]# who am i
root pts/0 2019-07-31 02:22 (192.168.1.1)
[root@localhost112 ~]# usermod -g root testuser
[root@localhost112 ~]# id testuser
uid=1001(testuser) gid=0(root) 组=0(root)

用户组管理命令

groupadd 增加组

groupadd 组名

groupdel 删除组

groupdel 组名

groupmod 修改组

group -n 新组名 旧组名

/etc/group 查看创建了那些组

cat /etc/group

[root@localhost112 ~]# groupadd test
[root@localhost112 ~]# groupmod -n test1 test
[root@localhost112 ~]# cat /etc/group
root:x:0:
...
postdrop:x:90:
postfix:x:89:
sshd:x:74:
ssrs:x:1000:ssrs
testuser:x:1001:
test1:x:1002:
[root@localhost112 ~]# groupdel testuser
[root@localhost112 ~]# cat /etc/group
...
dip:x:40:
postdrop:x:90:
postfix:x:89:
sshd:x:74:
ssrs:x:1000:ssrs
test1:x:1002:

文件权限类

文件属性

Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限。为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定。

在Linux中我们可以使用ll或者ls –l命令来显示一个文件的属性以及文件所属的用户和组。

1 2 3 4 5 6 7 8 9 10

1)从左到右的10个字符表示:

如果没有权限,就会出现减号[ - ]而已。从左至右用0-9这些数字来表示:

(1)0首位表示类型

在Linux中第一个字符代表这个文件是目录、文件或链接文件等等

- 代表文件

d 代表目录

c 字符流,装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)

s socket

p 管道

l 链接文档(link file);

b 设备文件,装置文件里面的可供储存的接口设备(可随机存取装置)

(2)第1-3位确定属主(该文件的所有者)拥有该文件的权限。---User

(3)第4-6位确定属组(所有者的同组用户)拥有该文件的权限,---Group

(4)第7-9位 ---Other用户

文件类型 属主权限 属组权限 其他用户权限
- 1 2 3 4 5 6 7 8 9
d R(4) w(2) x(1) R - x R - x
目录文件 读 写 执行 读 写 执行 读 写 执行
chmod 改变权限

基本语法

​ chmod [{ugo}{+-=}{rwx}] [文件或目录] [mode=421 ] [文件或目录]

功能描述

改变文件或者目录权限

文件: r-查看;w-修改;x-执行文件

目录: r-列出目录内容;w-在目录中创建和删除;x-进入目录

删除一个文件的前提条件: 该文件所在的目录有写权限,你才能删除该文件

[root@localhost112 ~]# ll
总用量 8
-r--rw-rw-. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod g+rwx aaa
[root@localhost112 ~]# ll
总用量 8
-r--rwxrw-. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod u+rwx aaa
[root@localhost112 ~]# ll
总用量 8
-rwxrwxrw-. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod o= aaa
[root@localhost112 ~]# ll
总用量 8
-rwxrwx---. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod u+rw aaa
[root@localhost112 ~]# ll
总用量 8
-rwxrwx---. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod u+rw- aaa
[root@localhost112 ~]# ll
总用量 8
-rwxrwx---. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data
[root@localhost112 ~]# chmod u= aaa
[root@localhost112 ~]# ll
总用量 8
----rwx---. 1 root root 313 8月 2 16:12 aaa
-rw-------. 1 root root 1436 8月 1 07:16 anaconda-ks.cfg
drwxr-xr-x. 2 root root 39 8月 1 07:16 openscap_data

【Linux】常用基础命令的更多相关文章

  1. Linux常用基础命令整理:关机命令、查看目录下文件命令等

    Linux常用基础命令整理:关机命令.查看目录下文件命令等 整理了一些Linux常用基础命令,欢迎指正. 首先记住四个热键,学会这四个键,收益一辈子. Tab按键---命令补齐功能Ctrl+c按键-- ...

  2. Linux常用基础命令(二)

    Linux常用基础命令 一.-ls--列表显示目录内容 二.-alias--设置别名 三.-du--统计目录及文件空间占用情况 四.-mkdir--创建新目录 五.-touch--创建空文件 六.-l ...

  3. 前后端同学,必会的Linux常用基础命令

    无论是前端还是后端同学,一些常用的linux命令还是必须要掌握的.发布版本.查看日志等等都会用到.以下是我简单的总结了一些简单又常用的命令,欢迎大家补充.希望能帮助到大家 本文首发于公众号 程序员共成 ...

  4. Linux常用基础命令

    一.系统目录结构 约定俗成:   bin (binaries)存放二进制可执行文件   sbin (super user binaries)存放二进制可执行文件,只有root才能访问   etc (e ...

  5. linux学习9 运维基本功-Linux常用基础命令实战应用

    一.文件系统知识回顾 1.Linux文件系统: a.文件名称严格区分字符大小写 b.文件可以使用除/以外任意字符 c.文件名长度不能超过255个字符 d.以.开头的文件为隐藏文件: . :当前目录 . ...

  6. linux常用基础命令(一)

    Rz命令 rz命令本地上传文件到服务器: rz在弹出的框中选择文件,上传文件 sz命令 sz命令发送文件到本地: Sz文件名 例:将文件file1 Sz file1 Tomcat启动/关闭命令 比如t ...

  7. Linux常用基础命令一

    一.目录操作 进入路径 cd [目录地址] 切换回主目录 cd 返回上一个路径 cd - 打印当前路径 pwd 列出目录下文件 ls ---查看只包含非隐藏文件 ls -a -----查看目录下所有文 ...

  8. Linux常用基础命令三

    一.ln 软链接 软链接也称为符号链接,类似于 windows 里的快捷方式,有自己的数据块,主要存放 了链接其他文件的路径. 在查看文件目录中,软连接是以'l'开头 创建软链接 ln -s [原文件 ...

  9. 【第四课】Linux的基础命令使用

    目录 一.passwd重置密码 二.单用户模式 三.救援模式 四.设置SElinux 五.Linux的常用基础命令详解 5.1.mkdir命令 5.2.ls命令 5.3.cd命令 5.4.chmod命 ...

  10. Linux的基础命令大全

    linux的基础命令大全 1.shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口(命令解释器) ls -al /bin/sh   ls -al /bin/bash 查看这些shell的 ...

随机推荐

  1. Trie树(代码),后缀树(代码)

    Trie树系列 Trie字典树 压缩的Trie 后缀树Suffix tree 后缀树--ukkonen算法 Trie是通过对字符串进行预先处理,达到加快搜索速度的算法.即把文本中的字符串转换为树结构, ...

  2. 为什么程序员一定要会用Google和Stack Overflow?

    为什么程序员一定要会用Google和Stack Overflow? https://blog.csdn.net/u012207345/article/details/81139665 StackOve ...

  3. Android Gradle 常用配置

    Gradle:multiDexEnabled之DEX 方法超过64K限制和gradle编译OOM问题解决DEX 方法超过64K限制 UNEXPECTED TOP-LEVEL EXCEPTION: co ...

  4. nginx 缓存,大文件分片请求方法

    实现的途径:expire cache-control 更新缓存的机制 如何校验本地缓存是否过期 expires cache-control(max-age)如果超期,说明失效 然后进行etag是否过期 ...

  5. guava的一些用法

    package guavaTest; import com.google.common.base.CharMatcher; import com.google.common.base.Joiner; ...

  6. 洛谷-P2292-L语言(字典树)

    链接: https://www.luogu.org/problem/P2292 题意: 标点符号的出现晚于文字的出现,所以以前的语言都是没有标点的.现在你要处理的就是一段没有标点的文章. 一段文章T是 ...

  7. HDU 6040 - Hints of sd0061 | 2017 Multi-University Training Contest 1

    /* HDU 6040 - Hints of sd0061 [ 第k小数查询,剪枝 ] 题意: 给出随机数列 a[N] (N < 1e7) 询问 b[M] (M < 100) ,对于每个询 ...

  8. 【Maven】-maven打包跳过javadoc

    有时候由于代码中注释错误(比如方法参数)或者maven javadoc插件版本有问题,导致打包报错,而我们着急打包验证问题,没有时间一一修改错误,这时候可以先跳过生成javadoc,继续下一步工作. ...

  9. Linux 目录共享

    ## 安装 nfs 和 rpc yum install -y nfs-utils rpcbind ## ubuntu 安装 nfs 和 rpc ## apt-get install nfs-kerne ...

  10. jquery mouseenter()方法 语法

    jquery mouseenter()方法 语法 作用:当鼠标指针穿过元素时,会发生 mouseenter 事件.该事件大多数时候会与 mouseleave 事件一起使用.mouseenter() 方 ...