1.顯示當前工作路徑
pwd-----------顯示當前路徑
pwd -P-------顯示真實的物理路徑
pwd -L-------默認為顯示鏈路路徑
↓首先創建一個軟連接然后分別用兩個參數查看路徑
[root@centos6 app]# ln -s /etc/sysconfig/network-scripts/ link
[root@centos6 app]# cd link1
[root@centos6 link]# pwd
/app/link
[root@centos6 link]# pwd -P
/etc/sysconfig/network-scripts
2. 目錄名與基名
- 基名名為路徑中最后一個文件夾的名字
- 目錄除基名外都屬于目錄名
[root@centos6 app]# dirname /etc/sysconfig/network-scripts/
/etc/sysconfig
[root@centos6 app]# basename /etc/sysconfig/network-scripts/
network-scripts
3. 路徑與路徑相關的變量
[root@centos6 li]# echo $PWD #當前路徑
/home/li
[root@centos6 li]# echo $OLDPWD #上一次目錄的路徑
/root
[root@centos6 li]#
4. LS命令練習
[root@centos6 li]# ls -R /etc/sysconfig/
[root@centos6 app]# ls -S
[root@centos6 app]# ls -d
[root@centos6 app]# ls -t
[root@centos6 app]# ls -X
[root@centos6 app]# ls -u
[root@centos6 app]# ls -U
[root@centos6 app]# ls -R
[root@centos6 app]# ls -1
1.pdf
1.txt
2.pdf
2.txt
當使用文件通配符時,ls命令默認會輸出目錄及子文件子目錄
5. 文件與文件夾的狀態
- atime:訪問時間,讀取文件內容
- mtime: 修改時間, 改變文件內容(數據)
- ctime: 改變時間, 元數據發生改變(屬性)
atime訪問時間的更新并不是實時的。
服務器為了避免頻繁的更新atime而造成服務器的壓力,所以從CentOS6之后atime不是實時更新。
1.在motime大于atime時更新
2.在atime大于一天未更新時更新
通過ls命令來查看文件的時間狀態
[root@centos6 app]# ll test --time=atime
-rw-r--r--. 1 root root 0 Jul 19 21:18 test
[root@centos6 app]# ll test --time=ctime
-rw-r--r--. 1 root root 0 Jul 19 21:18 test
[root@centos6 app]# stat
stat: missing operand
Try `stat --help' for more information.
[root@centos6 app]# stat .
File: `.'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 2 Links: 12
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-07-19 19:40:34.696577732 +0800
Modify: 2017-07-19 19:40:34.077573736 +0800
Change: 2017-07-19 19:40:34.077573736 +0800
6. 創建文件和刷新時間
- 刷新文件的atime、mtime、ctime
[root@centos6 down]# touch 1.txt
- 僅刷新文件的mtime和ctime
[root@centos6 down]# touch -m 1.txt
- 僅刷新文件的atime和ctime
[root@centos6 down]# touch -a 1.txt
- 指定文件的atime與mtime
[root@centos6 down]# touch -t "201810101020" 1.txt
時間格式[[CC]YY]MMDDhhmm[.ss]
- 如果文件不存在則不創建
[root@centos6 down]# touch -c test.txt
7. CP命令
-
CP為復制命令
- 直接復制與覆蓋前詢問
[root@centos6 app]# cp wnejian.sh ./back/
[root@centos6 app]# cp -i wnejian.sh ./back/
cp: overwrite `./back/wnejian.sh'? y
- 遞歸復制文件的內容與文件夾
[root@centos6 app]# cp -r ../app ./back/
- cp歸檔
[root@centos6 app]# cp a file ./back/
- CP命令對于連接文件,默認復制真實路徑的物理文件
[root@centos6 app]# ls -la /etc/grub.conf
lrwxrwxrwx. 1 root root 22 Jul 14 11:18 /etc/grub.conf -> ../boot/grub/grub.conf
[root@centos6 back]# cp /etc/grub.conf .
[root@centos6 back]# ls -al grub.conf
-rw-------. 1 root root 771 Jul 20 14:04 grub.conf
[root@centos6 back]# ls -al /boot/grub/grub.conf
-rw-------. 1 root root 771 Jul 14 11:18 /boot/grub/grub.conf
[root@centos6 back]#
- 復制鏈接文件而不復制連接本身
[root@centos6 back]# cp -P /etc/grub.conf .
- 只復制連接名,不復制原文件
[root@centos6 back]# cp -d /etc/grub.conf .
- 復制文件的保留mode(權限),ownership(主屬群組),timestamp(時間戳)屬性
[root@centos6 back]# cp -P /etc/grub.conf .
- 顯示出復制的過程
[root@centos6 back]# cp -av /etc/sysconfig/ ./wenjian/
`/etc/sysconfig/' -> `./wenjian/sysconfig'
`/etc/sysconfig/sysstat.ioconf' -> `./wenjian/sysconfig/sysstat.ioconf'
......
8.移動和剪切
mv -i
mv -f
9.刪除
rm -i 交互式
rm -f 強制
rm -r 遞歸
rm --no-preserve-root 刪除根
10. 目錄操作
- 顯示目錄樹
tree -d 只顯示目錄
tree -L leve 顯示指定層級數目
tree -P
- 創建目錄
mkdir -p 遞歸創建
mkdir -v 顯示詳細信息
mkdir -m 制定權限
- 刪除目錄
rmdir -p 刪除遞歸
rmdir -v 顯示詳細信息
inode節點表
[root@centos6 app]# ls -il ./
. 軟連接與硬鏈接
[root@centos6 app]# ll /app/link1/
total 228
-rw-r--r--. 1 root root 231 Jul 19 10:55 ifcfg-eth0
-rw-r--r--. 1 root root 164 Jul 19 10:58 ifcfg-eth1
-rw-r--r--. 1 root root 254 Jan 18 20:10 ifcfg-lo
........
[root@centos6 app]# ll /app/link1
lrwxrwxrwx. 1 root root 31 Jul 19 20:13 link1 -> /etc/sysconfig/network-scripts/
readlink 查看鏈接文件