内容提要,今天将要学习的有chmod,touch,mkdir,echo,cp,mv,rm,history,cat等shell命令,下面我们开始。
一、shell命令:chmod1.1字母方式
使用格式:chmod [u/g/o/a][+/-][r/w/x] filename
选项解释:第一对中括号中的u表示用户自己,g表示用户所在的组,o表示其它人,a表示所有,第二对中括号中的+或者-表示增加或者减少权限,第三对中括号中的r/w/x对应的是读写执行。最后跟上filename
使用举例:
root@debian:~/test# ls -l
总用量 0
-rwxr-xr-x 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test# chmod u-x a.sh
root@debian:~/test# ls -l
总用量 0
-rw-r-xr-x 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test# chmod a+w a.sh
root@debian:~/test# ls -l
总用量 0
-rw-rwxrwx 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test# chmod a-w a.sh
root@debian:~/test# ls -l
总用量 0
-r--r-xr-x 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test#
1.2数字方式
使用格式:chmod 741 filename
选项解释:第一个7表示读(4)+写(2)+执行(1)=7表示用户有所有权限unix命令整理,第二个4表示用户只读(4),第三个1表示其它人有执行权限(1),数字的含义上节讲过。
使用举例:
root@debian:~/test# ls -l
总用量 0
-r--r-xr-x 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test# chmod 741 a.sh
root@debian:~/test# ls -l
总用量 0
-rwxr----x 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test# chmod 644 a.sh
root@debian:~/test# ls -l
总用量 0
-rw-r--r-- 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
root@debian:~/test#
二、shell命令:touch
使用举例:
root@debian:~/test# ls
a.sh b.txt
root@debian:~/test# touch c.txt d.log e.abc
root@debian:~/test# ls -l
总用量 0
-rw-r--r-- 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 c.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 d.log
-rw-r--r-- 1 root root 0 11月 15 23:05 e.abc
root@debian:~/test#
三、shell命令:mkdir
使用举例:
root@debian:~/test# mkdir -p a/b/c
root@debian:~/test# ls -l
总用量 4
drwxr-xr-x 3 root root 4096 11月 15 23:13 a
-rw-r--r-- 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 c.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 d.log
-rw-r--r-- 1 root root 0 11月 15 23:05 e.abc
root@debian:~/test# mkdir b
root@debian:~/test# ls -l
总用量 8
drwxr-xr-x 3 root root 4096 11月 15 23:13 a
-rw-r--r-- 1 root root 0 11月 14 23:37 a.sh
drwxr-xr-x 2 root root 4096 11月 15 23:13 b
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 c.txt
-rw-r--r-- 1 root root 0 11月 15 23:05 d.log
-rw-r--r-- 1 root root 0 11月 15 23:05 e.abc
root@debian:~/test# ls a
a/ a.sh
root@debian:~/test# ls a/b/c/
root@debian:~/test# ls -a a/b/c/
. ..
root@debian:~/test#
四、shell命令:echo
使用举例:
root@debian:~/test# echo "hello, everyone"
hello, everyone
root@debian:~/test# echo "hello, everyone" > c.txt
root@debian:~/test# cat ./c.txt
hello, everyone
root@debian:~/test#
说明:第三行的 > c.txt是指把前面命令输出的结果重定向到文件中
五、shell命令:cp
使用举例:
oot@debian:~/test# ls
a a.sh b b.txt c.txt d.log e.abc
root@debian:~/test# cp c.txt f.txt
root@debian:~/test# ls
a a.sh b b.txt c.txt d.log e.abc f.txt
root@debian:~/test# cp -r a c
root@debian:~/test# ls
a a.sh b b.txt c c.txt d.log e.abc f.txt
root@debian:~/test#
六、shell命令:mv
使用举例:
root@debian:~/test# ls
a a.sh b b.txt c c.txt d.log e.abc f.txt
root@debian:~/test# mv a d
root@debian:~/test# ls
a.sh b b.txt c c.txt d d.log e.abc f.txt
root@debian:~/test# mv c.txt g.txt
root@debian:~/test# ls
a.sh b b.txt c d d.log e.abc f.txt g.txt
root@debian:~/test#
七、shell命令:rm
使用举例:
root@debian:~/test# ls
a.sh b b.txt c d d.log e.abc f.txt g.txt
root@debian:~/test# rm -r b
root@debian:~/test# ls
a.sh b.txt c d d.log e.abc f.txt g.txt
root@debian:~/test# rm f.txt
root@debian:~/test# ls
a.sh b.txt c d d.log e.abc g.txt
root@debian:~/test#
八、shell命令:history
使用举例:
root@debian:~/test# history
78 ls
root@debian:~/test# !78
ls
a.sh b.txt c d d.log e.abc g.txt
root@debian:~/test# !!
ls
a.sh b.txt c d d.log e.abc g.txt
root@debian:~/test#
说明:
!带上数字表示再次执行这个编号的命令记录。
!!表示重新执行上次命令,也就是最近那一次的命令。
九、shell命令:cat
使用举例:
oot@debian:~/test# ls -l
总用量 12
-rw-r--r-- 1 root root 0 11月 14 23:37 a.sh
-rw-r--r-- 1 root root 0 11月 14 23:37 b.txt
drwxr-xr-x 3 root root 4096 11月 15 23:20 c
drwxr-xr-x 3 root root 4096 11月 15 23:13 d
-rw-r--r-- 1 root root 0 11月 15 23:05 d.log
-rw-r--r-- 1 root root 0 11月 15 23:05 e.abc
-rw-r--r-- 1 root root 16 11月 15 23:16 g.txt
root@debian:~/test# cat g.txt
hello, everyone
root@debian:~/test#
好了今天就分享到这里,主要介绍一些常用命令,未来预计还有两次分享shell编程就完结了。最后一次分享会写一个简单的shell脚本。感谢大家的支持,点赞关注不迷路哦。
(编辑:91站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|