rm、环境变量、cp、mv、文档查看、chmod、chown、umask

rm

删除文件

rm 文件全名 #可以按tab辅助输入;
rm -f 文件全名 #不询问直接删除;

删除目录

rm -r #目录全名 #只用rm不能删除;
rm -rf #不询问直接删除;
rm -rfv #显示删除过程;

*通配符

rm testdir/*.txt #删除所有.txt文件;

history命令
可以查看使用过的命令

!rm #加叹号表示运行使用过的上一条rm命令,其他命令也可以加叹号

环境变量

环境变量是系统快速搜索的地方,可运行程序放在里边,当使用命令时,系统会从这些路径里搜索你输入的命令,而不用输入完整路径

[root@tanyvlinux ~]# which ls		#which也只能查找环境变量里的可运行程序;
alias ls='ls --color=auto'
	/bin/ls
[root@tanyvlinux ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/local/src/node-v4.2.3-linux-x86/bin:/root/bin:/usr/local/mysql/bin:/usr/local/php/bin:/root/bin	#以:分格;

ls放置在/bin里,/bin是环境变量,所以打命令只需要打ls。

临时添加环境变量,只在当前shell使用,重启无效

PATH=$PATH:/tmp #将/tmp添加到环境变量里;
取消环境变量,重新赋值
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/local/src/node-v4.2.3-linux-x86/bin:/root/bin:/usr/local/mysql/bin:/usr/local/php/bin:/root/bin

永久添加环境变量,将环境变量写在/etc/profile里

vi /etc/profile
添加语句 PATH=$PATH:/tmp

取消环境变量
删除语句 PATH=$PATH:/tmp

cp (复制文件和更改名字)

源是文件:
目标是不存在的名字,复制过去,并修改了名字(这个情况包括在原目录里,或其他目录里)

目标跟目录里的某个文件的名字相同,提示是否覆盖

[root@tanyvlinux ~]# ls
1.cap            bbs.conf   Desktop             mysqld            vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  wordpress-3.9-zh_CN.zip  模板  文档
1.txt            chapter11  gallery             NetBeansProjects  wget-1.14-18.el7_6.1.x86_64.rpm          zrlog.war                视频  下载
anaconda-ks.cfg  chapter4   hs_err_pid9271.log  url2png           wordpress                                公共                     图片  音乐
[root@tanyvlinux ~]# cp 1.txt 2.txt
[root@tanyvlinux ~]# ls
1.cap  anaconda-ks.cfg  chapter4  hs_err_pid9271.log  url2png                                  wordpress                公共  图片  音乐
1.txt  bbs.conf         Desktop   mysqld              vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  wordpress-3.9-zh_CN.zip  模板  文档
2.txt  chapter11        gallery   NetBeansProjects    wget-1.14-18.el7_6.1.x86_64.rpm          zrlog.war                视频  下载
[root@tanyvlinux ~]# cp 1.txt 2.txt
cp:是否覆盖"2.txt"? n

源是目录:
目标是不存在的目录,复制过去,并修改了名字(这个情况包括在原目录里,或其他目录里)

目标目录存在,源目录会复制到目标目录里,目录里没有跟源目录一样名字的文件或目录,目录成功复制;目录里有跟源目录一样名字的目录,提示是否覆盖。

[root@tanyvlinux ~]# mkdir dir1
[root@tanyvlinux ~]# touch dir1/file1
[root@tanyvlinux ~]# cp -r dir1 dir2		#加-r才能复制文件夹,原来dir2不存在,复制并改名成为dir2;
[root@tanyvlinux ~]# ll dir2
总用量 0
-rw-r--r-- 1 root root 0 8月  29 03:07 file1
[root@tanyvlinux ~]# cp -r dir1 dir2		#dir2存在,复制dir1到dir2里
[root@tanyvlinux ~]# ls dir2 -l
总用量 0
drwxr-xr-x 2 root root 19 8月  29 03:09 dir1
-rw-r--r-- 1 root root  0 8月  29 03:07 file1
[root@tanyvlinux ~]# touch dir1/file2		#增加文件,便于观察;
[root@tanyvlinux ~]# ls dir1
file1  file2
[root@tanyvlinux ~]# cp -r dir1 dir2			#再次复制,dir2里已经有目录dir1,提示是否覆盖;
cp:是否覆盖"dir2/dir1/file1"? y
[root@tanyvlinux ~]# ls /dir2/dir1 -l
ls: 无法访问/dir2/dir1: 没有那个文件或目录
[root@tanyvlinux ~]# ls dir2/dir1 -l			#dir1被覆盖,有file1、file2两个文件;
总用量 0
-rw-r--r-- 1 root root 0 8月  29 03:13 file1
-rw-r--r-- 1 root root 0 8月  29 03:13 file2

!$

cp -r dir1 dir2
ls !$ #即ls dir2,!$重复上一条命令的最后一个参数;

mv(移动或更改名字)

源是文件:

目标是不存在的名字,文件就修改了名字(这个情况包括在原目录里,或其他目录里)

目标跟目录里的某个文件的名字相同,提示是否覆盖
使用/bin/mv命令操作直接覆盖,因为mv是别名=mv -i(覆盖前询问)

[root@tanyvlinux ~]# ls
1.cap  anaconda-ks.cfg  Desktop             NetBeansProjects  url2png                                  wordpress-3.9-zh_CN.zip  视频  音乐
1.txt  bbs.conf         gallery             testdir           vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  zrlog.war                图片
2      chapter11        hs_err_pid9271.log  testdir2          wget-1.14-18.el7_6.1.x86_64.rpm          公共                     文档
222    chapter4         mysqld              testfile          wordpress                                模板                     下载
[root@tanyvlinux ~]# mv 222 333		#修改了名字;
[root@tanyvlinux ~]# ls
1.cap  anaconda-ks.cfg  Desktop             NetBeansProjects  url2png                                  wordpress-3.9-zh_CN.zip  视频  音乐
1.txt  bbs.conf         gallery             testdir           vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  zrlog.war                图片
2      chapter11        hs_err_pid9271.log  testdir2          wget-1.14-18.el7_6.1.x86_64.rpm          公共                     文档
333    chapter4         mysqld              testfile          wordpress                                模板                     下载
[root@tanyvlinux ~]# mv 333 testdir/444		#移动和修改名字;
[root@tanyvlinux ~]# ls testdir
444
[root@tanyvlinux ~]# touch 444
[root@tanyvlinux ~]# mv 444 testdir/444		#移动,同名提示是否覆盖;
mv:是否覆盖"testdir/444"? y

源是目录:
目标是不存在的目录,目录就修改了名字(这个情况包括在原目录里,或其他目录里)

目标跟目录里的某个目录的名字相同,提示是否覆盖,如果有一个文件跟目标名字一样,操作失败

[root@tanyvlinux ~]# ls
1.cap  anaconda-ks.cfg  chapter4  hs_err_pid9271.log  testdir   url2png                                  wordpress                公共  图片  音乐
1.txt  bbs.conf         Desktop   mysqld              testdir2  vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  wordpress-3.9-zh_CN.zip  模板  文档
2      chapter11        gallery   NetBeansProjects    testfile  wget-1.14-18.el7_6.1.x86_64.rpm          zrlog.war                视频  下载
[root@tanyvlinux ~]# mv testdir testdir3		#修改了目录名字;
[root@tanyvlinux ~]# ls
1.cap  anaconda-ks.cfg  chapter4  hs_err_pid9271.log  testdir2  url2png                                  wordpress                公共  图片  音乐
1.txt  bbs.conf         Desktop   mysqld              testdir3  vim-enhanced-7.4.160-6.el7_6.x86_64.rpm  wordpress-3.9-zh_CN.zip  模板  文档
2      chapter11        gallery   NetBeansProjects    testfile  wget-1.14-18.el7_6.1.x86_64.rpm          zrlog.war                视频  下载
[root@tanyvlinux ~]# mv testdir3 testdir2/testdir3	#移动了目录;
[root@tanyvlinux ~]# ls testdir2
testdir3
[root@tanyvlinux ~]# mkdir testdir3						
[root@tanyvlinux ~]# mv testdir3 testdir2/testdir3	#移动目录,有目录重名,提示是否覆盖;
mv:是否覆盖"testdir2/testdir3/testdir3"? y
[root@tanyvlinux ~]# touch testdir3
[root@tanyvlinux ~]# mv testdir2/testdir3 testdir3
mv:是否覆盖"testdir3"? y
mv: 无法以目录"testdir2/testdir3" 来覆盖非目录"testdir3"		#移动目录,有文件重名,失败;

cat more less head tail

cat /etc/passwd #读一个文件内容在屏幕上;
cat -A /etc/passwd #显示全部字符;
cat -n /etc/passwd #显示行数;
tac /etc/passwd #从后向前显示一个文件内容在屏幕上;
cat /etc/passwd >> 1.txt #把文件内容增加在文件1.txt的后面;

wc #行数,字数字算;

more /etc/passwd #一屏一屏的显示内容,按空格向下翻,control + b向上翻;

less /etc/passwd #可以一屏或逐行显示内容,空格,control + f向下翻,control + b向上翻;方向键可逐行查阅;可用/*由上到下查找内容,*为查找的内容,按n向下找到下一个查找到的内容,shift + n向上找查找的内容;?*由下向上查找内容,g可以去到文件的首行,shift + g可以去到文件的最后一行。

head /etc/passwd #显示文件的前10行;
head -n /etc/passwd #显示文件的前n行;

tail /etc/passwd #显示文件的最后10行;
tail -n /etc/passwd #显示文件的最后n行;
tail -f /var/log/nginx/access.log #实时显示文件的更新;

chmod

查看文件的权限

ll 1.txt
-rw-r–r--. 1 user3 user3 0 8月 6 15:17 1.txt

第二到十位为权限的具体情况,第二位到第四位rm-为文件所有者的权限,第五到七位r–为所属组(组内用户)的权限,第八到十位r–为其他用户的权限

所有者权限rw-,r代表可读,w代表可写,-代表不可运行,可运行为x,每一位都只有两种可能性,所以可以二进制表示为110,换算成10进制为6,即所有者权限为6可读可写(user3),同理所属组权限和其他用户权限都为4可读(组内用户和其他用户)。

chmod可以修改文件的权限,赋予用户你想要的权限。

[root@tanyvlinux ~]# chmod 666 1.txt
[root@tanyvlinux ~]# ll 1.txt
-rw-rw-rw-. 1 user3 user3 0 8月   6 15:17 1.txt

修改了权限为666,所有人对这个文件都可读可写

还有另我两种定义方式

[root@tanyvlinux ~]# chmod u=rwx,g=r,o=- 1.txt		#u代表所有者,g代表所属级,o代表其他用户;
[root@tanyvlinux ~]# ll 1.txt
-rwxr-----. 1 user3 user3 0 8月   6 15:17 1.txt
[root@tanyvlinux ~]# chmod o+r 1.txt							#为o加上读权限,可以继续定义,用逗号分隔;
[root@tanyvlinux ~]# ll 1.txt
-rwxr--r--. 1 user3 user3 0 8月   6 15:17 1.txt
[root@tanyvlinux ~]# chmod a-x 1.txt							#a包括u,g,o,减去运行权限;
[root@tanyvlinux ~]# ll 1.txt
-rw-r--r--. 1 user3 user3 0 8月   6 15:17 1.txt

chmod -R 755 dir1 #把该目录和目录下文件和目录都修成755权限;

[root@tanyvlinux ~]# getenforce 
Disabled																	#selinux关闭后创建文件;
[root@tanyvlinux ~]# touch 222.txt
[root@tanyvlinux ~]# ll 222.txt
-rw-r--r-- 1 root root 0 8月  29 10:35 222.txt		#第11位没有.这个文件不受selinux控制;
[root@tanyvlinux ~]# ll 1.txt
-rwxr-xr--. 1 user3 user3 0 8月   6 15:17 1.txt		#第11位.这个文件受selinux控制;

chown

chown user1 1.txt #修改文件所有者;
chown :user2 1.txt #修改文件所属组;
chown user2:user1 1.txt #修改文件所有人和所属组;
chgrp user2 1.txt #修改文件所属组;
chown
chgrp
chown -R user1:user2 dir1 #修改目录和目录里的文件和目录的所有者和所属组;
chown -R

umask

umask可以定义生成文件或目录时的权限,即定义所有者,所属组和其他用户的权限

[user1@tanyvlinux ~]$ umask		#user1普通用户的umask是0002
0002

假设一个文件的最低权限是666(任何人都可读可写,一般不用运行,除非是程序),一个目录的最低权限是777(任何人都可读可写可运行),这个时候创建一个文件,自动形成的权限为666-002(umask)=664(其他用户不能写),创建一个目录,自动形成的权限为777-002=775(其他用户不能写),我觉得这样是一个保护作用,作为普通用户创建的文件,不能让其他普通用户修改,自己和同组的人可读可修改;创建的目录,不能让其他普通用户修改,自已和同组的人可读可写;目录必须是5权限才有意义,4权限不能正常使用,目录的权限为三种选择,0,5,7; 文件的权限也是三种选择,0,4,6。

[root@tanyvlinux ~]# umask
0022

root帐号的umask为022,代表对root创建的文件具有更高的保护性,创建的文件为644,同组的人是只读;创建的目录为755,同组的人是只读和运行(cd和ls),不能修改

umask 003 #可修改umask,但是算权限直接用数字减会不准确,假设是文件rw-rw-rw-减去— --- -wx等于664, -减去x还是-;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值