小結:
在平時使用計算機時要找到需要的文件就必須知道文件的位置,而表示文件的位置的方式就是路徑
在Linux中 絕對路徑是從/開始的,比如/usr,/etc/passwd
如果一個路徑是從/開始的就一定是絕對路徑
[root@administrator ~]# pwd/root[root@administrator ~]# cd /etc/sysconfig/network-scripts/[root@administrator network-scripts]# pwd/etc/sysconfig/network-scripts
相對路徑是以.或者..開始的 .表示用戶當前操作所處的位置 即當前目錄 ..表示上級目錄
[root@administrator ~]# cd /etc/sysconfig/network-scripts/[root@administrator network-scripts]# pwd/etc/sysconfig/network-scripts[root@administrator network-scripts]# cd .[root@administrator network-scripts]# pwd/etc/sysconfig/network-scripts[root@administrator network-scripts]# cd ..[root@administrator sysconfig]# pwd/etc/sysconfig[root@administrator sysconfig]# cd ./[root@administrator sysconfig]# pwd/etc/sysconfig[root@administrator sysconfig]# cd ./..[root@administrator etc]# pwd/etc[root@administrator etc]# cd ..[root@administrator /]# pwd/
介紹文件和文件夾的相關操作
命令:touch 作用:創建空文件 語法:touch 文件名
[root@administrator ~]# touch example.txt[root@administrator ~]# lsanaconda-ks.cfg Documents example.txt Music Public VideosDesktop Downloads initial-setup-ks.cfg Pictures Templates
命令:mkdir 作用:創建目錄 語法:mkdir 目錄名
[root@administrator ~]# mkdir example[root@administrator ~]# lsanaconda-ks.cfg Documents example Music Public VideosDesktop Downloads initial-setup-ks.cfg Pictures Templates
-p 創建多級目錄
[root@administrator ~]# mkdir -p example/test[root@administrator ~]# lsanaconda-ks.cfg Documents example Music Public VideosDesktop Downloads initial-setup-ks.cfg Pictures Templates[root@administrator ~]# ll example/total 0drwxr-xr-x 2 root root 6 Aug 8 11:09 test[root@administrator ~]# cd example/[root@administrator example]# lstest
命令:cat 作用:查看文件內容 語法:cat 文件名
組合使用 場景:只查看文件的第2行內容 先查看文件initial-setup-ks.cfg前兩行內容
[root@administrator ~]# head -2 initial-setup-ks.cfg#version=DEVEL# X Window System configuration information
使用管道將上述操作的結果作為tail命令的輸入
[root@administrator ~]# head -2 initial-setup-ks.cfg | tail -1# X Window System configuration information
命令:cp 作用:復制文件 語法:cp [參數] 源文件 目標文件 參數:-r 連同子目錄和文件一起復制
[root@administrator ~]# cp initial-setup-ks.cfg test.cfg[root@administrator ~]# lsanaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates VideosDesktop Downloads Music Public test.cfg[root@administrator ~]# mkdir -p example/test/[root@administrator ~]# touch example/test/test.txt[root@administrator ~]# cp -r example/ cptest[root@administrator ~]# lsanaconda-ks.cfg Documents initial-setup-ks.cfg Public Videoscptest Downloads Music TemplatesDesktop example Pictures test.cfg[root@administrator ~]# ls cptest/test
命令:mv 作用:重命名目標文件或文件夾 語法:mv 源文件或文件夾 目標文件或文件夾
[root@administrator ~]# lsanaconda-ks.cfg Documents initial-setup-ks.cfg Public Videoscptest Downloads Music TemplatesDesktop example Pictures test.cfg[root@administrator ~]# mv test.cfg example.cfg[root@administrator ~]# lsanaconda-ks.cfg Documents example.cfg Pictures Videoscptest Downloads initial-setup-ks.cfg PublicDesktop example Music Templates
命令:rm 作用:刪除文件或目錄 語法:rm [參數] 文件或目錄 參數:-r 遞歸刪除(可以刪除目錄和目錄裡面的東西) -f 強行刪除
[root@administrator ~]# lsanaconda-ks.cfg Documents example.cfg Pictures Videoscptest Downloads initial-setup-ks.cfg PublicDesktop example Music Templates[root@administrator ~]# rm example.cfgrm: remove regular file ‘example.cfg’? y[root@administrator ~]# lsanaconda-ks.cfg Desktop Downloads initial-setup-ks.cfg Pictures Templatescptest Documents example Music [root@administrator ~]# rm -f example.cfg[root@administrator ~]# lsanaconda-ks.cfg Desktop Downloads initial-setup-ks.cfg Pictures Templatescptest Documents example Music Public Videos[root@administrator ~]# rm -rf example/[root@administrator ~]# lsanaconda-ks.cfg Desktop Downloads Music Public Videoscptest Documents initial-setup-ks.cfg Pictures Templates
REDHAT7使用XFS文件系統,XFS提供了xfsdump和xfsrestore工具協助備份XFS文件系統中的數據 。 xfsdump按inode順序備份一個XFS文件系統 ,與傳統的UNIX文件系統不同,XFS不需要在dump前被卸載對使用中的XFS文件系統做dump就可以保證鏡像的一致性。 這與XFS對快照的實現不同,XFS的dump和restore的過程是可以被中斷然後繼續的,無須凍結文件系統。 xfsdump甚至提供了高性能的多線程備份操作——它把一次dump拆分成多個數據流,每個數據流可以被發往不同的目的地。 xfsdump的備份級別有以下兩種,默認為即完全備份: 0 完全備份 1 增量備份
為了確保系統不被誤操作導致無法正常使用創建一個安全的實驗環境
[root@administrator ~]# ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
[root@administrator ~]# ls /dev/sdb*/dev/sdb /dev/sdb1
上面的操作將添加的硬盤分成了兩部分,一部分為剛才創建的1G新分區一部分為剩下的19G 3. 格式化分區並進行掛載 格式化分區為xfs分區
[root@administrator ~]# mkfs.xfs /dev/sdb1meta-data=/dev/sdb1 isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0
創建掛載點目錄sdb1
[root@administrator ~]# mkdir /sdb1[root@administrator ~]# ls /bin dev home lib64 mnt proc run sdb1 sys usrboot etc lib media opt root sbin srv tmp var
掛載分區到上面創建的掛載點目錄sdb1
[root@administrator ~]# mount /dev/sdb1 /sdb1/
查看剛才掛載的分區
[root@administrator ~]# mount | tail -1/dev/sdb1 on /sdb1 type xfs (rw,relatime,attr2,inode64,noquota)
先准備測試文件
[root@administrator ~]# cp /etc/passwd /sdb1/[root@administrator ~]# mkdir /sdb1/dumptest[root@administrator ~]# ls /sdb1dumptest passwd
命令:xfsdump 作用:對分區或者文件進行備份 語法:xfsdump -f 備份文件路徑 備份源
[root@administrator ~]# xfsdump -f ~/sdb1.dump /sdb1xfsdump: using file dump (drive_simple) strategyxfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control ============================= dump label dialog ==============================please enter label for this dump session (timeout in 300 sec) -> sdb1session label entered: "sdb1" --------------------------------- end dialog ---------------------------------xfsdump: level 0 dump of administrator:/sdb1xfsdump: dump date: Mon Aug 8 13:08:52 2016xfsdump: session id: 97f9f6d0-3816-4791-9568-facc0cdf49d1xfsdump: session label: "sdb1"xfsdump: ino map phase 1: constructing initial dump listxfsdump: ino map phase 2: skipping (no pruning necessary)xfsdump: ino map phase 3: skipping (only one dump stream)xfsdump: ino map construction completexfsdump: estimated dump size: 25536 bytesxfsdump: /var/lib/xfsdump/inventory created ============================= media label dialog =============================please enter label for media in drive 0 (timeout in 300 sec) -> sdb1media label entered: "sdb1" --------------------------------- end dialog ---------------------------------xfsdump: creating dump session media file 0 (media 0, file 0)xfsdump: dumping ino mapxfsdump: dumping directoriesxfsdump: dumping non-directory filesxfsdump: ending media filexfsdump: media file size 24240 bytesxfsdump: dump size (non-dir files) : 2592 bytesxfsdump: dump complete: 9 seconds elapsedxfsdump: Dump Summary:xfsdump: stream 0 /root/sdb1.dump OK (success)xfsdump: Dump Status: SUCCESS
查看備份文件
[root@administrator ~]# cat sdb1.dumpxFSdump0�XW�������8G��h�� �I�administratorsdb1Rpsd��.�B٨��v�}1/sdb1/dev/sdb1xfsBkm��J�����{�?�������d����A�"W��N)b��W��@5W�#W��@5W�#�:�� passwd�%' dumptest����X��\�A�W��@5W�#W��@5W�#W��@5W�#����휧?����W��ͅW��ͅW��ͅ����root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologinavahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologinsystemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologinsystemd-network:x:998:996:systemd Network Management:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:997:995:User for polkitd:/:/sbin/nologinunbound:x:996:993:Unbound DNS resolver:/etc/unbound:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologincolord:x:995:992:User for colord:/var/lib/colord:/sbin/nologinusbmuxd:x:113:113:usbmuxd user:/:/sbin/nologingeoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologinsaslauth:x:993:76:Saslauthd user:/run/saslauthd:/sbin/nologinlibstoragemgmt:x:992:990:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologinabrt:x:173:173::/etc/abrt:/sbin/nologinsetroubleshoot:x:991:988::/var/lib/setroubleshoot:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologinrtkit:x:172:172:RealtimeKit:/proc:/sbin/nologinchrony:x:990:987::/var/lib/chrony:/sbin/nologinradvd:x:75:75:radvd user:/:/sbin/nologinqemu:x:107:107:qemu user:/:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinpulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologingdm:x:42:42::/var/lib/gdm:/sbin/nologingnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologinavahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologintcpdump:x:72:72::/:/sbin/nologincourier:x:1000:1000:courier:/home/courier:/bin/bash��������
可以看出備份文件進行了加密導致亂碼
使用參數-L和-M進行無交互式的備份
[root@administrator ~]# xfsdump -f ~/sdb1.dump0 /sdb1 -L sdb1 -M sdb1xfsdump: using file dump (drive_simple) strategyxfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsdump: WARNING: most recent level 0 dump was interrupted, but not resuming that dump since resume (-R) option not specifiedxfsdump: level 0 dump of administrator:/sdb1xfsdump: dump date: Mon Aug 8 13:14:23 2016xfsdump: session id: 2ff3a409-406f-4d93-a054-8af7f70ea278xfsdump: session label: "sdb1"xfsdump: ino map phase 1: constructing initial dump listxfsdump: ino map phase 2: skipping (no pruning necessary)xfsdump: ino map phase 3: skipping (only one dump stream)xfsdump: ino map construction completexfsdump: estimated dump size: 25536 bytesxfsdump: creating dump session media file 0 (media 0, file 0)xfsdump: dumping ino mapxfsdump: dumping directoriesxfsdump: dumping non-directory filesxfsdump: ending media filexfsdump: media file size 24240 bytesxfsdump: dump size (non-dir files) : 2592 bytesxfsdump: dump complete: 0 seconds elapsedxfsdump: Dump Summary:xfsdump: stream 0 /root/sdb1.dump0 OK (success)xfsdump: Dump Status: SUCCESS[root@administrator ~]# lsanaconda-ks.cfg Documents Music sdb1.dump Videoscptest Downloads Pictures sdb1.dump0Desktop initial-setup-ks.cfg Public Templates
備份目標分區中的單個文件或者目錄
[root@administrator ~]# xfsdump -f ~/pwd.dump -s passwd /sdb1 -L pwd -M pwdxfsdump: using file dump (drive_simple) strategyxfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsdump: level 0 dump of administrator:/sdb1xfsdump: dump date: Mon Aug 8 13:19:03 2016xfsdump: session id: 0b6f8c2b-d9df-4713-a0b7-d991d6277f61xfsdump: session label: "pwd"xfsdump: ino map phase 1: constructing initial dump listxfsdump: ino map phase 2: skipping (no pruning necessary)xfsdump: ino map phase 3: skipping (only one dump stream)xfsdump: ino map construction completexfsdump: estimated dump size: 25216 bytesxfsdump: creating dump session media file 0 (media 0, file 0)xfsdump: dumping ino mapxfsdump: dumping directoriesxfsdump: dumping non-directory filesxfsdump: ending media filexfsdump: media file size 23960 bytesxfsdump: dump size (non-dir files) : 2592 bytesxfsdump: dump complete: 5 seconds elapsedxfsdump: Dump Summary:xfsdump: stream 0 /root/pwd.dump OK (success)xfsdump: Dump Status: SUCCESS[root@administrator ~]# lsanaconda-ks.cfg Desktop Downloads Music Public Templatescptest Documents initial-setup-ks.cfg Pictures pwd.dump Videos
命令:xfsrestore 作用:對分區或者文件進行恢復 命令:xfsrestore -f 備份源 需要恢復的目標分區或文件路徑 刪除/sdb1分區下的所有文件
[root@administrator ~]# rm -rf /sdb1/*[root@administrator ~]# ls /sdb1/
使用之前的備份進行恢復
[root@administrator ~]# xfsrestore -f sdb1.dump /sdb1/xfsrestore: using file dump (drive_simple) strategyxfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsrestore: searching media for dumpxfsrestore: examining media file 0xfsrestore: dump description:xfsrestore: hostname: administratorxfsrestore: mount point: /sdb1xfsrestore: volume: /dev/sdb1xfsrestore: session time: Mon Aug 8 13:25:18 2016xfsrestore: level: 0xfsrestore: session label: "sdb1"xfsrestore: media label: "sdb1"xfsrestore: file system id: 426b6d86-0782-4a1e-92e2-c3f310ba7b87xfsrestore: session id: 228b15a9-7c1f-46ed-9fae-c64fc8e465a5xfsrestore: media id: d670fd47-fbcb-4845-8d7e-7993cf2103aexfsrestore: using online session inventoryxfsrestore: searching media for directory dumpxfsrestore: reading directoriesxfsrestore: 2 directories and 2 entries processedxfsrestore: directory post-processingxfsrestore: restoring non-directory filesxfsrestore: restore complete: 0 seconds elapsedxfsrestore: Restore Summary:xfsrestore: stream 0 /root/sdb1.dump OK (success)xfsrestore: Restore Status: SUCCESS[root@administrator ~]# ls /sdb1/dumptest passwd[root@administrator ~]# cat /sdb1/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologinavahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologinsystemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologinsystemd-network:x:998:996:systemd Network Management:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:997:995:User for polkitd:/:/sbin/nologinunbound:x:996:993:Unbound DNS resolver:/etc/unbound:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologincolord:x:995:992:User for colord:/var/lib/colord:/sbin/nologinusbmuxd:x:113:113:usbmuxd user:/:/sbin/nologingeoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologinsaslauth:x:993:76:Saslauthd user:/run/saslauthd:/sbin/nologinlibstoragemgmt:x:992:990:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologinabrt:x:173:173::/etc/abrt:/sbin/nologinsetroubleshoot:x:991:988::/var/lib/setroubleshoot:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologinrtkit:x:172:172:RealtimeKit:/proc:/sbin/nologinchrony:x:990:987::/var/lib/chrony:/sbin/nologinradvd:x:75:75:radvd user:/:/sbin/nologinqemu:x:107:107:qemu user:/:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinpulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologingdm:x:42:42::/var/lib/gdm:/sbin/nologingnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologinavahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologintcpdump:x:72:72::/:/sbin/nologincourier:x:1000:1000:courier:/home/courier:/bin/bash
可以看出文件已經恢,查看文件顯示正常
恢復單個文件:先刪除/sdb1分區中的passwd文件,再使用備份進行恢復
[root@administrator ~]# ls /sdb1/dumptest passwd[root@administrator ~]# rm -rf /sdb1/passwd[root@administrator ~]# ls /sdb1/dumptest[root@administrator ~]# xfsrestore -f sdb1.dump -s passwd /sdb1/xfsrestore: using file dump (drive_simple) strategyxfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsrestore: searching media for dumpxfsrestore: examining media file 0xfsrestore: dump description:xfsrestore: hostname: administratorxfsrestore: mount point: /sdb1xfsrestore: volume: /dev/sdb1xfsrestore: session time: Mon Aug 8 13:25:18 2016xfsrestore: level: 0xfsrestore: session label: "sdb1"xfsrestore: media label: "sdb1"xfsrestore: file system id: 426b6d86-0782-4a1e-92e2-c3f310ba7b87xfsrestore: session id: 228b15a9-7c1f-46ed-9fae-c64fc8e465a5xfsrestore: media id: d670fd47-fbcb-4845-8d7e-7993cf2103aexfsrestore: using online session inventoryxfsrestore: searching media for directory dumpxfsrestore: reading directoriesxfsrestore: 2 directories and 2 entries processedxfsrestore: directory post-processingxfsrestore: restoring non-directory filesxfsrestore: restore complete: 0 seconds elapsedxfsrestore: Restore Summary:xfsrestore: stream 0 /root/sdb1.dump OK (success)xfsrestore: Restore Status: SUCCESS[root@administrator ~]# ls /sdb1/dumptest passwd
more:不支持後退,但幾乎不需要加參數,空格鍵是向下翻頁,Enter鍵是向下翻一行,在不需要後退的情況下比較方便 less:支持前後翻滾,既可以向上翻頁(pageup按鍵),也可以向下翻頁(pagedown按鍵) ,空格鍵是向下翻頁,Enter鍵是向下翻一行
http://xxxxxx/Linuxjc/1156024.html TechArticle