新建文件
可使用vim或者touch創(chuàng)建新的文件,命令后可以直接是文件名,也可以是包含路徑的文件名,但路徑必須是存在的
[root@linux ~]# touch newfile
[root@linux ~]# ll
總用量 24
drwxr-xr-x. 3 root root 16 4月 19 00:14 aa
[root@linux ~]# mkdir -p aa/bb
[root@linux ~]# touch aa/bb/newfile
[root@linux ~]# cd aa/bb
[root@linux bb]# ll
總用量 0
-rw-r--r--. 1 root root 0 4月 19 00:14 newfile
新建文件夾
使用mkdir創(chuàng)建新的文件夾,使用-p參數(shù)可以自動創(chuàng)建多級文件夾
[root@linux ~]# mkdir -p one/two/three
[root@linux ~]# cd one/two/three
[root@linux three]#
查看文件權(quán)限
使用ll查看文件的詳細信息,ll是ls -l的別名,注:是字母L的小寫而不是1
[root@linux ~]# ll newfile
-rw-r--r--. 1 root root 0 4月 19 00:14 newfile
-rw-r--r--即文件的權(quán)限信息:
1.第1位是文件類型,-表示文件類型為文件,其他還有l表示軟連接,d表示文件夾
2.第234位是文件所有者的權(quán)限,分別對應讀寫執(zhí)行,-表示沒有權(quán)限,這里rw-即表示有讀寫權(quán)限沒有執(zhí)行權(quán)限
3.第567位是文件所屬組的權(quán)限,具體情況與上面類似
4.第8910位是其他人的權(quán)限,具體情況與上面類似
修改文件權(quán)限
方法一:chmod 766
三位數(shù)字分別對應用戶、所屬組和其他的權(quán)限,7是111,即讀、寫、執(zhí)行,6是110,即讀、寫、-
[root@linux ~]# chmod 755 newfile
[root@linux ~]# ll
-rwxr-xr-x. 1 root root 0 4月 19 00:26 newfile
方法二:chmod og+w,u用戶、g組織、o其他、a所有,+/-權(quán)限r(nóng)、w、x
[root@linux ~]# chmod og+w newfile
-rw-rwxrwx. 1 root root 0 4月 19 00:26 newfile
只有文件所有者或者管理員才能修改文件的權(quán)限
修改文件的所有者
只有管理員才能修改文件所有者
使用chown命令修改文件所有者,文件所屬組并不會發(fā)生變化
[tom@linux ~]$ ll
總用量 0
-rw-r--r--. 1 tom bigdata 0 4月 19 00:45 newfile
[root@linux tom]# chown jay newfile
[root@linux tom]# ll
總用量 0
-rw-r--r--. 1 jay bigdata 0 4月 19 00:45 newfile
同時修改所屬用戶和組
[root@linux tom]# ll
總用量 0
-rw-r--r--. 1 tom bigdata 0 4月 19 00:45 newfile
[root@linux tom]# chown jay:test newfile
[root@linux tom]# ll
總用量 0
-rw-r--r--. 1 jay test 0 4月 19 00:45 newfile
加上-R參數(shù)則可遞歸修改目錄下子目錄和文件
[root@linux tom]# chown -P jay:test newfolder