1、Linux的常用命令
pwd 命令
簡介: Print the name of the current working directory.
格式: pwd [-LP]
實例1 [root@centos6 local]# pwd #顯示當前的工作目錄在/usr/local下 /usr/local
cd 命令
簡介: Change the shell working directory.
格式: cd [-L|-P] [dir]
實例1: [root@centos6 network-scripts]# cd /usr/local/ [root@centos6 local]# pwd /usr/local
實例2: [root@centos6 local]# cd .. #到上一級目錄(..:為上一級目錄) [root@centos6 usr]# pwd /usr
實例3: [root@centos6 usr]# cd #回到家目錄 [root@centos6 ~]# pwd /root
實例4: [root@centos6 ~]# cd - /usr [root@centos6 usr]# pwd /usr
ls 命令
簡介: ls - list directory contents
格式: ls [OPTION]... [FILE]...
選項: -a: 列出所有文件,包括以 "." 開頭的隱含文件 -l: 列出文件的詳細信息,如創建者,創建時間,文件的讀寫權限列表等等 -R: 遞歸列出遇到的子目錄 -d: 將目錄名象其它文件一樣列出,而不是列出它們的內容 -1: 文件獨立分行顯示 -S: 按文件大小而不是字典序排序目錄內容,大文件靠前 -u: 使用最近訪問時間代替最近修改時間為依據來排序 -U: 不排序目錄內容;按它們在磁盤上存儲的順序列出
實例1: [root@centos6 ~]# ls anaconda-ks.cfg edrawmax-cn.exe edrawmax_V8.3.2.550_setup.exe install.log install.log.syslog Office_2016.rar test wget-log [root@centos6 ~]# ls -a #顯示已.開頭的因此文件以及當前目錄.與上級目錄.. . anaconda-ks.cfg .bash_logout .bashrc edrawmax-cn.exe install.log .lesshst .ssh test wget-log .. .bash_history .bash_profile .cshrc edrawmax_V8.3.2.550_setup.exe install.log.syslog Office_2016.rar .tcshrc .viminfo
實例2: [root@centos6 ~]# ls -l total 171436 -rw-------. 1 root root 2429 Aug 2 09:46 anaconda-ks.cfg -rw-r--r-- 1 root root 3604480 Aug 2 13:28 edrawmax-cn.exe -rw-r--r-- 1 root root 171294244 Jul 11 10:39 edrawmax_V8.3.2.550_setup.exe -rw-r--r--. 1 root root 45324 Aug 2 09:46 install.log -rw-r--r--. 1 root root 9963 Aug 2 09:44 install.log.syslog -rw-r--r-- 1 root root 137601 Aug 2 10:49 Office_2016.rar drwxr-xr-x 2 root root 4096 Aug 2 18:57 test -rw-r--r-- 1 root root 429430 Aug 2 13:01 wget-log
實例3: [root@centos6 boot]# pwd /boot [root@centos6 boot]# ls -R .: config-2.6.32-642.el6.x86_64 initramfs-2.6.32-642.el6.x86_64.img symvers-2.6.32-642.el6.x86_64.gz efi initrd-2.6.32-642.el6.x86_64kdump.img System.map-2.6.32-642.el6.x86_64 grub lost+found vmlinuz-2.6.32-642.el6.x86_64 ./efi: EFI ./efi/EFI: redhat ./efi/EFI/redhat: grub.efi ./grub: device.map fat_stage1_5 grub.conf jfs_stage1_5 minix_stage1_5 splash.xpm.gz stage2 vstafs_stage1_5 e2fs_stage1_5 ffs_stage1_5 iso9660_stage1_5 menu.lst reiserfs_stage1_5 stage1 ufs2_stage1_5 xfs_stage1_5 ./lost+found:
實例4 [root@centos6 ~]# ls -1 anaconda-ks.cfg install.log install.log.syslog Office_2016.rar test wget-log
stat 命令
簡介: stat - display file or file system status
格式: stat [OPTION]... FILE...
實例1: [root@centos6 ~]# stat anaconda-ks.cfg File: `anaconda-ks.cfg' Size: 2429 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 131083 Links: 1 Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2016-08-02 18:57:51.284999765 +0800 Modify: 2016-08-02 09:46:34.172999723 +0800 Change: 2016-08-02 09:46:38.611999719 +0800
touch 命令
簡介: touch - change file timestamps
格式: touch [OPTION]... FILE...
選項: -a: 僅改變文件的訪問時間 -m: 僅改變文件的修改時間 -t: 設置文件的訪問、修改、改變時間,[[CC]YY]MMDDhhmm[.ss] -c: 如果文件不存在,則不予創建
實例1: 使用-a選項更改文件的訪問時間,以系統時間為準
實例2:
實例3:
cp 命令
簡介: cp - copy files and directories
格式: cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE...
格式(1) cp SOURCE DEST,詳解如下: SRC是文件: 如果目標不存在:新建DEST,并將SRC中內容填充至新建DEST中 如果目標存在: 如果DEST是文件:將SRC中的內容覆蓋至DEST中,基于安全,建議為cp命令使用-i選項 如果DEST是目錄:在DEST下新建與原文件同名的文件,并將SRC中內容填充至新文件中 格式(2) cp SRC... DEST SRC...:多個文件 DEST必須存在,且為目錄,其它情形均會出錯; 格式(3) cp SRC DEST SRC是目錄:此時使用選項:-r 如果DEST不存在:則創建指定目錄,復制SRC目錄中所有文件至DEST中; 如果DEST存在: 如果DEST是文件:報錯 如果DEST是目錄:復制SRC目錄中所有文件至DEST中
選項: -a:復制時,盡可能保持文件的結構和屬性.(但不保持目錄結構)等同于 -dpR -d:復制符號鏈接作為符號鏈接而不是復制它指向的文件, 并且保護在副本中原文件之間的硬鏈接 -f:強制 -i:交互式 -r:遞歸地復制目錄 --preserv:保持原始文件的所有者,組,許可,和時間表屬性 -p:與--preserv 一致 -v:顯示復制過程
實例1 [root@centos6 ~]# cp -r /usr/local /testdir/ #遞歸復制 cp: overwrite `/testdir/local/share/applications/mimeinfo.cache'? y [root@centos6 ~]# ls -R /testdir/ #遞歸查看 /testdir/: local /testdir/local: bin etc games include lib lib64 libexec sbin share src /testdir/local/bin: /testdir/local/etc: /testdir/local/games: /testdir/local/include: /testdir/local/lib: /testdir/local/lib64: /testdir/local/libexec: /testdir/local/sbin: /testdir/local/share: applications info man ...
實例2: [root@centos6 local]# pwd /testdir/local [root@centos6 local]# ls bin etc games include lib lib64 libexec sbin share src [root@centos6 local]# cp -rf /usr/local/etc* ./ #強制遞歸復制覆蓋,不做交互式
mv 命令
簡介: mv - move (rename) files
格式: mv [OPTION]... [-T] SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE...
選項: -f:強制 -i:交互式
實例1 [root@centos6 ~]# mv -f /testdir/local/etc /testdir/local/etc1 [root@centos6 ~]#
rm命令
簡介: rm - remove files or directories
格式: rm [OPTION]... FILE...
選項: -i: 交互式 -f: 強制刪除 -r: 遞歸 --no-preserve-root
實例1 [root@centos6 ~]# cd /testdir/local/ [root@centos6 local]# ls bin etc1 games include lib lib64 libexec sbin share src [root@centos6 local]# rm -rf etc1 #強制遞歸刪除目錄etc1,不做交互式提醒(建議:少用) [root@centos6 local]# ls bin games include lib lib64 libexec sbin share src [root@centos6 local]#
tree 命令
簡介: tree - list contents of directories in a tree-like format.
格式: tree [options] [directory ...]
選項: -d: 只顯示目錄 -L level:指定顯示的層級數目 -P pattern: 只顯示由指定pattern匹配到的路徑
實例1: [root@centos6 ~]# rpm -aq|grep tree #查看是否已安裝tree命令 tree-1.5.3-3.el6.x86_64 [root@centos6 ~]# ls anaconda-ks.cfg file file2 install.log install.log.syslog test wget-log [root@centos6 ~]# tree #不加參數,直接對當前目錄使用tree命令 . ├── anaconda-ks.cfg ├── file ├── file2 ├── install.log ├── install.log.syslog ├── test └── wget-log 1 directory, 6 files #root目錄下有一個目錄和六個普通文件 [root@centos6 ~]#
mkdir 命令
簡介: mkdir - make directories
格式: mkdir [OPTION]... DIRECTORY...
選項: -p: 存在于不報錯,且可自動創建所需的各目錄 -v: 顯示詳細信息 -m MODE: 創建目錄時直接指定權限
實例1: [root@centos6 testdir]# ls local [root@centos6 testdir]# mkdir -v test mkdir: created directory `test' [root@centos6 testdir]# ls local test [root@centos6 testdir]#
實例2: [root@centos6 testdir]# mkdir -pv /testdir/test/a/b/c/d mkdir: created directory `/testdir/test/a' mkdir: created directory `/testdir/test/a/b' mkdir: created directory `/testdir/test/a/b/c' mkdir: created directory `/testdir/test/a/b/c/d' [root@centos6 testdir]# tree -d /testdir/test/ /testdir/test/ └── a └── b └── c └── d 4 directories [root@centos6 testdir]#
實例3: [root@centos6 testdir]# mkdir test1 [root@centos6 testdir]# ls -ld test1 drwxr-xr-x 2 root root 4096 Aug 3 12:21 test1 #默認創建的目錄權限為755 [root@centos6 testdir]# mkdir -m 444 test2 [root@centos6 testdir]# ls -ld test2 dr--r--r-- 2 root root 4096 Aug 3 12:22 test2 #設置創建test2目錄的權限為444
rmdir 命令
簡介: rmdir - remove empty directories
格式: rmdir [OPTION]... DIRECTORY...
選項: -p: 遞歸刪除父空目錄 -v: 顯示詳細信息
實例1 [root@centos6 ~]# mkdir -pv /testdir/test/a/b/c/d mkdir: created directory `/testdir/test' mkdir: created directory `/testdir/test/a' mkdir: created directory `/testdir/test/a/b' mkdir: created directory `/testdir/test/a/b/c' mkdir: created directory `/testdir/test/a/b/c/d' [root@centos6 ~]# rmdir -pv /testdir/test/a/b/c/d rmdir: removing directory, `/testdir/test/a/b/c/d' rmdir: removing directory, `/testdir/test/a/b/c' rmdir: removing directory, `/testdir/test/a/b' rmdir: removing directory, `/testdir/test/a' rmdir: removing directory, `/testdir/test' rmdir: removing directory, `/testdir' rmdir: failed to remove directory `/testdir': Directory not empty #因為testdir目錄并非空目錄,因此無法刪除 [root@centos6 ~]# ll /testdir/ total 12 drwxr-xr-x 11 root root 4096 Aug 3 12:11 local drwxr-xr-x 2 root root 4096 Aug 3 12:21 test1 dr--r--r-- 2 root root 4096 Aug 3 12:22 test2 [root@centos6 ~]#
2、Linux中的通配符glob
通配符:*, ?, [] (1) * 任意長度的任意字符 a*b: 匹配:aab, ab, a123b, 非匹配:abc (2) ? 任意單個字符 a?b: 匹配aab 非匹配ab, a12b, abc (3) [] 匹配指定范圍內的任意單個字符 [0-9]:數字0-9 [a-z]:不區分字符大小寫,也就是a-z和A-Z (4) [^] 匹配指定范圍外的任意單個字符 [^0-9]:非0-9的數字的任意單個字符
專用字符集合: [:digit:]:任意數字,相當于0-9 [:lower:]:任意小寫字母 [:upper:]: 任意大寫字母 [:alpha:]: 任意大小寫字母 [:alnum:]:任意數字或字母 [:space:]:空格 [:punct:]:標點符號
原創文章,作者:Aleen,如若轉載,請注明出處:http://www.www58058.com/27468
寫的很詳細,總結的很好,對常見選項分析很到位