Linux 學習筆記(一) 阿新 • • 發佈:2018-11-26 shell的版本: /bin/sh /bin/bash * /sbin/nologin /bin/tcsh /bin/csh 外部命令:任何一個外部命令都是一個可執行的檔案,例如ls,外部命令儲存在硬碟上 內部命令:shell直譯器的一部分,例如cd,內部命令儲存在記憶體中 複製:ctrl+shift+c 貼上:ctrl+shift+v 複製貼上:選中,按下滾軸 help cd 內部命令幫助,內部命令少 man ls 外部命令幫助,外部命令多 ls --help 目錄操作命令: cd - 上一次目錄 cd .. 上一級目錄 linux中不記錄建立日期 ls -lh 可以顯示檔案大小(以K,M,G等單位) ls -ld /etc 顯示/etc本身目錄的屬性 alias 建立別名 alias la="ls -a" unalias 刪除別名 unalias la mkdir -p /test/a{1,2}/b{1..5} ls -R test/ 遞迴查詢test資料夾,R注意大小寫 /test/a1: b1 b2 b3 b4 b5 /test/a2: b1 b2 b3 b4 b5 du -sh /etc/ 顯示/etc檔案內的大小 ls -lhd /etc 顯示/etc本目錄檔案的大小 drwxr-xr-x. 120 root root 12K 12月 18 14:06 /etc/ //120表示硬連結檔案數 檔案操作命令: file /etc 檢視檔案型別 /etc/: directory [[email protected] /]# file file1 file1: empty cp file1 file2 file3 file4 file5 /etc 將5個檔案複製到/etc下 cp -r 1 2 3 5 將目錄1 ,2 ,3複製到5下 //複製目錄需要加-r,檔案不需要 [[email protected] 5]# ls 1 2 3 [[email protected] 5]# tar -czf 123.gz 1 2 3 //建立123.gz壓縮包 [[email protected] 5]# ls 1 123.gz 2 3 [[email protected] 5]# tar -xvf 123.gz -C 2/ //將123.gz壓縮到2下,必須要用-C,C注意大小寫 在檔案中 ctrl+r 與 u 相反 :r /etc/host.conf 把/etc/host.conf複製到本檔案末尾 cp -r 複製目錄 cp -r /etc /mnt cp -a 複製目錄 cp -a /etc /mnt cp -r 複製目錄 \cp -rf /etc /mnt ?下面解釋 alias [[email protected] /]# alias alias cp='cp -i' //-i 的優先順序高於f,需要用\強制轉換cp即可 alias rm='rm -i' //-f 的優先順序高於i,不需要用\強制轉換 rm -f file1 which 用於查詢外部命令,在PATH環境變數中找 [email protected] /]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin whereis passwd 找到passwd的命令和passwd的檔案 [[email protected] /]# whereis passwd passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz locate 找出使用者輸入的關鍵詞檔名 [[email protected] /]# updatedb [[email protected] /]# locatepasswd bash: locatepasswd: command not found [[email protected] /]# locate passwd [[email protected] /]# find /etc -name "*.conf" -a -size +10k //大於10k,-a表示and,-10k,小於10k /etc/dnsmasq.conf /etc/lvm/lvm.conf /etc/latrace.d/ncurses.conf /etc/snmp/snmpd.conf /etc/httpd/conf/httpd.conf /etc/ltrace.conf find /etc -name "*.conf" -a -size +10k -exec ls -lh {} \; //{}表示find /etc -name "*.conf" -a -size +10k的結果,\;表示轉義字元; -exec ls -lh 對結果再處理 -rw-r--r--. 1 root root 21K 8月 17 2011 /etc/dnsmasq.conf -rw-r--r--. 1 root root 29K 10月 19 2011 /etc/lvm/lvm.conf -rw-r--r--. 1 root root 11K 6月 4 2010 /etc/latrace.d/ncurses.conf find /etc -name "*.conf" -exec ls -lh {} \; find /etc -name "*.conf" -exec ls -lh {} + //結果一樣,+號效率高 硬連結只能針對檔案建立,而且不能跨分割槽 軟連線目錄檔案,可以跨分割槽建立 每一個檔案都會佔用一個inlde號,查詢就找inode號,ls -i 檢視inode號,inode號在系統中是唯一的 [[email protected] etc]# grep root passwd root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin //包括root的行 [[email protected] etc]# grep ^root passwd //以root開頭的行 root:x:0:0:root:/root:/bin/bash [[email protected] etc]# [[email protected] etc]# grep nologin$ passwd 以nologin結尾的行 [[email protected] etc]# grep nologin$ passwd | wc -l //算的前面結果的行數 33 [[email protected] etc]# ls -l | grep passwd //含有passwd的行顯示出來 -rw-r--r--. 1 root root 1897 12月 17 23:52 passwd -rw-r--r--. 1 root root 1897 12月 17 23:52 passwd- [[email protected] ~]# tar czf /root/etc.tar.gz 123 456 [[email protected] ~]# ls 123 etc.tar.gz workspace 視訊 下載 456 install.log 公共的 圖片 音樂 anaconda-ks.cfg install.log.syslog 模板 文件 桌面 [[email protected] ~]# ctrl+v 選中 , I , #, ESC,ESC 選擇的行加# //可視模組