建立、複製、刪除、移動、查看、編輯、壓縮、查找node
Windows: 以多根的方式組織文件 C:\ D:\ E:\
Linux: 以單根的方式組織文件 /mysql
/目錄結構: FSH (Filesystem Hierarchy Standard)linux
[root@tianyun ~]# ls / bin dev lib media net root srv usr boot etc lib64 misc opt sbin sys var cgroup home lost+found mnt proc selinux tmp
注:下圖爲Centos7目錄結構sql
bin 普通用戶使用的命令 /bin/ls, /bin/date
sbin 管理員使用的命令 /sbin/service
dev 設備文件 /dev/sda,/dev/sda1,/dev/tty1,/dev/tty2,/dev/pts/1, /dev/zero, /dev/null, /dev/random
root root用戶的HOME
home 存儲普通用戶家目錄
lost+found fsck修復時,存儲沒有連接的文件或目錄
proc 虛擬的文件系統,反映出來的是內核,進程信息或實時狀態
usr 系統文件,至關於C:\Windows
/usr/local 軟件安裝的目錄,至關於C:\Program
/usr/bin 普通用戶使用的應用程序
/usr/sbin 管理員使用的應用程序
/usr/lib 庫文件Glibc
/usr/lib64 庫文件Glibc
boot 存放的系統啓動相關的文件,例如kernel,grub(引導裝載程序)
etc 配置文件(系統相關如網絡/etc/sysconfig/network,應用相關配置文件如/etc/ssh/sshd_config...)
lib 庫文件Glibc
lib64 庫文件Glibc
tmp 臨時文件(全局可寫:進程產生的臨時文件)
var 存放的是一些變化文件,好比數據庫,日誌,郵件....
mysql: /var/lib/mysql
vsftpd: /var/ftp
mail: /var/spool/mail
cron: /var/spool/cron
log: /var/log
臨時文件: /var/tmp(進程產生的臨時文件)
==設備(主要指存儲設備)掛載目錄==
media 移動設備默認的掛載點
mnt 手工掛載設備的掛載點
misc automount進程掛載
net automount進程掛載
/bin 普通用戶使用的命令 /bin/ls, /bin/date RHEL7淘汰
/sbin 管理員使用的命令 RHEL7淘汰
/usr/bin 普通用戶使用的應用程序
/usr/sbin 管理員使用的應用程序
/lib 庫文件Glibc RHEL7淘汰
/lib64 庫文件Glibc RHEL7淘汰
/usr/lib 庫文件Glibc
/usr/lib64 庫文件Glibc
ls -l 文件名 僅看的是文件的修改時間shell
Linux文件有四種時間:數據庫
# stat anaconda-ks.cfg //查看文件的詳細屬性(其中包括文件時間屬性)
訪問時間:atime, 查看內容 //RHEL6會延後修改atime
修改時間:mtime,修改內容
改變時間:ctime, 文件屬性,好比權限
刪除時間:dtime, 文件被刪除的時間vim
[root@root ~]# ls -l install.log
-rw-r--r-- 1 root root 34793 10-23 13:49 install.log
[root@root ~]# stat install.log
File: 「install.log」
Size: 34793 Blocks: 80 IO Block: 4096 通常文件
Device: 802h/2050d Inode: 65282 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-10-23 16:53:20.000000000 +0800
Modify: 2012-10-23 13:49:46.000000000 +0800
Change: 2012-10-23 13:49:52.000000000 +0800
注:RHEL6開始relatime,atime延遲修改,必須知足其中一個條件:
1. 自上次atime修改後,已達到86400秒;
2. 發生寫操做時;c#
經過顏色判斷文件的類型是不必定正確的!!!
Linux系統中文件是沒有擴展名!!!安全
ls -l 文件名 //看第一個字符
- 普通文件(文本文件,二進制文件,壓縮文件,電影,圖片。。。)
d 目錄文件(藍色)
b 設備文件(塊設備)存儲設備硬盤,U盤 /dev/sda, /dev/sda1
c 設備文件(字符設備)打印機,終端 /dev/tty1
s 套接字文件
p 管道文件
l 連接文件(淡藍色)
[root@root ~]# ll -d /etc/hosts /bin/ls /home /dev/sda /dev/tty1 /etc/grub2.cfg /dev/log /run/dmeventd-client
-rwxr-xr-x. 1 root root 117616 Nov 20 2015 /bin/ls
srw-rw-rw- 1 root root 0 Mar 14 2017 /dev/log
brw-rw---- 1 root disk 8, 0 Mar 14 09:03 /dev/sda
crw--w---- 1 root tty 4, 1 Mar 14 09:03 /dev/tty1
lrwxrwxrwx. 1 root root 22 Dec 21 01:40 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
-rw-r--r-- 1 root root 392 Feb 22 15:51 /etc/hosts
drwxr-xr-x. 10 root root 4096 Mar 14 11:00 /home
[root@localhost ~]# file /etc/hosts
/etc/hosts: ASCII text
[root@localhost ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aa7ff68f13de25936a098016243ce57c3c982e06, stripped
[root@localhost ~]# file /dev/sda
/dev/sda: block special
[root@localhost ~]# file /dev/tty1
/dev/tty1: character special
[root@localhost ~]# file /etc/grub2.cfg
/etc/grub2.cfg: broken symbolic link to `../boot/grub2/grub.cfg'
[root@localhost ~]# file /home
/home: directory
[root@localhost ~]# file /run/dmeventd-client
/run/dmeventd-client: fifo (named pipe)
你要在哪兒建立文件?
你要將什麼文件複製到什麼地方?
你要刪除什麼地方的什麼文件?bash
/home/alice/file1 和 /home/bob/file1 不是同一文件!!!
/abc/file5 和 abc/file5 有多是不同的!!!
絕對路徑: 從/開始的路徑 /home/alice/file1
相對路徑: 相對於當前目錄開始 a.txt ./a.txt ../bob/b.txt [假如:此時在目錄/home/alice]
cd 絕對路徑 cd /home/alice cd ~alice cd 相對路徑 cd Desktop/abc cd .. cd . ======================================================= cd 專用: cd - 返回上次目錄 cd 直接回家 =======================================================
文件 touch # touch file1.txt //無則建立,有則修改時間 # touch file3 file4 # touch /home/file10.txt # touch /home/file5 file6 # touch /home/{zhuzhu,gougou} # touch file{1..20} # touch file{a..c} # touch yang{a,b,c} //{}集合,等價touch yanga yangb yangc 目錄 mkdir # mkdir dir1 # mkdir /home/dir2 /home/dir3 # mkdir /home/{dir4,dir5} # mkdir -v /home/{dir6,dir7} # mkdir -v /hoem/dir8/111/22 # mkdir -pv /hoem/dir8/111/222 //包括其父母的建立,不會有任何消息輸出 # mkdir -pv /home/{yang/{dir1,111},tianyun}
Usage: cp [OPTION]... [-T] SOURCE DEST # cd # mkdir /home/dir{1,2} # cp -v install.log /home/dir1 # cp -v install.log /home/dir1/yang.txt # cp -rv /etc /home/dir1 # cp -v install.log /home/dir90 //沒有/home/dir90 # cp -v install.log /home/dir2 # cp -v anaconda-ks.cfg !$ # cp -rv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/grub.conf /home/dir2 //將多個文件拷貝到同一個目錄 # cp -rv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/grub.conf /etc/hosts . # cp -r /etc /tmp # cp -rf /etc /tmp # \cp -r /etc /tmp
[root@localhost ~]# type -a cp cp is aliased to `cp -i' cp is /bin/cp [root@localhost ~]# cp -rv /etc/sysconfig/network-scripts/{ifcfg-eth0,ifcfg-eth0.bak} [root@localhost ~]# cp -rv /etc/sysconfig/network-scripts/ifcfg-eth0{,-org} [root@localhost ~]# cp -rv /etc/sysconfig/network-scripts/{ifcfg-eth0,yang-eth0}
Usage: mv [OPTION]... [-T] SOURCE DEST # mv file1 /home/dir3 將file2移動到/home/dir3 # mv file2 /home/dir3/file20 將file2移動到/home/dir3,並更名爲file20 # mv file4 file5 將file4重命名爲file5,當前位置的移動就是重命名
示例1:刪除/home/dir1 # cd /home # rm -rf dir1 -r 遞歸 -f force強制 -v 詳細過程 示例2: [root@localhost~]# mkdir /home/dir10 [root@localhost~]# touch /home/dir10/{file2,file3,.file4} [root@localhost~]# rm -rf /home/dir10/* //不包括隱藏文件 [root@localhost~]# ls /home/dir10/ -a . .. .file4 示例3: [root@localhost~]# rm -rf file* [root@localhost~]# rm -rf *.pdf
==文本文件 (cat tac less more head tail tailf grep ...) /bin/date /etc/hosts /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/shadow /etc/group /etc/grub2.cfg /etc/resolv.conf /etc/profile //設置系統環境變量 /etc/bashrc //影響bash shell環境 /var/log/messages //系統主日誌文件 /var/log/secure //跟安全相關的日誌如ssh登陸,本地登陸...
cat -n 顯示行號 -A 包括控制字符(換行符/製表符) linux $ Windows ^M$ less more head tail tailf [root@localhost~]# head /etc/passwd [root@localhost~]# head -2 /etc/passwd [root@localhost~]# tail /etc/passwd [root@localhost~]# tail -1 /etc/passwd [root@localhost~]# tail /var/log/messages [root@localhost~]# tail -20 /var/log/messages [root@localhost~]# tail -f /var/log/secure //-f 動態查看文件的尾部 [root@localhost~]# tail -F /var/log/secure //-F 動態查看文件的尾部 注:vim, gedit編輯文件時,索引號會改變 grep 針對文件內容進行過濾 # grep 'root' /etc/passwd # grep '^root' /etc/passwd # grep 'bash$' /etc/passwd # grep 'failure' /var/log/secure
[root@localhost~]# ll -a > list.txt
文件編輯器 gedit
文件編輯器 vi, vim, nano
命令模式: a. 光標定位 hjkl 0 $ gg G 3G 進入第三行 /string (n N 能夠循環的) 快速定位到某一行 /^d /txt$ b. 文本編輯(少許) y 複製 yy 3yy ygg yG (以行爲單位) d 刪除 dd 3dd dgg dG (以行爲單位) p 粘貼 x 刪除光標所在的字符 D 從光標處刪除到行尾 u undo撤銷 ^r redo重作 r 能夠用來修改一個字符 c. 進入其它模式 a 進入插入模式 i 進入插入模式 o 進入插入模式 A 進入插入模式 : 進入末行模式(擴展命令模式) v 進入可視模式 ^v 進入可視塊模式 V 進入可視行模式 R 進入替換模式 插入模式: 可視塊模式: 塊插入(在指定塊前加入字符): 選擇塊,I 在塊前插入字符, ESC 塊替換: 選擇塊,r 輸入替換的字符 塊刪除: 選擇塊,d | x 塊複製: 選擇塊,y 擴展命令模式: a. 保存退出 :10 進入第10行 :w 保存 :q 退出 :wq 保存並退出 :w! 強制保存 :q! 不保存並退出 :wq! 強制保存退出 :x 保存並退出 ZZ b. 查找替換 :範圍 s/old/new/選項 :1,5 s/root/yang/ 從1-5行的root 替換爲yang :5,$ s/root/yang/ $表示最後一行 :1,$ s/root/yang/g = :% s/root/yang/g %表示全文 g表示全局 :% s#/dev/sda#/var/ccc#g :,8 s/root/yang/ 從當前行到第8行 :4,9 s/^#// 4-9行的開頭#替換爲空 :5,10 s/.*/#&/ 5-10前加入#字符 (.*整行 &引用查找的內容) c. 讀入文件/寫文件(另存爲) :w 存儲到當前文件 :w /tmp/aaa.txt 另存爲/tmp/aaa.txt :1,3 w /tmp/2.txt :r /etc/hosts 讀入文件到當前行後 :5 r /etc/hosts 讀入文件到第5行後 d. 設置環境 臨時設置: :set nu 設置行號 :set ic 不區分大小寫 :set ai 自動縮進 :set list 顯示控制字符 :set nonu 取消設置行號 :set noic 永久的環境: /etc/vimrc 影響全部系統用戶 ~/.vimrc 影響某一個用戶 # vim ~/.vimrc set ic set nu