初试linux,cp、rm、mv、file、umask等命令粗略使用方法

ls

--color=never 不要依據檔案特性給予顏色顯示;
--color=always 顯示顏色
--color=auto 讓系統自行依據設定來判斷是否給予顏色
--full-time 以完整時間模式 (包含年、月、日、時、分) 輸出
--time= 輸出 access 時間或改變權限屬性時間 (ctime) 而非內容變更時間 (modification time)

cp的一些常用的命令

-a 相当于-drp
-d 若为链接文件就复制链接而非文件本身
-r 复制文件夹
-i 询问
-u 比较两文件,若要复制的文件比要被覆盖的文件新才会进行复制
-f 强制
-p 把属性一同复制过去

举例

root@DESKTOP-FA1P4IO:~# ls -l --time={atime,ctime} 12.txt      #显示源文件信息日期是八月5号
-rwxrw-rw- 1 sys001 root 84 Aug  5 12:59 12.txt
root@DESKTOP-FA1P4IO:~# cp 12.txt test1/12.txt          # 复制
root@DESKTOP-FA1P4IO:~# ls -l --time={atime,ctime} 12.txt  #源文件的属性修改时间没有变
-rwxrw-rw- 1 sys001 root 84 Aug  5 12:59 12.txt
root@DESKTOP-FA1P4IO:~# ls -l test1/12.txt  # 显示复制过去的文件信息,显示八月21号(复制源文件过来的时间)创建
-rwxrw-rw- 1 root root 84 Aug 21 14:39 test1/12.txt
root@DESKTOP-FA1P4IO:~# cp -p 12.txt test1/12.txt  # 重新复制,采用-p
root@DESKTOP-FA1P4IO:~# ls -l test1/12.txt
-rwxrw-rw- 1 sys001 root 84 Jul 25 01:23 test1/12.txt
root@DESKTOP-FA1P4IO:~# ls -l --time={atime,ctime} test1/12.txt   # 复制过去的文件和源文件信息一致
-rwxrw-rw- 1 sys001 root 84 Aug 21 14:41 test1/12.txt

-p用于文件备份很好用

三个时间

atime 显示文件被执行的时间,如被cat以下,atime就是要更新的
mtime 文件内容被修改的时间
ctime 文件的权限和目录信息改变的时间
ls默认显示的是mtime,可以用--time={atime,ctime}来显示ctime或atime

rm

-f 强制
-i 询问
-r 删除目录

file显示文件属性

which用来寻找可执行文件也就是命令

whereis 搜寻文件

umask 默认属性

在这里插入图片描述
文件默认不能建立未执行文件,必须手工赋予执行权限

实例

root@DESKTOP-FA1P4IO:~# mkdir masks
root@DESKTOP-FA1P4IO:~# touch 122.txt
root@DESKTOP-FA1P4IO:~# ls -l masks 122.txt
-rw-rw-rw- 1 root root   0 Aug 21 15:10 122.txt

masks:
total 0
root@DESKTOP-FA1P4IO:~# ls -l masks
total 0
root@DESKTOP-FA1P4IO:~# ll -d masks
drwxrwxrwx 1 root root 512 Aug 21 15:10 masks/
root@DESKTOP-FA1P4IO:~# ll -d venv
drwxrwxrwx 1 root root 512 Aug 11 19:42 venv/
root@DESKTOP-FA1P4IO:~# umask
0000
root@DESKTOP-FA1P4IO:~# umask 002
root@DESKTOP-FA1P4IO:~# umask
0002
root@DESKTOP-FA1P4IO:~# rm -rf masks 122.txt
root@DESKTOP-FA1P4IO:~# touch 122.txt
root@DESKTOP-FA1P4IO:~# mkdir masks
root@DESKTOP-FA1P4IO:~# ll -d masks 122.txt
-rw-rw-r-- 1 root root   0 Aug 21 15:14 122.txt
drwxrwxr-x 1 root root 512 Aug 21 15:14 masks/
posted @ 2019-08-21 15:18  sogeisetsu  阅读(270)  评论(0编辑  收藏  举报