初识50个Linux命令
1.?【命令】:cat
【功能說明】:
concatenate files and print on the standard output #連接文件并打印到標(biāo)準(zhǔn)輸出,有標(biāo)準(zhǔn)輸出的都可以用重定向定向?qū)氲轿募锩?/span>
【語法格式】:
cat [OPTION]...[FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b,--number-nonblank | number nonempty output lines | 非空輸出行編號(hào) |
| -n,--number | number all outputnlines | 所有行輸出編號(hào) |
【示例】:
1、基本用法:查看文件內(nèi)容
[root@oldboy ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
?
2、把log1.txt的文件內(nèi)容加上行號(hào)輸入log2.txt這個(gè)文件里
[root@oldboy ~]# cat -n log1.txt
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?????4
?????5
[root@oldboy ~]# cat -n log1.txt>log2.txt
[root@oldboy ~]# cat log2.txt
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?????4
?????5
?
3、把文件log1.txt里面的文件空格不顯示行號(hào)加入log2.txt中
[root@oldboy ~]# cat -n log1.txt
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?????4
?????5
[root@oldboy ~]# cat -b log1.txt
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?
?
[root@oldboy ~]# cat -b log1.txt>log2.txt
[root@oldboy ~]# cat log2.txt
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?
4、同時(shí)顯示log1.txt和log2.txt
[root@oldboy ~]# cat log1.txt log2.txt
2012-1
2013-1
2014-1
?
?
?????1 ?2012-1
?????2 ?2013-1
?????3 ?2014-1
?
5、使用cat編輯文檔內(nèi)容
[root@oldboy ~]# cat >log1.txt<<EOF
> 2012-3
> 2013-3
> 2014-3
> EOF
[root@oldboy ~]# cat log1.txt
2012-3
2013-3
2014-3
?
6、使用cat追加編輯文檔內(nèi)容
[root@oldboy data]# cat >>oldboy.txt<<EOF
> ni hao
> jin tian tian qi zhen hao
> EOF
[root@oldboy data]# cat oldboy.txt
I am oldboy
I am study linux
ni hao
jin tian tian qi zhen hao
?
?
2.?【命令】:cd
【功能說明】:
Change the current directory to DIR #更改當(dāng)前路徑為DIR
【語法格式】:
cd [-L|-P] [dir]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -L | force symbolic links to be followed | ? |
| -P | use the physical directory structure without following symbolic | ? |
| - | ? | ? |
【示例】:
1、基本用法:更改目錄路徑到根目錄
[root@oldboy ~]# cd /
[root@oldboy /]#
?
2、基本用法:更改目錄路徑到上級目錄
[root@oldboy ~]# cd ..
[root@oldboy /]#
?
3、更改目錄路徑到上一次使用的目錄
[root@oldboy /]# cd -
/root
[root@oldboy ~]#
?
?
3.?【命令】:mkdir
【功能說明】:
make directories ??#創(chuàng)建目錄
【語法格式】:
mkdir [OPTION]... DIRECTORY...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -m, --mode | set file mode (as in chmod), not a=rwx - umask | 設(shè)定權(quán)限<模式>(類似chmod),而不是rwxrwxrwx減umask |
| -p, --parents | no error if existing, make parent directories as needed | 遞歸創(chuàng)建目錄 |
| -v, --verbose | print a message for each created directory | 每次創(chuàng)建新目錄都顯示信息 |
| -Z | set the SELinux security context of each created directory to CTX | ? |
【示例】:
1、基本用法:創(chuàng)建目錄
[root@oldboy ~]# mkdir /data
[root@oldboy ~]# cd /data
[root@oldboy data]# pwd
/data
?
2、遞歸創(chuàng)建多個(gè)目錄
[root@oldboy data]# mkdir -p /oldboy/oldboy
[root@oldboy data]# cd /oldboy/oldboy
[root@oldboy oldboy]# pwd
/oldboy/oldboy
?
?
?
4.?【命令】:ls
【功能說明】:
list directory contents ??#列出目標(biāo)目錄中所有的子目錄和文件
【語法格式】:
ls [OPTION]... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a, --all | do not ignore entries starting with. | 列出目錄下的所有文件 |
| -A, --almost-all | do not list implied.and .. | 同-a,但不列出“.”(表示當(dāng)前目錄)和“..”(表示當(dāng)前目錄的父目錄) |
| -b, --escape | print octal escapes for nongraphic characters | 把文件名中不可輸出的字符用反斜杠加字符編號(hào)的形式列出 |
| -B, --ignore-backups | do not list implied entries ending with ~ | 不輸出以“~”結(jié)尾的備份文件 |
| -c | sort by ctime | 配合-lt;根據(jù)ctime排序及顯示ctime(文件狀態(tài)最后更改的時(shí)間)配合-l:顯示ctime但根據(jù)名稱排序否則:根據(jù)ctime排序 |
| -C | list entries by clumns | 每欄由上至下列出項(xiàng)目 |
| -d, --directory | list directory entries instead of contentsm,and do not dereference symbolic links | 將目錄象文件一樣顯示,而不是顯示其下的文件 |
| -D, --dired | generate output designed for Emacs’?dired mode | 產(chǎn)生適合Emacs的dired模式使用的結(jié)果 |
| -f | do not sort,enable -aU,disable -ls --color | 對輸出的文件不進(jìn)行排序,-aU選項(xiàng)生效,-1st選項(xiàng)失效 |
| -F --classify | append indicator(one of */=>@|)to entries | 在每個(gè)文件名后附上一個(gè)字符以說明該文件的類型,“*”表示可執(zhí)行的普通 |
| -g | like -l,but do not list owner | 類似-l,但不列出所有者 |
| -h, --human-readable | with -l,print sizes in human readable format | 以容易理解的格式列出文件大小 |
| -H, --dereference-command-line | follow symbolic links listed on the command line | 使用命令列中的符號(hào)鏈接指示的真正目的地 |
| -i, --inode | print the index number of each file | 打印出每個(gè)文件的inode號(hào) |
| -I,--ignore=PATTERN | do not list implied entries matching shell PATTERN | 不打印出任何符合shell萬用字符<樣式>的項(xiàng)目 |
| -k | like --block-size=1K | 以k字節(jié)的形式表示文件的大小 |
| -l | use a long listing format | 除了文件名之外,還將文件的權(quán)限、所有者、文件大小等信息詳細(xì)列出來 |
| -L,--dereference | when showing file information for a symbolic link,show information for the file the link references rather than for the link itself | 當(dāng)顯示符號(hào)鏈接的文件信息時(shí),顯示符號(hào)鏈接所指示的對象而并非符號(hào)鏈接本身的信息。 |
| -m | fill width with a comma separated list of entries | 所有項(xiàng)目以逗號(hào)分隔,并填滿整行行寬 |
| -n, --numeric-uid-gid | like -l,but list numeric user and group IDs | 用數(shù)字的UID,GID代替名稱 |
| -N, --literal | print raw entry names | 不限制文件長度 |
| -o | like -l,but do not list group information | 類似-l,顯示文件的除組信息外的詳細(xì)信息 |
| -p, --indicator-style=slash | append / indicator to directories | 對目錄添加“/”符號(hào) |
| -q, --hide-control-chars | print ? instead of non graphic characters | 用?號(hào)代替不可輸出的字符 |
| -Q, --quote-name | enclose entry names in double quotes | 把輸出的文件名用雙引號(hào)括起來 |
| -r, --reverse | reverse order while sorting | 依相反次序排列 |
| -R, --recursive | list subdirectories recursively | 同時(shí)列出所有子目錄層 |
| -s, --size | print the allocated size of each file,in blocks | 以塊大小為單位列出所有文件的大小 |
| -S | sort by file size | 根據(jù)文件大小排序 |
| -t | sort by modification time | 以文件修改時(shí)間排序 |
| -T, --tabsize=COLS | assume tab stops at each COLS instead of 8 | ? |
| -u | with -lt: sort by, and show, access time with -l:show access time and sort by name otherwise: sort by access time | 配合-lt:顯示訪問時(shí)間而且依訪問時(shí)間排序 配合-l:顯示訪問時(shí)間但根據(jù)名稱排序 其他:根據(jù)訪問時(shí)間排序 |
| -U | do not sort; list entries in directory order | 不進(jìn)行排序;依文件系統(tǒng)原有的次序列出項(xiàng)目 |
| -v | natural sort of (version) numbers within text | 根據(jù)版本進(jìn)行排序 |
| -w, --width=COLS | assume screen width instead of current value | 自行指定屏幕寬度而不使用目前的數(shù)值 |
| -x | list entries by lines instead of by columns | 逐行列出項(xiàng)目而不是逐欄列出 |
| -X | sort alphabetically by entry extension | 根據(jù)擴(kuò)展名排序 |
| -1 | list one file per line | 每行只列出一個(gè)文件 |
?
?
【示例】:
1、基本用法:查看目錄內(nèi)容
[root@oldboy ~]# ls
anaconda-ks.cfg ?data ?install.log ?install.log.syslog ?log1.txt ?log2.txt ?test.txt
?
2、基本用法:查看目錄全部內(nèi)容(包含隱藏文件)
[root@oldboy ~]# ls -la
total 88
dr-xr-x---. ?3 root root ?4096 Mar ?7 18:16 .
dr-xr-xr-x. 24 root root ?4096 Mar ?9 17:00 ..
-rw-------. ?1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
-rw-------. ?1 root root ?5003 Mar ?9 04:13 .bash_history
-rw-r--r--. ?1 root root ???18 May 20 ?2009 .bash_logout
-rw-r--r--. ?1 root root ??176 May 20 ?2009 .bash_profile
-rw-r--r--. ?1 root root ??176 Sep 23 ?2004 .bashrc
-rw-r--r--. ?1 root root ??100 Sep 23 ?2004 .cshrc
drwxr-xr-x. ?3 root root ?4096 Mar ?9 01:47 data
-rw-r--r--. ?1 root root 22179 Mar ?3 23:14 install.log
-rw-r--r--. ?1 root root ?5890 Mar ?3 23:13 install.log.syslog
-rw-r--r--. ?1 root root ???18 Mar ?7 18:13 log1.txt
-rw-r--r--. ?1 root root ???44 Mar ?7 17:53 log2.txt
-rw-r--r--. ?1 root root ??129 Dec ?4 ?2004 .tcshrc
-rw-r--r--. ?1 root root ????0 Mar ?7 18:27 test.txt
?
3、基本用法:查看目錄(使用長模式)
[root@oldboy ~]# ls -l
total 52
-rw-------. 1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
drwxr-xr-x. 3 root root ?4096 Mar ?9 01:47 data
-rw-r--r--. 1 root root 22179 Mar ?3 23:14 install.log
-rw-r--r--. 1 root root ?5890 Mar ?3 23:13 install.log.syslog
-rw-r--r--. 1 root root ???18 Mar ?7 18:13 log1.txt
-rw-r--r--. 1 root root ???44 Mar ?7 17:53 log2.txt
-rw-r--r--. 1 root root ????0 Mar ?7 18:27 test.txt
?
5.?【命令】:pwd
【功能說明】:
print name of current/working directory ??#打印當(dāng)前目錄路徑
【語法格式】:
pwd [OPTION]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -L, --logical | use PWD from environment,even if it contains symlinks | 當(dāng)目錄為鏈接路徑時(shí),顯示鏈接路徑 |
| -P, --physical | avoid all symlinks | 顯示實(shí)際物理路徑,而非使用鏈接 |
【示例】:
1、基本用法:顯示當(dāng)前目錄所在路徑
[root@oldboy ~]# pwd
/root
[root@oldboy ~]#
?
2、顯示當(dāng)前目錄的物理路徑
[root@oldboy ~]# cd /etc/init.d
[root@oldboy init.d]# pwd -P
/etc/rc.d/init.d
?
3、顯示當(dāng)前目錄的鏈接路徑
[root@oldboy ~]# cd /etc/init.d
[root@oldboy init.d]# pwd -L
/etc/init.d
?
?
6.?【命令】:touch
【功能說明】:
change file timestamps ??#創(chuàng)建文件或改變文件的時(shí)間戳
【語法格式】:
pwd [OPTION]... FILE...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | change only the access time | 只更改存取時(shí)間 |
| -c, --no-create | do not create any files | 不新建任何文檔 |
| -d, --date=STRING | parse STRING and use it instead of current time | 使用指定的日期時(shí)間,而非現(xiàn)在的時(shí)間 |
| -f | (ignored) | 忽略 |
| -h, --no-dereference | affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) | 會(huì)影響符號(hào)鏈接本身,而非符號(hào)鏈接所指示的目的地 |
| -m | change only the modification time | 只更改變動(dòng)時(shí)間 |
| -r, --reference=FILE | use this file’s times instead of current time | 把指定文檔或目錄的日期時(shí)間,統(tǒng)統(tǒng)設(shè)成和參考文檔或目錄的日期時(shí)間相同 |
| -t STAMP | use [[CC]YY]MMDDhhmm[.ss] instead of current time | 使用指定格式的日期時(shí)間,而非當(dāng)前時(shí)間 |
| --time=WORD | change ?the ?specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m | 使用WORD指定的時(shí)間:access、atime、use都等于-a選項(xiàng)的效果,而modify、mtime等于-m選項(xiàng)的效果 |
【示例】:
1、基本用法:創(chuàng)建新文件
[root@oldboy data]# touch log2012.log log2013.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar ?9 17:48 log2012.log
-rw-r--r--. 1 root root 0 Mar ?9 17:48 log2013.log
?
2、不創(chuàng)建不存在的文件
[root@oldboy data]# touch -c log2014.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar ?9 17:48 log2012.log
-rw-r--r--. 1 root root 0 Mar ?9 17:48 log2013.log
?
3、更新log2012.log的時(shí)間和log.log時(shí)間戳相同
[root@oldboy data]# touch log.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Mar ?9 ?2016 log2012.log
-rw-r--r--. 1 root root 0 Mar ?9 ?2016 log2013.log
-rw-r--r--. 1 root root 0 May 23 00:00 log.log
[root@oldboy data]# touch -r log.log log2012.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 May 23 00:00 log2012.log
-rw-r--r--. 1 root root 0 Mar ?9 ?2016 log2013.log
-rw-r--r--. 1 root root 0 May 23 00:00 log.log
?
4、設(shè)定文件時(shí)間戳
[root@oldboy data]# touch -t 201211142234.50 log2016.log
[root@oldboy data]# ll
total 0
-rw-r--r--. 1 root root 0 Nov 14 ?2012 log2016.log
?
【說明】:
?????-t??time?使用指定的時(shí)間值?time?作為指定文件相應(yīng)時(shí)間戳記的新值.此處的?time規(guī)定為如下形式的十進(jìn)制數(shù):??????
??????[[CC]YY]MMDDhhmm[.SS]?????
?? ???這里,CC為年數(shù)中的前兩位,即”世紀(jì)數(shù)”;YY為年數(shù)的后兩位,即某世紀(jì)中的年數(shù).如果不給出CC的值,則touch???將把年數(shù)CCYY限定在1969--2068之內(nèi).MM為月數(shù),DD為天將把年數(shù)CCYY限定在1969--2068之內(nèi).MM為月數(shù),DD為天數(shù),hh?為小時(shí)數(shù)(幾點(diǎn)),mm為分鐘數(shù),SS為秒數(shù).此處秒的設(shè)定范圍是0--61,這樣可以處理閏秒.這些數(shù)字組成的時(shí)間是環(huán)境變量TZ指定的時(shí)區(qū)中的一個(gè)時(shí)?間.由于系統(tǒng)的限制,早于1970年1月1日的時(shí)間是錯(cuò)誤的。
?
7.?【命令】:echo
【功能說明】:
display a line of text ??#打印輸出
【語法格式】:
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -n | do not output the trailing newline | 不要在最后自動(dòng)換行 |
| -e | enable interpretation of backslash escapes | 若字符串中出現(xiàn)以下字符,則特別加以處理,而不會(huì)將它當(dāng)成一般文字輸出 ??\a 發(fā)出警告聲; |
| -E | disable interpretation of backslash escapes (default) | 不解釋轉(zhuǎn)意字符 |
【示例】:
1、基本用法:打印內(nèi)容
[root@oldboy data]# echo "I am studying linux."
I am studying linux.
?
2、打印變量內(nèi)容
[root@oldboy data]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
?
?
8.?【命令】:xargs
【功能說明】:
build and execute command lines from standard input ?#從標(biāo)準(zhǔn)輸入獲取內(nèi)容創(chuàng)建和執(zhí)行命令
【語法格式】:
xargs ?[-0prtx] ?[-E ?eof-str] ?[-e[eof-str]] ?[--eof[=eof-str]] [--null] [-d delimiter]
???????[--delimiter delimiter] ?[-I ?replace-str] ?[-i[replace-str]] ?[--replace[=replace-str]]
???????[-l[max-lines]] ?[-L max-lines] [--max-lines[=max-lines]] [-n max-args] [--max-args=max-
???????args] [-s ?max-chars] ?[--max-chars=max-chars] ?[-P ?max-procs] ?[--max-procs=max-procs]
???????[--interactive] ????[--verbose] ????[--exit] ???[--no-run-if-empty] ???[--arg-file=file]
???????[--show-limits] [--version] [--help] [command [initial-arguments]]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| ? | ? | ? |
【示例】:
1、基本用法:與find配合使用,刪除/data目錄下所有.txt文件
[root@oldboy ~]# find /data -type f -name "*.txt"|xargs rm -f
[root@oldboy ~]# cd /data
[root@oldboy data]# ll
total 0
?
?
?
9.?【命令】:mv
【功能說明】:
?move (rename) files #移動(dòng)或重命名文件
【語法格式】:
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| --backup[=CONTROL] | make a backup of each existing destination file | 備份模式:若需覆蓋文件,則覆蓋前先行備份 |
| -b | like --backup but does not accept an argument | 若需覆蓋文件,則覆蓋前先行備份。 |
| -f, --force | do not prompt before overwriting | force?強(qiáng)制的意思,如果目標(biāo)文件已經(jīng)存在,不會(huì)詢問而直接覆蓋 |
| -i, --interactive | prompt before overwrite | 若目標(biāo)文件?(destination)?已經(jīng)存在時(shí),就會(huì)詢問是否覆蓋 |
| -n, --no-clobber | do not overwrite an existing file | ? |
| -S, --suffix=SUFFIX | override the usual backup suffix | 為備份文件指定后綴,而不使用默認(rèn)的后綴; |
| -t, --target-directory=DIRECTORY | move all SOURCE arguments into DIRECTORY | 指定mv的目標(biāo)目錄,該選項(xiàng)適用于移動(dòng)多個(gè)源文件到一個(gè)目錄的情況,此時(shí)目標(biāo)目錄在前,源文件在后 |
| -T, --no-target-directory | treat DEST as a normal file | ? |
| -u, --update | move ?only ?when ?the ?SOURCE file is newer than the destination file or when the destination file is missing | 若目標(biāo)文件已經(jīng)存在,且?source?比較新,才會(huì)更新(update) |
| -v, --verbose | explain what is being done | 顯示程序執(zhí)行過程 |
【示例】:
1、基本用法:移動(dòng)文件
[root@oldboy ~]# mv ett.txt /root/data
[root@oldboy ~]# cd data
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar ?9 13:28 ett.txt
?
2、基本用法:移動(dòng)目錄
[root@oldboy ~]# mv /data /root
[root@oldboy ~]# ll
total 56
-rw-------. 1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root ?4096 Mar ?9 13:56 data
-rw-r--r--. 1 root root 22179 Mar ?3 23:14 install.log
?
3、更改文件名
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar ?9 13:28 ett.txt
[root@oldboy data]# mv ett.txt oldboy.txt
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root 292 Mar ?9 13:28 oldboy.txt
?
4、多個(gè)文件移動(dòng)到同一個(gè)目錄
[root@localhost?test3]#?mv?-t?/opt/soft/test/test4/?log1.txt?log2.txt? log3.txt?
[root@localhost?test3]#?cd?..
[root@localhost?test]#?cd?test4/
[root@localhost?test4]#?ll
總計(jì)?12
-rw-r--r--?1?root?root??8?10-28?06:15?log1.txt
-rw-r--r--?1?root?root?12?10-28?06:15?log2.txt
-rw-r--r--?1?root?root?13?10-28?06:16?log3.txt
?
?
10.?【命令】:rm
【功能說明】:
?remove files or directories #移除文件或目錄
【語法格式】:
rm [OPTION]... FILE...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -f, --force | ignore nonexistent files,never prompt | 忽略不存在的文件,從不給出提示 |
| -i | prompt before every removal | 進(jìn)行交互式刪除 |
| -I | prompt once before removing more than three files, or when removing ?recursively. Less intrusive than -i, while still giving protection against most mistakes | ? |
| -r, -R, --recursive | remove directories and their contents recursively | 指示rm將參數(shù)中列出的全部目錄和子目錄均遞歸地刪除 |
| -v, --verbose | explain what is being done | 顯示命令執(zhí)行過程 |
【示例】:
1、基本用法:刪除文件
[root@oldboy ~]# rm log1.txt
rm: remove regular file `log1.txt'? y
[root@oldboy ~]# ll
total 52
-rw-------. 1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root ?4096 Mar ?9 13:56 data
-rw-r--r--. 1 root root 22179 Mar ?3 23:14 install.log
-rw-r--r--. 1 root root ?5890 Mar ?3 23:13 install.log.syslog
-rw-r--r--. 1 root root ???44 Mar ?7 17:53 log2.txt
-rw-r--r--. 1 root root ???18 Mar ?9 13:19 oldboy.txt
?
2、基本用法:刪除目錄
[root@oldboy data]# rm -r a
rm: descend into directory `a'? y
rm: descend into directory `a/b'? y
rm: remove regular empty file `a/b/oldboy.txt'? y
rm: remove directory `a/b/c'? y
rm: remove directory `a/b'? y
rm: remove regular empty file `a/oldboy.txt'? y
rm: remove directory `a'? y
?
11.?【命令】:find
【功能說明】:
?search for files in a directory hierarchy #查找文檔
【語法格式】:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
【選項(xiàng)參數(shù)】:
| 參數(shù)或選項(xiàng) | 說明 | 簡解 |
| -atime n | File was last accessed n*24 hours ago. ?When find figures out ?how ?many ?24-hour periods ?ago ?the ?file ?was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. | 根據(jù)最后一次的訪問時(shí)間查找文件 |
| -ctime n | File’s status was last changed n*24 hours ago. ?See the comments ?for ?-atime ?to understand how rounding affects the interpretation of file status change times. | 根據(jù)最后一次的改變時(shí)間查找文件 |
| -mtime n | File’s data was last modified n*24 hours ago. ?See the ?comments ?for ?-atime ?to understand how rounding affects the interpretation of file modification times. | 根據(jù)最后一次的修改時(shí)間查找文件 |
| -type c | File is of type c: b ?????block (buffered) special c ?????character (unbuffered) special d ?????directory p ?????named pipe (FIFO) f ?????regular file l ?????symbolic ?link; ?this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. ?If you want ?to ?search for symbolic links when -L is in effect, use -xtype. s ?????socket D ?????door (Solaris) | 查找某一類型的文件 b ??塊設(shè)備文件 d ??目錄 c ??字符設(shè)備文件 p ??管道文件 l ???符號(hào)鏈接文件 f ??普通文件 s ??socket文件 |
| -name pattern | Base ?of ?file name (the path with the leading directories removed) matches shell pattern pattern. ?The metacharacters (‘*’, ‘?’, and ‘[]’) ?match ?a ?‘.’ ?at ?the start ?of ?the ?base name (this is a change in findutils-4.2.2; see section STAN-DARDS CONFORMANCE below). ?To ignore a directory and ?the ?files ?under ?it, ?use -prune; see an example in the description of -path. ?Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. ?The filename matching is performed with the use of the fnmatch(3) library function. ??Don’t forget to enclose the pattern ?in quotes in order to protect it from expansion by the shell. | 按文件名查找文件 |
| -perm mode | File’s ?permission ?bits ?are ?exactly ?mode (octal or symbolic). ?Since an exact match is required, if you want to use this form for symbolic modes, you may ?have ?to specify a rather complex mode string. ?For example ‘-perm g=w’ will only match files which have mode 0020 (that is, ones for which group write permission is the only permission set). ?It is more likely that you will want to use the ‘/’ or ‘-’ forms, for example ‘-perm -g=w’, which matches any file with group write ?permis- sion. ?See the EXAMPLES section for some illustrative examples. | 按照文件權(quán)限來查找文件 |
| -size n[cwbkMG] | File ?uses ?n ?units ?of space. ?The following suffixes can be used: ‘b’ ???for 512-byte blocks (this is the default if ?no ?suffix is used) ‘c’ ???for bytes ‘w’ ???for two-byte words ‘k’ ???for Kilobytes (units of 1024 bytes) ‘M’ ???for Megabytes (units of 1048576 bytes) ‘G’ ???for Gigabytes (units of 1073741824 bytes) ? | 按大小查找 |
【示例】:
1、基本用法:按文件名查找文件
[root@oldboy ~]# find /root/data -name "*.txt"
/root/data/oldboy.txt
?
2、基本用法:按文件類型查找文件
[root@oldboy ~]# find /root/data -type f
/root/data/oldboy.txt
?
3、查找文件名稱不為oldboy.txt的所有文件
[root@oldboy ~]# ll
total 52
-rw-------. 1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
drwxr-xr-x. 2 root root ?4096 Mar ?9 15:09 data
-rw-r--r--. 1 root root 22179 Mar ?3 23:14 install.log
-rw-r--r--. 1 root root ?5890 Mar ?3 23:13 install.log.syslog
-rw-r--r--. 1 root root ???44 Mar ?7 17:53 log2.txt
-rw-r--r--. 1 root root ???18 Mar ?9 13:19 oldboy.txt
[root@oldboy ~]# find /root ! -name "oldboy.txt"
/root
/root/.bash_history
/root/.bashrc
/root/.bash_logout
/root/.bash_profile
/root/data
/root/install.log
/root/log2.txt
/root/.lesshst
/root/.cshrc
/root/anaconda-ks.cfg
/root/install.log.syslog
/root/.tcshrc
?
4、利用find查找刪除擴(kuò)展名為txt的所有文件
[root@oldboy data]# ll
total 4
-rw-r--r--. 1 root root ??0 Mar ?9 16:13 1.txt
-rw-r--r--. 1 root root ??0 Mar ?9 16:13 2.txt
-rw-r--r--. 1 root root ??0 Mar ?9 16:13 3.txt
-rw-r--r--. 1 root root 292 Mar ?9 13:28 oldboy.txt
[root@oldboy data]# find /root/data -type f -name "*.txt"|xargs rm -f
[root@oldboy data]# ll
total 0
?
【說明】:
1、按修改時(shí)間查找文件,+7表示距今天7天以前,7表示距今天整7天,-7表示最近7天
2、-o表示或者的意思,-a表示并且的意思,!表示取反
?
?
12.?【命令】:grep
【功能說明】:
?print lines matching a pattern #用于過濾、搜索特定字符
【語法格式】:
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a, --text | Process ??a ?binary ?file ?as ?if ?it ?were ?text; ?this ?is ?equivalent ?to ?the --binary-files=text option. | 不要忽略二進(jìn)制的數(shù)據(jù) |
| -A NUM , --after-context=NUM | Print ?NUM ?lines ?of ?trailing ?context ?after ?matching ?lines. ??Places a line containing ?a ?group ?separator ?(described ?under ??--group-separator) ??between contiguous groups of matches. ?With the -o or --only-matching option, this has no effect and a warning is given. | 除了顯示符合范本樣式的那一列之外,并顯示該行之后的內(nèi)容 |
| -b, --byte-offset | Print ?the ?0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print ?the ?offset ?of ?the ?matching ?part ?itself. | 在顯示符合樣式的那一行之前,標(biāo)示出該行第一個(gè)字符的編號(hào) |
| -B NUM, --before-context=NUM | Print NUM lines ?of ?leading ?context ?before ?matching ?lines. ??Places ?a ?line containing ??a ??group ?separator ?(described ?under ?--group-separator) ?between contiguous groups of matches. ?With the -o or --only-matching option, this has no effect and a warning is given. | 除了顯示符合樣式的那一行之外,并顯示該行之前的內(nèi)容 |
| -c, --count | Suppress ?normal ?output; ?instead print a count of matching lines for each input ?file. With the -v, --invert-match option (see below), count non-matching ?lines. (-c is specified by POSIX.) | 計(jì)算符合樣式的列數(shù) |
| -C NUM, -NUM, --context=NUM | Print ?NUM ?lines ?of output context. ?Places a line containing a group separator (described under --group-separator) between contiguous groups of ?matches. ??With the -o or --only-matching option, this has no effect and a warning is given. | 除了顯示符合樣式的那一行之外,并顯示該行之前后各n行內(nèi)容 |
| -d ACTION, --directories=ACTION | If an input file is a directory, use ACTION to process it. ?By default, ACTION is read, ?i.e., ?read directories just as if they were ordinary files. ?If ACTION is skip, silently skip directories. ?If ACTION is recurse, read all files under each directory, ?recursively, following symbolic links only if they are on the command line. ?This is equivalent to the -r option. | 當(dāng)指定要查找的是目錄而非文件時(shí),必須使用這項(xiàng)參數(shù),否則grep指令將回報(bào)信息并停止動(dòng)作。 |
| -e PATTERN, --regexp=PATTERN | Use ?PATTERN ?as ?the ?pattern. ??This ?can ?be ?used ?to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). ?(-e is ?specified by POSIX.) | 使用正則表達(dá)式 |
| -E, --extended-regexp | Interpret PATTERN as an extended regular expression (ERE, ?see ?below). ??(-E is specified by POSIX.) | 使用拓展的正則表達(dá)式 |
| -f FILE, --file=FILE | Obtain ?patterns from FILE, one per line. ?The empty file contains zero patterns, and therefore matches nothing. ?(-f is specified by POSIX.) | 指定規(guī)則文件,其內(nèi)容含有一個(gè)或多個(gè)規(guī)則樣式,讓grep查找符合規(guī)則條件的文件內(nèi)容,格式為每行一個(gè)規(guī)則樣式。 |
| -h, --no-filename | Suppress the prefixing of file names on output. ?This is the default ?when ?there is only one file (or only standard input) to search. | 在顯示符合樣式的那一行之前,不標(biāo)示該行所屬的文件名稱。 |
| -H, --with-filename | Print ?the file name for each match. ?This is the default when there is more than one file to search. | 在顯示符合樣式的那一行之前,表示該行所屬的文件名稱。 |
| -i, --ignore-case | Ignore case distinctions in both ?the ?PATTERN ?and ?the ?input ?files. ??(-i is specified by POSIX.) | 忽略字符大小寫的差別。 |
| -l, --files-with-matches | Suppress normal output; instead print the name of ?each ?input ?file ?from ?which output ?would ?normally ?have ?been printed. ?The scanning will stop on the first match. ?(-l is specified by POSIX.) | 列出文件內(nèi)容符合指定的樣式的文件名稱。 |
| -L, --files-without-match | Suppress normal output; instead print the name of each input file from ?which ?no output ?would ?normally ?have ?been printed. ?The scanning will stop on the first match. | 列出文件內(nèi)容不符合指定的樣式的文件名稱。 |
| -n, --line-number | Prefix ?each ?line ?of output with the 1-based line number within its input file. (-n is specified by POSIX.) | 在顯示符合樣式的那一行之前,標(biāo)示出該行的列數(shù)編號(hào)。 |
| -q, --quiet, --silent | Quiet; do not write anything to standard ?output. ??Exit ?immediately ?with ?zero status ?if any match is found, even if an error was detected. ?Also see the -s or --no-messages option. ?(-q is specified by POSIX.) | 不顯示任何信息。 |
| -r, --recursive | Read ?all ?files under each directory, recursively, following symbolic links only if they are on the command line. ?This is equivalent to the -d recurse option. | 如果文件參數(shù)是目錄,該選項(xiàng)將遞歸搜索該目錄下的所有子目錄和文件。同-R |
| -s, --no-messages | Suppress error messages about nonexistent or unreadable files. ?Portability note: unlike ?GNU ?grep, ?7th ?Edition ?Unix ?grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep’s -q ?option. ??USG-style ?grep also ?lacked ?-q but its -s option behaved like GNU grep. ?Portable shell scripts should avoid both -q and -s and should redirect ?standard ?and ?error ?output ?to /dev/null instead. ?(-s is specified by POSIX.) | 不顯示錯(cuò)誤信息。 |
| -v, --invert-match | Invert ?the sense of matching, to select non-matching lines. ?(-v is specified by POSIX.) | 顯示不包含匹配文本的所有行。 |
| -V, --version | Print ?the ?version ?number ?of grep to the standard output stream. ?This version number should be included in all bug reports (see below). | 顯示版本信息。 |
| -w, --word-regexp | Select only those lines containing matches that form whole words. ??The ?test ?is that ?the ?matching ?substring ?must ?either ?be at the beginning of the line, or preceded by a non-word constituent character. ?Similarly, it must ?be ?either ?at ?the ?end ?of ?the ?line ?or ?followed by a non-word constituent character. ?Word- constituent characters are letters, digits, and the underscore. | 只顯示完整單詞的匹配 |
| -x, --line-regexp | Select only those matches that exactly match the whole line. ?(-x is specified by POSIX.) | 只顯示完整行的匹配 |
【示例】:
1、基本用法:顯示文件中包含字符串的行
[root@oldboy ~]# cat oldboy.txt
test
liyao
oldboy
[root@oldboy ~]# grep "oldboy" oldboy.txt
oldboy
[root@oldboy ~]#
?
2、基本用法:顯示文件中不包含字符串的行
[root@oldboy ~]# grep -v "oldboy" oldboy.txt
test
liyao
?
3、除了顯示匹配的一行外,并顯示該行之后的n行
[root@oldboy ~]# grep 20 -A 10 test.txt
20
21
22
23
24
25
26
27
28
29
30
?
?
【說明】:
grep的正則表達(dá)式:
^??#錨定行的開始?如:'^grep'匹配所有以grep開頭的行。????
$??#錨定行的結(jié)束?如:'grep$'匹配所有以grep結(jié)尾的行。????
.??#匹配一個(gè)非換行符的字符?如:'gr.p'匹配gr后接一個(gè)任意字符,然后是p。????
*??#匹配零個(gè)或多個(gè)先前字符?如:'*grep'匹配所有一個(gè)或多個(gè)空格后緊跟grep的行。????
.*???#一起用代表任意字符。???
[]???#匹配一個(gè)指定范圍內(nèi)的字符,如'[Gg]rep'匹配Grep和grep。????
[^]??#匹配一個(gè)不在指定范圍內(nèi)的字符,如:'[^A-FH-Z]rep'匹配不包含A-R和T-Z的一個(gè)字母開頭,緊跟rep的行。????
\(..\)??#標(biāo)記匹配字符,如'\(love\)',love被標(biāo)記為1。????
\<??????#錨定單詞的開始,如:'\<grep'匹配包含以grep開頭的單詞的行。????
\>??????#錨定單詞的結(jié)束,如'grep\>'匹配包含以grep結(jié)尾的單詞的行。????
x\{m\}??#重復(fù)字符x,m次,如:'0\{5\}'匹配包含5個(gè)o的行。????
x\{m,\}??#重復(fù)字符x,至少m次,如:'o\{5,\}'匹配至少有5個(gè)o的行。????
x\{m,n\}??#重復(fù)字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配5--10個(gè)o的行。???
\w????#匹配文字和數(shù)字字符,也就是[A-Za-z0-9],如:'G\w*p'匹配以G后跟零個(gè)或多個(gè)文字或數(shù)字字符,然后是p。???
\W????#\w的反置形式,匹配一個(gè)或多個(gè)非單詞字符,如點(diǎn)號(hào)句號(hào)等。???
\b????#單詞鎖定符,如:?'\bgrep\b'只匹配grep。??
?
POSIX字符:
????為了在不同國家的字符編碼中保持一至,POSIX(The?Portable?Operating?System?Interface)增加了特殊的字符類,如[:alnum:]是[A-Za-z0-9]的另一個(gè)寫法。要把它們放到[]號(hào)內(nèi)才能成為正則表達(dá)式,如[A-?Za-z0-9]或[[:alnum:]]。在linux下的grep除fgrep外,都支持POSIX的字符類。
[:alnum:]????#文字?jǐn)?shù)字字符???
[:alpha:]????#文字字符???
[:digit:]????#數(shù)字字符???
[:graph:]????#非空字符(非空格、控制字符)???
[:lower:]????#小寫字符???
[:cntrl:]????#控制字符???
[:print:]????#非空字符(包括空格)???
[:punct:]????#標(biāo)點(diǎn)符號(hào)???
[:space:]????#所有空白字符(新行,空格,制表符)???
[:upper:]????#大寫字符???
[:xdigit:]???#十六進(jìn)制數(shù)字(0-9,a-f,A-F)
?
13.?【命令】:head
【功能說明】:
output the first part of files ?#打印文件的前幾行
【語法格式】:
head [OPTION]... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c, --bytes=[-]K | print the first K bytes of each file; with ?the ?leading ?‘-’,print all but the last K bytes of each file | 按前K字節(jié)打印文件 |
| -n, --lines=[-]K | print ?the ?first ?K ?lines ?instead of the first 10; with the leading ‘-’, print all but the last K lines of each file | 按前K行打印文件 |
| -q, --quiet, --silent | never print headers giving file names | 隱藏文件名 |
| -v, --verbose | always print headers giving file names | 顯示文件名 |
| ? | ? | ? |
【示例】:
1、基本用法:打印文件前幾行
[root@oldboy ~]# head -n 13 test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
?
2、打印文件前K個(gè)字節(jié)
[root@oldboy ~]# head -c 20 test.txt
1
2
3
4
5
6
7
8
9
10[root@oldboy ~]#
?
3、顯示文件名
[root@oldboy ~]# head -v test.txt
==> test.txt <==
1
2
3
4
5
6
7
8
9
10
?
14.?【命令】:cp
【功能說明】:
copy files and directories ?#復(fù)制文件或目錄
【語法格式】:
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a, --archive | same as -dR --preserve=all | 保持源文件的原有結(jié)構(gòu)和屬性,與選項(xiàng)“-dpR”相同 |
| --backup[=CONTROL] | make a backup of each existing destination file | 做一個(gè)已存在文件的備份 |
| -b | like --backup but does not accept an argument | 覆蓋已存在的目標(biāo)文件前將目標(biāo)文件備份 |
| --copy-contents | copy contents of special files when recursive | ? |
| -d | same as --no-dereference --preserve=links | 如果復(fù)制的源文件是符號(hào)鏈接,僅復(fù)制符號(hào)鏈接本身,而且保留符號(hào)鏈接所指向的目標(biāo)文件或目錄 |
| -f, --force | if an existing destination file cannot be ?opened, ?remove ?it and try again (redundant if the -n option is used) | 強(qiáng)制覆蓋已經(jīng)存在的目標(biāo)文件,不提示用戶確認(rèn) |
| -i, --interactive | prompt before overwrite (overrides a previous -n option) | 在覆蓋已存在的目標(biāo)文件前提示用戶進(jìn)行確認(rèn) |
| -H | follow command-line symbolic links in SOURCE | ? |
| -l, --link | link files instead of copying | 為源文件創(chuàng)建硬鏈接 |
| -L, --dereference | always follow symbolic links in SOURCE | ? |
| -n, --no-clobber | do ?not ?overwrite ?an ?existing file (overrides a previous -i option) | ? |
| -P, --no-dereference | never follow symbolic links in SOURCE | ? |
| -p | same as --preserve=mode,ownership,timestamps | 復(fù)制文件時(shí)保持源文件的所有者、權(quán)限信息以及時(shí)間屬性 |
| --preserve[=ATTR_LIST] | preserve ?the ?specified ?attributes ??(default: ??mode,owner-ship,timestamps), ?if possible additional attributes: context, links, xattr, all | ? |
| -c | same as --preserve=context | ? |
| --no-preserve=ATTR_LIST | don’t preserve the specified attributes | ? |
| --parents | use full source file name under DIRECTORY | ? |
| -R, -r, --recursive | copy directories recursively | 對目錄進(jìn)行復(fù)制操作,采用遞歸的操作方式 |
| --reflink[=WHEN] | control clone/CoW copies. See below. | ? |
| --remove-destination | remove each existing destination ?file ?before ?attempting ?to ?open it (contrast with --force) | ? |
| --sparse=WHEN | control creation of sparse files. See below. | ? |
| --strip-trailing-slashes | remove any trailing slashes from each SOURCE argument | ? |
| -s, --symbolic-link | make symbolic links instead of copying | 為源文件創(chuàng)建符號(hào)鏈接 |
| -S, --suffix=SUFFIX | override the usual backup suffix | 在備份文件時(shí),用指定的后綴“SUFFIX”代替文件名的默認(rèn)后綴 |
| -t, --target-directory=DIRECTORY | copy all SOURCE arguments into DIRECTORY | ? |
| -T, --no-target-directory | treat DEST as a normal file | ? |
| -u, --update | copy ?only ?when the SOURCE file is newer than the destination file or when the destination file is missing | 當(dāng)目標(biāo)文件不存在或者源文件比目標(biāo)文件新時(shí)才進(jìn)行復(fù)制操作 |
| -v, --verbose | explain what is being done | 詳細(xì)顯示指令執(zhí)行的操作 |
| -x, --one-file-system | stay on this file system | 復(fù)制的文件或目錄存放的文件系統(tǒng),必須與cp指令執(zhí)行時(shí)所處的文件系統(tǒng)相同,否則不復(fù)制,亦不處理位于其他分區(qū)的文件 |
| -Z, --context=CONTEXT | set security context of copy to CONTEXT | ? |
【示例】:
1、基本用法:復(fù)制文件到指定位置
[root@oldboy ~]# cp test.txt data
[root@oldboy ~]# cat data/test.txt
1
2
3
4
5
6
7
?
2、基本用法:復(fù)制目錄到指定位置
[root@oldboy ~]# cp -r /root/data /tmp
[root@oldboy ~]# cd /tmp/data
[root@oldboy data]#
?
3、復(fù)制時(shí)保持文件屬性
[root@oldboy ~]# ll
total 56
-rw-------. 1 root root ?1079 Mar ?3 23:14 anaconda-ks.cfg
drwxr-xr-x. 7 root root ?4096 Mar 13 16:25 data
-rw-r--r--. 1 root root 22179 Mar ?3 23:14 install.log
-rw-r--r--. 1 root root ?5890 Mar ?3 23:13 install.log.syslog
-rw-r--r--. 1 root root ???44 Mar ?7 17:53 log2.txt
-rw-r--r--. 1 root root ???18 Mar ?9 13:19 oldboy.txt
-rw-r--r--. 1 root root ??292 Mar 13 15:13 test.txt
[root@oldboy ~]# cp -p test.txt /tmp
[root@oldboy ~]# ll /tmp
total 108
drwxr-xr-x ?7 root root ??4096 Mar 13 16:28 data
-rw-r--r-- ?1 root root ???292 Mar 13 15:13 test.txt
-rw-------. 1 root root ?????0 Mar ?3 23:09 yum.log
-rw-------. 1 root root 100203 Mar ?4 00:39 yum_save_tx-2016-03-04-00-39i_5ZVm.yumtx
?
?
15.?【命令】:tail
【功能說明】:
output the last part of files ?#打印文件末尾幾行
【語法格式】:
tail [OPTION]... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c, --bytes=K | output the last K bytes; alternatively, use -c ?+K ?to ?output bytes starting with the Kth of each file | 輸出文件尾部的N個(gè)字節(jié)內(nèi)容 |
| -f, --follow[={name|descriptor}] | output ?appended ?data ?as ?the ?file grows; -f, --follow, and --follow=descriptor are equivalent | 顯示文件最新追加的內(nèi)容 |
| -F | same as --follow=name --retry | 與選項(xiàng)“--follow=name”和“--retry”連用時(shí)的功能相同 |
| -n, --lines=K | output the last K lines, instead of the last 10; or use -n ?+K ?to output lines starting with the Kth | 輸出文件尾部K行內(nèi)容 |
| --max-unchanged-stats=N | with ?--follow=name, ?reopen a FILE which has not changed size after N (default 5) iterations to see if it has been ?unlinked or ?renamed ?(this ?is ?the ?usual case of rotated log files). With inotify, this option is rarely useful. | 參看texinfo文檔(默認(rèn)為5) |
| --pid=PID | with -f, terminate after process ID, PID dies | 與-f合用,表示在進(jìn)程ID,PID死掉之后結(jié)束 |
| -q, --quiet, --silent | never output headers giving file names | 不顯示文件名 |
| --retry | keep trying to open a file even when it is or becomes inacces-sible; useful when following by name, i.e., with --follow=name | 即使文件不可訪問或者文件稍后變得不可訪問,都始終嘗試打開文件 |
| -s, --sleep-interval=N | with -f, sleep ?for ?approximately ?N ?seconds ?(default ?1.0) between iterations. ? With ?inotify and --pid=P, check process P at least once every N seconds. | 與“-f”連用,指定監(jiān)視文件變化時(shí)間所間隔的秒數(shù) |
| -v, --verbose | always output headers giving file names | 總在開頭顯示文件名 |
【示例】:
1、基本用法:顯示文件末尾的n行
[root@oldboy ~]# tail -8 test.txt
93
94
95
96
97
98
99
100
?
2、在開頭顯示文件名
[root@oldboy ~]# tail -v -n 8 test.txt
==> test.txt <==
93
94
95
96
97
98
99
100
?
16.?【命令】:alias
【功能說明】:
Define or display aliases. ?#顯示或設(shè)置別名
【語法格式】:
alias [-p] [name[=value] ... ]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -p | Print all defined aliases in a reusable format | 打印已經(jīng)設(shè)置的命令別名 |
【示例】:
1、基本用法:打印已經(jīng)設(shè)置的別名(-p可以省略)
[root@oldboy ~]# alias -p
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
?
2、基本用法:設(shè)置新別名
[root@oldboy ~]# alias rm='echo "Do not use rm!"'
[root@oldboy ~]# rm -f test.txt
Do not use rm! -f test.txt
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='echo "Do not use rm!"'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
?
?
17.?【命令】:unalias
【功能說明】:
Remove each NAME from the list of defined aliases. ?#取消別名
【語法格式】:
unalias [-a] name [name ...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | remove all alias definitions. | 取消所有別名 |
【示例】:
1、基本用法:取消別名
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='echo "Do not use rm!"'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldboy ~]# unalias rm
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
?
2、取消所有別名
[root@oldboy ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldboy ~]# unalias -a
[root@oldboy ~]# alias
[root@oldboy ~]#
?
18.?【命令】:seq
【功能說明】:
print a sequence of numbers ?#生成數(shù)字序列
【語法格式】:
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -f, --format=FORMAT | use printf style floating-point FORMAT | 格式化輸出 |
| -s, --separator=STRING | use STRING to separate numbers (default: \n) | 指定分隔符,默認(rèn)是換行符 |
| -w, --equal-width | equalize width by padding with leading zeroes | 輸出同寬數(shù)列,不足的位數(shù)用0補(bǔ)齊 |
【示例】:
1、基本用法:生成數(shù)字序列
[root@oldboy ~]# seq 10
1
2
3
4
5
6
7
8
9
10
?
2、格式化輸出
[root@oldboy ~]# seq -f 100%g 10
1001
1002
1003
1004
1005
1006
1007
1008
1009
10010
3、指定分隔符
[root@oldboy ~]# seq -s "..." 10
1...2...3...4...5...6...7...8...9...10
[root@oldboy ~]#?
?
4、輸出同寬數(shù)列
[root@oldboy ~]# seq -w 10
01
02
03
04
05
06
07
08
09
10
?
19.?【命令】:sed
【功能說明】:
stream editor for filtering and transforming text ?#用于過濾和轉(zhuǎn)化文本的流編輯器
【語法格式】:
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -n, --quiet, --silent | suppress automatic printing of pattern space | 取消默認(rèn)輸出,只顯示操作過的那一行 |
| -e script, --expression=script | add the script to the commands to be executed | 直接在命令列模式上進(jìn)行sed的動(dòng)作編輯 |
| -f script-file, --file=script-file | add the contents of script-file to the commands to be executed | 運(yùn)行腳本內(nèi)的動(dòng)作 |
| --follow-symlinks | follow symlinks when processing ?in ?place; ?hard ?links ?will still be broken | ? |
| -i[SUFFIX], --in-place[=SUFFIX] | edit files in place (makes backup if extension supplied). ?The default operation mode is to break symbolic ?and ?hard ?links.This can be changed with --follow-symlinks and --copy | 直接修改讀取的文件內(nèi)容 |
| -c, --copy | use ?copy ?instead ?of rename when shuffling files in -i mode. While this will avoid breaking links (symbolic or ?hard), ?the resulting editing operation is not atomic. ?This is rarely the desired mode; --follow-symlinks is usually enough, and ?it ?is ?both faster and more secure. | ? |
| -l N, --line-length=N | specify the desired line-wrap length for the ‘l’ command | ? |
| --posix | disable all GNU extensions. | ? |
| -r, --regexp-extended | use extended regular expressions in the script | 在腳本中應(yīng)用拓展的正則表達(dá)式 |
| -s, --separate | consider ?files as separate rather than as a single continuous long stream | ? |
| -u, --unbuffered | load minimal amounts of data from the input ?files ?and ?flush ?the output buffers more often | ? |
?
【示例】:
1、基本用法:僅列出 /etc/passwd 文件內(nèi)的第 5-7 行
[root@oldboy ~]# nl /etc/passwd | sed -n '5,7p'
?????5 ?lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
?????6 ?sync:x:5:0:sync:/sbin:/bin/sync
?????7 ?shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
?
2、利用sed替換取IP地址
[root@oldboy ~]# ifconfig eth0 ?????
eth0 ?????Link encap:Ethernet ?HWaddr 00:0C:29:9C:9A:32 ?
??????????inet addr:10.0.0.8 ?Bcast:10.0.0.255 ?Mask:255.255.255.0
??????????inet6 addr: fe80::20c:29ff:fe9c:9a32/64 Scope:Link
??????????UP BROADCAST RUNNING MULTICAST ?MTU:1500 ?Metric:1
??????????RX packets:641 errors:0 dropped:0 overruns:0 frame:0
??????????TX packets:321 errors:0 dropped:0 overruns:0 carrier:0
??????????collisions:0 txqueuelen:1000
??????????RX bytes:56546 (55.2 KiB) ?TX bytes:40576 (39.6 KiB)
?
[root@oldboy ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's#^.*addr:##g' | sed 's#Bcast.*$##g'
10.0.0.8
?
3、直接修改文件內(nèi)容
[root@oldboy ~]# cat test.txt
1
2
3
4
5
6
7
8
9
10
[root@oldboy ~]# sed -i 's#5#500#g' test.txt
[root@oldboy ~]# cat test.txt
1
2
3
4
500
6
7
8
9
10
?
【特別說明】:
動(dòng)作說明: [n1[,n2]]function
n1, n2 :不見得會(huì)存在,一般代表『選擇進(jìn)行動(dòng)作的行數(shù)』,舉例來說,如果我的動(dòng)作是需要在 10 到 20 行之間進(jìn)行的,則『 10,20[動(dòng)作行為] 』
function:
a :新增, a 的后面可以接字串,而這些字串會(huì)在新的一行出現(xiàn)(目前的下一行)~
c :取代, c 的后面可以接字串,這些字串可以取代 n1,n2 之間的行!
d :刪除,因?yàn)槭莿h除啊,所以 d 后面通常不接任何咚咚;
i :插入, i 的后面可以接字串,而這些字串會(huì)在新的一行出現(xiàn)(目前的上一行);
p :打印,亦即將某個(gè)選擇的數(shù)據(jù)印出。通常 p 會(huì)與參數(shù) sed -n 一起運(yùn)行~
s :取代,可以直接進(jìn)行取代的工作哩!通常這個(gè) s 的動(dòng)作可以搭配正則表達(dá)式!例如 1,20s#old#new#g 就是啦!
?
20.?【命令】:man
【功能說明】:
format and display the on-line manual pages ?#查看在線幫助手冊
【語法格式】:
man [-acdDfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]
???????[-M pathlist] ?[-P ?pager] ?[-B ?browser] ?[-H ?htmlpager] ?[-S ?sec-
???????tion_list] [section] name ...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| ? | ? | ? |
| ? | ? | ? |
| ? | ? | ? |
【示例】:
1、基本用法:查看在線幫助
[root@oldboy ~]# man ls
LS(1) ???????????????????????????User Commands ??????????????????????????LS(1)
?
NAME
???????ls - list directory contents
?
SYNOPSIS
???????ls [OPTION]... [FILE]...
以下省略
?
?
21.?【命令】:useradd
【功能說明】:
create a new user or update default new user information ??#創(chuàng)建新用戶或更新默認(rèn)新用戶的信息
【語法格式】:
useradd [options] LOGIN
useradd -D
useradd -D [options]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c, --comment COMMENT | Any text string. It is generally a short description of the login, and is currently used as the field for the user's full name. | 加上備注文字 |
| -d, --home HOME_DIR | The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The parent directory of HOME_DIR must exist otherwise the home directory cannot be created. | 指定用戶登入時(shí)的起始目錄 |
| -D, ?defaults | See below, the subsection "Changing the default values". | 變更預(yù)設(shè)值 |
| -e, --expiredate EXPIRE_DATE | The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD. ? If not specified, useradd will use the default ?expiry date specified by the EXPIRE variable in /etc/default/useradd, or an empty string (no expiry) by default. | 指定賬號(hào)的有效期限 |
| -f, --inactive INACTIVE | The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of -1 disables the feature. ? If not specified, useradd will use the default ?inactivity period specified by the INACTIVE variable ?in /etc/default/useradd, or -1 by default. | 指定在密碼過期后多少天即關(guān)閉該賬號(hào) |
| -g, --gid GROUP | The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group. | 指定用戶所屬的群組 |
| -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] | A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. The default is for ?the user to belong only to the initial group. | 指定用戶所屬的附加群組 |
| -m, --create-home | Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. ? | 自動(dòng)建立用戶的登入目錄 |
| -M | Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes. | 不要自動(dòng)建立用戶的登入目錄 |
| -N, --no-user-group | Do not create a group with the same name as the user, but add the user to the group specified by the -g option or by the GROUP variable in /etc/default/useradd. | 取消建立以用戶名稱為名的群組 |
| -r, --system | Create a system account. | 建立系統(tǒng)賬號(hào) |
| -s, --shell SHELL | The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default. | 指定用戶登入后使用的shell |
| -u, --uid UID | The numerical value of the user's ID. This value must be unique, unless the -o option is used. The value must be non-negative. The default is to use the smallest ID value greater than or equal to UID_MIN and greater than every other user. | 指定用戶ID |
【示例】:
1、基本用法:創(chuàng)建新用戶
[root@oldboy ~]# useradd test
[root@oldboy ~]# cat /etc/passwd|tail -1
test:x:501:501::/home/test:/bin/bash
?
22.?【命令】:passwd
【功能說明】:
update user’s authentication tokens ?#為用戶設(shè)置或修改密碼
【語法格式】:
passwd ?[-k] ?[-l] ?[-u [-f]] [-d] [-e] [-n mindays] [-x
???????maxdays] [-w warndays] [-i inactivedays] [-S] ?[--stdin]
???????[username]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -d | This ?is ?a quick way to delete a password for an account. It will set the named account ?password-less. Available to root only. | 刪除密碼,僅有系統(tǒng)管理者才能使用 |
| -k | The option -k, ?is ?used ?to ?indicate ?that ?the update ?should only be for expired authentication tokens (passwords); the user wishes to keep their non-expired tokens as before. | 設(shè)置只有在密碼過期失效后,方能更新 |
| -l | This option is used to lock the specified account and it is available to root only. The locking ?is performed ?by ?rendering ?the ?encrypted password into ?an ?invalid ?string ??(by ??prefixing ??the ?encrypted string with an !). | 鎖住密碼 |
| -S | This will output a short ?information ?about ?the ?status ?of ?the ?password ?for ?a ?given account.Available to root user only. | 列出密碼的相關(guān)信息,僅有系統(tǒng)管理者才能使用 |
| -u | This ?is ?the ?reverse of the -l option - it will unlock the account password ?by ?removing ?the ?!prefix. This option is available to root only. By default passwd will refuse to create a ?password-less ?account (it will not unlock an account that has only "!" as a password). The force option ?-f ?will override this protection. | 解開已上鎖的賬號(hào) |
【示例】:
1、基本用法:設(shè)置用戶密碼
[root@oldboy ~]# passwd oldboy
Changing password for user oldboy.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
?
?
23.?【命令】:uname
【功能說明】:
print system information ?#打印系統(tǒng)信息
【語法格式】:
uname [OPTION]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a, --all | print all information, in ?the ?following ?order, except omit -p and -i if unknown: | 顯示全部的信息 |
| -s, --kernel-name | print the kernel name | 顯示操作系統(tǒng)類型 |
| -n, --nodename | print the network node hostname | 顯示主機(jī)名 |
| -r, --kernel-release | print the kernel release | 顯示核心版本號(hào) |
| -v, --kernel-version | print the kernel version | 顯示操作系統(tǒng)的版本 |
| -m, --machine | print the machine hardware name | 顯示機(jī)器架構(gòu)類型 |
| -p, --processor | print the processor type or "unknown" | ? |
| -i, --hardware-platform | print the hardware platform or "unknown" | 顯示硬件平臺(tái) |
| -o, --operating-system | print the operating system | 顯示操作系統(tǒng) |
【示例】:
1、基本用法:顯示全部信息
[root@oldboy ~]# uname -a
Linux oldboy 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
?
2、基本用法:顯示主機(jī)名
[root@oldboy ~]# uname -n
oldboy
?
3、顯示核心版本號(hào)
[root@oldboy ~]# uname -r
2.6.32-573.el6.x86_64
?
4、顯示機(jī)器架構(gòu)類型
[root@oldboy ~]# uname -m
x86_64
?
?
24.?【命令】:hostname
【功能說明】:
show or set the system’s host name ?#顯示和設(shè)置主機(jī)名
【語法格式】:
hostname ??[-v] ?[-a] ?[--alias] ?[-d] ?[--domain] ?[-f]
???????[--fqdn] [-A] ?[--all-fqdns] ?[-i] ?[--ip-address] ?[-I]
???????[--all-ip-addresses] [--long] [-s] [--short] [-y] [--yp]
???????[--nis]
hostname [-v] [-F filename] [--file filename] [hostname]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -v, --verbose | Be verbose and tell what’s going on. | 詳細(xì)信息模式 |
| -a, --alias | Display the alias name of the host (if used) | 顯示主機(jī)別名 |
| -d, --domain | Display the name of the DNS domain. Don’t use the ?command ?domainname ?to ?get ?the DNS domain name because it will show the NIS domain name and ?not ?the DNS domain name. Use dnsdomainname instead. | 顯示DNS域名 |
| -f, --fqdn, --long | Display the FQDN (Fully Qualified Domain Name). A FQDN ?consists ?of ?a short host name and the DNS domain name. Unless you are using bind or NIS for host ?lookups you can change the FQDN and the DNS domain name (which is part of the ?FQDN) ?in ?the /etc/hosts ?file. See the warnings in section THE FQDN above, and ?avoid ?using ?this ?option; ?use hostname --all-fqdns instead | 顯示FQDN名稱 |
| -i, --ip-address | Display the IP address(es) of the host. Note that this works only if the host name can be resolved. Avoid using this option; use ?hostname ?--all-ip- addresses instead | 顯示主機(jī)的ip地址 |
| -s, --short | Display ?the ?short ?host ?name. This is the host name cut at the first dot. | 顯示短主機(jī)名稱,在第一個(gè)點(diǎn)處截?cái)?/p> |
| -y, --yp, --nis | Display ?the ?NIS ?domain name. If a parameter is given (or --file name ) then root can also set ?a new NIS domain | 顯示NIS域名 |
【示例】:
1、基本用法:顯示主機(jī)名
[root@oldboy ~]# hostname
oldboy
?
2、基本用法:修改主機(jī)名
[root@oldboy ~]# hostname oldgirl
[root@oldboy ~]# hostname
oldgirl
?
?
25.?【命令】:runlevel
【功能說明】:
output previous and current runlevel ?#查看系統(tǒng)運(yùn)行狀態(tài)
【語法格式】:
runlevel [OPTION]... ?[UTMP]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| --quiet | Does ?not ?output ?the ?current and previous run-level, nor does it output unknown in the case ?of error (but it will exit with an error code). ? This ?may ?be ?used to test for the presence of a runlevel entry, or to check ?for ?errors ?reading from the file. | 不顯示當(dāng)前運(yùn)行狀態(tài) |
【示例】:
1、基本用法:查看系統(tǒng)運(yùn)行狀態(tài)
[root@oldboy ~]# runlevel
N 3
?
?
26.?【命令】:init
【功能說明】:
Upstart process management daemon ?#設(shè)置系統(tǒng)運(yùn)行狀態(tài)
【語法格式】:
init [OPTION]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -v, --verbose | Outputs ?verbose messages about job state changes and event emissions to the system console or log,useful for debugging boot. | 顯示詳細(xì)信息 |
| -q, --quiet | reduce output to errors only | 只顯示錯(cuò)誤 |
【示例】:
1、基本用法:關(guān)機(jī)
[root@oldboy ~]# init 0
?
2、基本用法:重啟
[root@oldboy ~]# init 6
?
?
?
27.?【命令】:shutdown
【功能說明】:
bring the system down ?#關(guān)機(jī)
【語法格式】:
shutdown [OPTION]... ?TIME [MESSAGE]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -r | Requests that the system be rebooted after it has been brought down | 重啟系統(tǒng) |
| -h | Requests that the system be either halted or pow-ered off after it has been brought down, with the choice as to which left up to the system. | 關(guān)機(jī) |
| -H | Requests that the system be halted after ?it ?has ?been brought down | ? |
| -P | Requests ?that the system be powered off after it has been brought down. | ? |
| -c | Cancels a running shutdown. ?TIME?is ?not ?specified with this option, the first argument is MES-SAGE. | 當(dāng)執(zhí)行“shutdown -h 11:50”指令時(shí),只要按+鍵就可以中斷關(guān)機(jī)的指令 |
| -k | Only send out the warning ?messages ?and ?disable ?logins, do not actually bring the system down | 只發(fā)送警告信息,不真關(guān)機(jī) |
【示例】:
1、基本用法:立即關(guān)機(jī)
[root@oldboy ~]# shutdown -h now
?
2、指定12點(diǎn)關(guān)機(jī)
[root@oldboy ~]# shutdown -h 12:00
?
Broadcast message from root@oldboy
????????(/dev/pts/0) at 11:54 ...
?
The system is going down for halt in 6 minutes!
?
?
?
28.?【命令】:reboot
【功能說明】:
reboot the system ?#重啟系統(tǒng)
【語法格式】:
reboot [OPTION]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -f, --force | Does ?not invoke shutdown(8) and instead performs the actual action you would expect from the name. | 強(qiáng)制重新開機(jī) |
| -p, --poweroff | Instructs ?the ?halt command to instead behave as poweroff | ? |
| -w, --wtmp-only | Does not call shutdown(8) or the reboot(2) system call ?and instead only writes the shutdown record to /var/log/wtmp | 僅做測試,并不真正將系統(tǒng)重新開機(jī),只會(huì)把重開機(jī)的數(shù)據(jù)寫入/var/log目錄下的wtmp記錄文件。 |
| --verbose | Outputs ?slightly ?more ?verbose ?messages ??when rebooting, ?useful ?for ?debugging ?problems with shutdown. | ? |
| -n, --no-sync | don't sync before reboot or halt | ? |
【示例】:
1、基本用法:重啟系統(tǒng)
[root@oldboy ~]# reboot
?
?
29.?【命令】:history
【功能說明】:
Display or manipulate the history list. ?#查看命令歷史
【語法格式】:
history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c | clear the history list by deleting all of the entries | 清空當(dāng)前歷史命令 |
| -d | offset delete the history entry at offset OFFSET | ? |
| -a | append history lines from this session to the history file | 將歷史命令緩沖區(qū)中命令寫入歷史命令文件中 |
| -n | read all history lines not already read from the history file | ? |
| -r | read the history file and append the contents to the history list | 將歷史命令文件中的命令讀入當(dāng)前歷史命令緩沖區(qū) |
| -w | write the current history to the history file and append them to the history list | ? |
| -p | perform history expansion on each ARG and display the result without storing it in the history list | ? |
| -s | append the ARGs to the history list as a single entry | ? |
【示例】:
1、基本用法:查看命令歷史
[root@oldboy ~]# history
????1 ?cd /usr/local/
????2 ?cd ..
????3 ?pwd
????4 ?cd ../..
????5 ?cd -
????6 ?cd ~
????7 ?cd /
????8 ?ll
9 ?ls -la
......
?
?
30.?【命令】:dmesg
【功能說明】:
print or control the kernel ring buffer ?#查看系統(tǒng)故障信息
【語法格式】:
dmesg [-c] [-r] [-n level] [-s bufsize]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c | Clear the ring buffer contents after printing. | 顯示信息后,清除ring buffer中的內(nèi)容 |
| -r | Print ?the ?raw message buffer, i.e., don’t strip ?the log level prefixes. | ? |
| -s bufsize | Use a buffer of size bufsize to query the ?kernel ring ?buffer. ??This ?is ?16392 by default. ?(The default kernel syslog buffer ?size ?was ?4096 ?at ?first, ?8192 ?since 1.3.54, 16384 since 2.1.113.) If you have set the kernel buffer ?to ?be ?larger than ?the default then this option can be used to view the entire buffer | 設(shè)置ring buffer大小,預(yù)設(shè)置為8196,剛好等于ring buffer的大小 |
| -n level | Set the level at which ?logging ?of ?messages ?is done ?to the console. ?For example, -n 1 prevents all messages, except panic messages, from appear-ing ?on ?the console. ?All levels of messages are still written to /proc/kmsg, ?so ?syslogd(8) ?can ?still ?be ?used ?to ?control exactly where kernel messages appear. ?When the ?-n ?option ?is ?used,dmesg ?will ?not ?print ?or clear the kernel ring buffer | 設(shè)置記錄信息的層級 |
| ? | ? | ? |
【示例】:
1、基本用法:查看信息
[root@oldboy ~]# dmesg
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-573.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Thu Jul 23 15:44:03 UTC 2015
Command line: ro root=UUID=8fc55236-ce36-4cc4-9924-202ed5142065 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto ?KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
?
31.?【命令】:ifup、ifdown
【功能說明】:
ifup - bring a network interface up ?#開啟網(wǎng)卡
ifdown - take a network interface down ?#關(guān)閉網(wǎng)卡
【語法格式】:
ifup IFACE [boot]
ifdown IFACE
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| ? | ? | ? |
【示例】:
1、基本用法:關(guān)閉、開啟網(wǎng)卡
[root@oldboy ~]# ifdown eth0
[root@oldboy ~]# ifup eth0
Determining if ip address 10.0.0.8 is already in use for device eth0...
?
32.?【命令】:nl
【功能說明】:
number lines of files ?#顯示文件行號(hào)
【語法格式】:
nl [OPTION]... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b, --body-numbering=STYLE | use STYLE for numbering body lines | 指定行號(hào)指定的方式,主要有兩種: -b?a?:表示不論是否為空行,也同樣列出行號(hào)(類似?cat?-n); -b?t?:如果有空行,空的那一行不要列出行號(hào)(默認(rèn)值); |
| -d, --section-delimiter=CC | use CC for separating logical pages | ? |
| -f, --footer-numbering=STYLE | use STYLE for numbering footer lines | ? |
| -h, --header-numbering=STYLE | use STYLE for numbering header lines | ? |
| -i, --line-increment=NUMBER | line number increment at each line | ? |
| -l, --join-blank-lines=NUMBER | group of NUMBER empty lines counted as one | ? |
| -n, --number-format=FORMAT | insert line numbers according to FORMAT | 列出行號(hào)表示的方法,主要有三種: -n?ln?:行號(hào)在螢?zāi)坏淖钭蠓斤@示; -n?rn?:行號(hào)在自己欄位的最右方顯示,且不加?0?; -n?rz?:行號(hào)在自己欄位的最右方顯示,且加?0?; |
| -p, --no-renumber | do not reset line numbers at logical pages | 在邏輯定界符處不重新開始計(jì)算 |
| -s, --number-separator=STRING | add STRING after (possible) line number | ? |
| -v, --starting-line-number=NUMBER | first line number on each logical page | ? |
| -w, --number-width=NUMBER | use NUMBER columns for line numbers | 行號(hào)欄位的占用的位數(shù) |
?
【示例】:
1、基本用法:顯示行號(hào)(默認(rèn)空行不顯示)
[root@oldboy ~]# nl test.txt
?????1 ?10
?????2 ?14
?????3 ?99
???????
???????
???????
?????4 ?8a1
?????5 ?69
?
2、顯示行號(hào)(空行也顯示)
[root@oldboy ~]# nl -b a test.txt
?????1 ?10
?????2 ?14
?????3 ?99
?????4
?????5
?????6
?????7 ?8a1
?????8 ?69
?
3、讓行號(hào)前自動(dòng)補(bǔ)上0,統(tǒng)一輸出格式
[root@oldboy ~]# nl -b a -n rz test.txt
000001 ?10
000002 ?14
000003 ?99
000004
000005
000006
000007 ?8a1
000008 ?69
?
4、調(diào)整統(tǒng)一輸出格式為三位數(shù)字
[root@oldboy ~]# nl -b a -n rz -w 3 test.txt
001 ????10
002 ????14
003 ????99
004
005
006
007 ????8a1
008 ????69
?
?
33.?【命令】:less
【功能說明】:
opposite of more ?#分屏查看文本(可回退)
【語法格式】:
???????less -?
???????less --help
???????less -V
???????less --version
???????less [-[+]aBcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
????????????[-b space] [-h lines] [-j line] [-k keyfile]
????????????[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
????????????[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
????????????[-# shift] [+[+]cmd] [--] [filename]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -bn | Specifies the amount of buffer ?space ?less ?will use ?for ?each ?file, in units of kilobytes (1024 bytes). ?By default 64K of buffer space ?is ?used for each file (unless the file is a pipe; see the -B option). ?The -b option specifies instead that n ?kilobytes ?of ?buffer space should be used for each file. ?If n is -1, buffer ?space ?is ?unlimited; ?that ?is, the entire file can be read into memory. | 設(shè)置緩沖區(qū)的大小 |
| -e | Causes less to automatically exit the second time it reaches end-of-file. ?By default, the only way to exit less is via the "q" command. | 當(dāng)文件顯示結(jié)束后,自動(dòng)離開 |
| -f | Forces non-regular files to be opened. ??(A ?non-regular ?file ?is a directory or a device special file.) ?Also suppresses the warning message ?when a ?binary ?file is opened. ?By default, less will refuse to open non-regular files. ?Note that some operating ?systems ?will not allow directories to be read, even if -f is set | 強(qiáng)迫打開特殊文件,例如外圍設(shè)備代號(hào)、目錄和二進(jìn)制文件 |
| -g | Normally, ?less ?will highlight ALL strings which match the last search ?command. ??The ?-g ?option changes ?this behavior to highlight only the particular string which was found by the last search command. ??This ?can ?cause ?less to run somewhat ?faster than the default | 只標(biāo)志最后搜索的關(guān)鍵詞 |
| -i | Causes searches to ignore case; that ?is, ?uppercase ?and ?lowercase ?are ?considered ?identical. This option is ignored if any ?uppercase ?letters appear ?in the search pattern; in other words, if a pattern contains uppercase letters, ?then ?that ?search does not ignore case | 忽略搜索時(shí)的大小寫 |
| -m | Causes less to prompt verbosely (like more), with the ?percent ?into ?the ?file. ??By default, less prompts with a colon | 顯示類似more命令的百分比 |
| -N | Causes a line ?number ?to ?be ?displayed ?at ?the beginning of each line in the display. | 顯示每行的行號(hào) |
| -ofilename | Causes ?less ?to copy its input to the named file as it is being viewed. ?This ?applies ?only ?when the ?input ?file is a pipe, not an ordinary file. If the file already exists, ?less ?will ?ask ?for confirmation before overwriting it | 將less?輸出的內(nèi)容在指定文件中保存起來 |
| -Q | Causes ?totally ?"quiet" ?operation: the terminal bell is never rung. | 不使用警告音 |
| -s | Causes ?consecutive ?blank ?lines ?to be squeezed into a single blank line. ?This ?is ?useful ?when viewing nroff output | 顯示連續(xù)空行為一行 |
| -S | Causes ?lines ?longer than the screen width to be chopped rather than folded. ?That is, the portion of ?a ?long ?line that does not fit in the screen width is not shown. ?The default is to fold ?long lines; that is, display the remainder on the next line | 行過長時(shí)間將超出部分舍棄 |
| -xn | Sets ?tab stops. ?If only one n is specified, tab stops are set at multiples ?of ?n. ??If ?multiple ?values ?separated ?by ?commas ?are specified, tab stops are set at those positions, and ?then ?continue with the same spacing as the last two. ?For example, -x9,17 will set tabs at positions 9, 17,25, 33, etc. The default for n is 8 | 將“tab”鍵顯示為規(guī)定的數(shù)字空格 |
【示例】:
1、基本用法:查看文件
[root@oldboy ~]# less test.txt
10
14
99
?
?
?
8a1
69
38
?
【特別說明】
1.全屏導(dǎo)航
ctrl?+?F?-?向前移動(dòng)一屏
ctrl?+?B?-?向后移動(dòng)一屏
ctrl?+?D?-?向前移動(dòng)半屏
ctrl?+?U?-?向后移動(dòng)半屏
?
2.單行導(dǎo)航
j?-?向前移動(dòng)一行
k?-?向后移動(dòng)一行
?
3.其它導(dǎo)航
G?-?移動(dòng)到最后一行
g?-?移動(dòng)到第一行
q?/?ZZ?-?退出?less?命令
?
4.其它有用的命令
v?-?使用配置的編輯器編輯當(dāng)前文件
h?-?顯示?less?的幫助文檔
&pattern?-?僅顯示匹配模式的行,而不是整個(gè)文件
?
5.標(biāo)記導(dǎo)航
當(dāng)使用?less?查看大文件時(shí),可以在任何一個(gè)位置作標(biāo)記,可以通過命令導(dǎo)航到標(biāo)有特定標(biāo)記的文本位置:
ma?-?使用?a?標(biāo)記文本的當(dāng)前位置
'a?-?導(dǎo)航到標(biāo)記?a?處
?
34.?【命令】:more
【功能說明】:
file perusal filter for crt viewing ?#分屏查看文件(不可回退)
【語法格式】:
more [-dlfpcsu] [-num] [+/pattern] [+linenum] [file ...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| +num | Start at line number num | 從笫n行開始顯示 |
| -num | This option specifies an integer which is the screen size (in lines) | 定義屏幕大小為n行 |
| +/pattern | The +/ option specifies a string that will be searched for before each file is displayed | 在每個(gè)檔案顯示前搜尋該字串(pattern),然后從該字串前兩行之后開始顯示 |
| -c | Do not scroll. ?Instead, paint each screen from the top, clearing the remainder of each line as it is displayed. | 從頂部清屏,然后顯示 |
| -d | more will prompt the user with the message "[Press space to continue, ’q’ to quit.]" and will display"[Press ’h’ for instructions.]" instead of ringing the bell when an illegal key is pressed | 提示“Press?space?to?continue,’q’?to?quit(按空格鍵繼續(xù),按q鍵退出)”,禁用響鈴功能 |
| -l | more usually treats ^L (form feed) as a special character, and will pause after any line that contains a form feed. ?The -l option will prevent this behavior. | 忽略Ctrl+l(換頁)字符 |
| -p | Do not scroll. ?Instead, clear the whole screen and then display the text | 通過清除窗口而不是滾屏來對文件進(jìn)行換頁,與-c選項(xiàng)相似 |
| -s | Squeeze multiple blank lines into one. | 把連續(xù)的多個(gè)空行顯示為一行 |
| -u | Suppress underlining | 把文件內(nèi)容中的下畫線去掉 |
【示例】:
1、基本用法:查看文件
[root@oldboy ~]# more test.txt
10
14
99
?
?
?
8a1
69
38
【特別說明】
Enter????向下n行,需要定義。默認(rèn)為1行
Ctrl+F???向下滾動(dòng)一屏
空格鍵??向下滾動(dòng)一屏
Ctrl+B??返回上一屏
=??????? ?輸出當(dāng)前行的行號(hào)
:f???? ?輸出文件名和當(dāng)前行的行號(hào)
V????? ??調(diào)用vi編輯器
!命令???調(diào)用Shell,并執(zhí)行命令?
q?????? ??退出more
?
35.?【命令】:wc
【功能說明】:
print newline, word, and byte counts for each file ?#打印行數(shù)、字?jǐn)?shù)
【語法格式】:
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c, --bytes | print the byte counts | 打印字節(jié)數(shù) |
| -m, --chars | print the character counts | 打印字符數(shù) |
| -l, --lines | print the newline counts | 打印行數(shù) |
| --files0-from=F | read input from the files specified by NUL-terminated names in file F; If F is - then read ?names from standard input | ? |
| -L, --max-line-length | print the length of the longest line | 打印最長行的長度 |
| -w, --words | print the word counts | 打印單詞數(shù) |
【示例】:
1、基本用法:打印行數(shù)、單詞數(shù)、字節(jié)數(shù)及文件名
[root@oldboy ~]# wc test.txt
?9 ?6 22 test.txt
?
2、只打印統(tǒng)計(jì)數(shù)字不打印文件名
[root@oldboy ~]# cat test.txt|wc -l
9
?
?
36.?【命令】:chkconfig
【功能說明】:
updates and queries runlevel information for system services ?#管理開機(jī)自啟動(dòng)程序
【語法格式】:
chkconfig [--list] [--type type][name]
chkconfig --add name
chkconfig --del name
chkconfig --override name
chkconfig ??[--level ??levels] ??[--type ??type] ???name<on|off|reset|resetpriorities>
???????chkconfig [--level levels] [--type type] name
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| --level levels | Specifies the run levels an operation should pertain ?to. It is given as a string of numbers from 0 to 6. For example, --level ?35 ?specifies ?run- levels 3 and 5 | 指定系統(tǒng)服務(wù)要在哪一個(gè)執(zhí)行等級中開啟或關(guān)畢 |
| --add name | This ?option adds a new service for management by chkconfig. ?When a new service is added, ?chkconfig ?ensures ?that the service has either a start or a kill entry in every runlevel. ?If ?any ?run-level is missing such an entry, chkconfig creates the appropriate entry as specified by the default values ?in ?the ?init ?script. ?Note that default entries in ?LSB-delimited ?’INIT ?INFO’ ?sections take precedence over the default runlevels in the initscript; if any ?Required-Start ?or ?Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies | 增加所指定的系統(tǒng)服務(wù),讓chkconfig指令得以管理它,并同時(shí)在系統(tǒng)啟動(dòng)的敘述文件內(nèi)增加相關(guān)數(shù)據(jù) |
| --del name | The service is removed from chkconfig management,and any symbolic links ?in ?/etc/rc[0-6].d ?which pertain to it are removed.Note ?that ?future package installs for this service may run chkconfig --add, which ?will ?re-add such ?links. ?To disable a service, run chkconfig name off. | 刪除所指定的系統(tǒng)服務(wù),不再由chkconfig指令管理,并同時(shí)在系統(tǒng)啟動(dòng)的敘述文件內(nèi)刪除相關(guān)數(shù)據(jù) |
| --list name | This option lists all of the services which ?chkconfig ?knows about, and whether they are stopped or started in each runlevel. If ?name ?is ?specified, ?information ?in only display about service name. | 羅列所有服務(wù)在各執(zhí)行等級上的開啟、關(guān)閉情況 |
【示例】:
1、基本用法:查看所有服務(wù)在各執(zhí)行等級上的開啟、關(guān)閉情況
[root@oldboy ~]# chkconfig --list
abrt-ccpp ??????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
abrtd ??????????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
acpid ??????????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
atd ????????????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
auditd ?????????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
blk-availability ???????0:off ??1:on ???2:off ??3:off ??4:off ??5:off6:off
cpuspeed ???????0:off ??1:on ???2:off ??3:off ??4:off ??5:off ??6:off
crond ??????????0:off ??1:off ??2:on ???3:on ???4:on ???5:on ???6:off
haldaemon ??????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
......
?
2、基本用法:在指定執(zhí)行等級上關(guān)閉(開啟)一個(gè)服務(wù)
[root@oldboy ~]# chkconfig --level 2345 atd off
[root@oldboy ~]# chkconfig --list|grep "atd"
atd ????????????0:off ??1:off ??2:off ??3:off ??4:off ??5:off ??6:off
?
?
37.?【命令】:tar
【功能說明】:
manual page for tar 1.23 ?#打包命令
【語法格式】:
tar [OPTION...] [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -A | append tar files to an archive | 新增壓縮文件到已存在的壓縮 |
| -c | create a new archive | 建立新的壓縮文件 |
| -d | find differences between archive and file system | 記錄文件的差別 |
| -r | append files to the end of an archive | 添加文件到已經(jīng)壓縮的文件結(jié)尾 |
| -u | only append files newer than copy in archive | 添加改變了和現(xiàn)有的文件到已經(jīng)存在的壓縮文件 |
| -x | extract files from an archive | 從壓縮的文件中提取文件 |
| -t | list the contents of an archive | 顯示壓縮文件的內(nèi)容 |
| -z | filter the archive through gzip | 支持gzip解壓文件 |
| -j | filter the archive through bzip2 | 支持bzip2解壓文件 |
| -v | verbosely list files processed | 顯示操作過程 |
| -W | attempt to verify the archive after writing it | 確認(rèn)壓縮文件的正確性 |
| -C | change to directory DIR | 切換到指定目錄 |
| -f | use archive file or device ARCHIVE | 指定壓縮文件 |
【示例】:
1、基本用法:打包文件zcvf
[root@oldboy ~]# tar zcvf data.tar.gz ./data
./data/
./data/d.txt
./data/oldboy.txt
./data/dir5/
./data/dir1/
./data/test.txt
./data/c.txt
./data/dir2/
./data/dir3/
./data/dir4/
./data/e.txt
[root@oldboy ~]# ls
anaconda-ks.cfg ?install.log ????????oldboy ????????test.txt
data ????????????install.log.syslog ?oldboy.tar.gz
data.tar.gz ?????log2.txt ???????????oldboy.txt
?
2、基本用法:解包zxvf
[root@oldboy tmp]# tar zxvf data.tar.gz
./data/
./data/d.txt
./data/oldboy.txt
./data/dir5/
./data/dir1/
./data/test.txt
./data/c.txt
./data/dir2/
./data/dir3/
./data/dir4/
./data/e.txt
[root@oldboy tmp]# ls
data ?data.tar.gz ?file1.txt ?file2.txt ?oldboy ?test.txt
?
3、批量排除打包
[root@oldboy?opt]#?cat?paichu.log
stu05??
stu06??
stu07
[root@oldboy?opt]#?tar?zcvfX?paichuX.tar.gz?paichu.log?./test?
./test/
./test/stu03
./test/stu01
./test/stu02
./test/stu09
./test/stu08
./test/stu10
./test/stu04
[root@oldboy?opt]#?tar?tf?paichuX.tar.gz?
./test/
./test/stu03
./test/stu01
./test/stu02
./test/stu09
./test/stu08
./test/stu10
./test/stu04
?
38.?【命令】:cut
【功能說明】:
remove sections from each line of files ?#
【語法格式】:
cut OPTION... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b, --bytes=LIST | select only these bytes | 以字節(jié)為單位進(jìn)行分割 |
| -c, --characters=LIST | select only these characters | 以字符為單位進(jìn)行分割 |
| -d, --delimiter=DELIM | use DELIM instead of TAB for field delimiter | 自定義分隔符,默認(rèn)為制表符 |
| -f, --fields=LIST | select ?only these fields; ?also print any line that contains ?no ?delimiter ?character, ?unless ?the ?-soption is specified | 與-d一起使用,指定顯示哪個(gè)區(qū)域 |
| -n | with -b: don’t split multibyte characters | 取消分割多字節(jié)字符僅和 -b 標(biāo)志一起使用。如果字符的最后一個(gè)字節(jié)落在由 -b 標(biāo)志的 List 參數(shù)指示的范圍之內(nèi),該字符將被寫出;否則,該字符將被排除。 |
| --complement | complement ?the set of selected bytes, characters or fields | 補(bǔ)足被選擇的字節(jié)、字符或字段 |
| -s, --only-delimited | do not print lines not containing delimiters | 不打印不含分隔符的行 |
| --output-delimiter=STRING | use STRING as the output delimiter the default is to use the input delimiter | 指定分隔符打印樣式 |
【示例】:
1、基本用法:以字節(jié)為單位取列
[root@oldboy ~]# cat oldboy.txt
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
[root@oldboy ~]# cut -b6-18 oldboy.txt
addr:10.0.0.8
?
2、基本用法:以字符為單位取列
[root@oldboy ~]# cat oldboy.txt
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
[root@oldboy ~]# cut -c6-18 oldboy.txt
addr:10.0.0.8
?
3、基本用法:以分隔符為單位取列
[root@oldboy ~]# cat /etc/passwd|head -5
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@oldboy ~]# cat /etc/passwd|head -5|cut -d':' -f5
root
bin
daemon
adm
lp
?
?
39.?【命令】:tr
【功能說明】:
translate or delete characters ?#轉(zhuǎn)換或刪除字符
【語法格式】:
tr [OPTION]... SET1 [SET2]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -c, -C, --complement | use the complement of SET1 | 取代所有不屬于第一字符集的字符 |
| -d, --delete | delete characters in SET1, do not translate | 刪除所有屬于第一字符集的字符 |
| -s, --squeeze-repeats | replace each input sequence of a repeated ?character that ?is ?listed in SET1 with a single occurrence of that character | 把連續(xù)重復(fù)的字符以單獨(dú)一個(gè)字符表示 |
| -t, --truncate-set1 | first truncate SET1 to length of SET2 | 先刪除第一字符集較第二字符集多出的字符 |
【示例】:
1、基本用法:替換字符
[root@oldboy ~]# echo abcdef|tr 'a-f' 'x-za-c'
xyzabc
?
2、刪除字符
[root@oldboy ~]# echo abcdef|tr -d 'a-c'
def
?
3、連續(xù)重復(fù)的字符以單獨(dú)一個(gè)字符表示
[root@oldboy ~]# echo aaabbbccc|tr -s 'abc'
abc
[root@oldboy ~]# echo aaabbbccc|tr -s 'a'
abbbccc
?
?
40.?【命令】:stat
【功能說明】:
display file or file system status ?#顯示文件和文件系統(tǒng)狀態(tài)(查看文件屬性)
【語法格式】:
stat [OPTION]... FILE...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -L, --dereference | follow links | 如果是鏈接文件,則獲取原文件信息 |
| -Z, --context | print the SELinux security context | 打印SELinux安全上下文信息 |
| -f, --file-system | display file system status instead of file status | 顯示文件系統(tǒng)狀態(tài)而非文件狀態(tài) |
| -c ?--format=FORMAT | use ?the ?specified ?FORMAT ?instead of the default; output a newline after each use of FORMAT | 自定義輸出格式,結(jié)尾有換行 |
| --printf=FORMAT | like --format, but interpret backslash escapes, ?and do ?not output a mandatory trailing newline. ?If you want a newline, include \n in FORMAT. | 自定義輸出格式,結(jié)尾無換行符,需手動(dòng)添加 |
| -t, --terse | print the information in terse form | 以簡潔方式輸出信息 |
【示例】:
1、基本用法:查看文件信息
[root@oldboy ~]# stat test.txt
??File: `test.txt'
??Size: 22 ?????????????Blocks: 8 ?????????IO Block: 4096 ??regular file
Device: 803h/2051d ?????Inode: 11628 ??????Links: 1
Access: (0644/-rw-r--r--) ?Uid: ( ???0/ ???root) ??Gid: ( ???0/ ???root)
Access: 2016-03-19 16:08:55.616298620 +0800
Modify: 2016-03-19 16:08:44.504300222 +0800
Change: 2016-03-19 16:08:44.505300149 +0800
?
2、利用stat取文件權(quán)限屬性
[root@oldboy ~]# stat test.txt
??File: `test.txt'
??Size: 22 ?????????????Blocks: 8 ?????????IO Block: 4096 ??regular file
Device: 803h/2051d ?????Inode: 11628 ??????Links: 1
Access: (0644/-rw-r--r--) ?Uid: ( ???0/ ???root) ??Gid: ( ???0/ ???root)
......
[root@oldboy ~]# stat -c %a test.txt
644
?
41.?【命令】:file
【功能說明】:
determine file type ?#顯示文件類型
【語法格式】:
file [-bchikLNnprsvz0] [--apple] [--mime-encoding]
??????????[--mime-type] [-e testname] [-F separator] [-f namefile]
??????????[-m magicfiles] file ...
file -C [-m magicfiles]
file [--help]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b | Do not prepend filenames to output lines (brief mode) | 列出文件辨識(shí)結(jié)果時(shí),不顯示文件名稱。 |
| -c | Cause a checking printout of the parsed form of the magic file. ?This is usually used in conjunction with the -m flag to debug a new magic file before installing it | 詳細(xì)顯示指令執(zhí)行過程,便于排錯(cuò)或分析程序執(zhí)行的情形 |
| -f | Read the names of the files to be examined from namefile (one per line) before the argument list.Either namefile or at least one filename argument must be present; to test the standard input, use ‘-’ as a filename argument. | 列出文件中文件名的文件類型 |
| -F | Use the specified string as the separator between the filename and the file result returned. Defaults to‘:’. | 使用指定分隔符號(hào)替換輸出文件名后的默認(rèn)的“:”分隔符 |
| -i | Causes the file command to output mime type strings rather than the more traditional human readable ones.Thus it may say ‘text/plain; charset=us-ascii’ rather than ‘ASCII text’. ?In order for this option to work,file changes the way it handles files recognized by the command itself (such as many of the text file types, directories etc), and makes use of an alternative ‘magic’ file. ?(See the FILES section, below) | 輸出mime類型的字符串 |
| -L | option causes symlinks to be followed, as the like-named option in ls(1) (on systems that support symbolic links). ?This is the default if the environment variable POSIXLY_CORRECT is defined | 查看對應(yīng)軟鏈接對應(yīng)文件的文件類型 |
| -z | Try to look inside compressed files. | 嘗試去解讀壓縮文件的內(nèi)容 |
【示例】:
1、基本用法:顯示文件類型
[root@oldboy ~]# file test.txt
test.txt: ASCII text
[root@oldboy ~]# file /data
/data: directory
?
?
42.?【命令】:last
【功能說明】:
show listing of last logged in users ?#查看用戶登錄信息
【語法格式】:
last ?[-R] ?[-num] ?[ ?-n num ] [-adFiowx] [ -f file ] [ -t
???????YYYYMMDDHHMMSS ] [name...] ?[tty...]
???????lastb [-R] [-num] [ ?-n ?num ?] ?[ ?-f ?file ?] ?[-adFiowx]
???????[name...] ?[tty...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | Display ?the ?hostname in the last column. Useful in combination with the next flag | 將登錄系統(tǒng)的的主機(jī)名稱或IP地址,顯示在最后一行 |
| -d | For non-local logins, Linux stores not only the host name ?of ?the remote host but its IP number as well.This option translates the IP ?number ?back ?into ?a hostname | 將IP地址轉(zhuǎn)換成主機(jī)名稱 |
| -f | Specifies a file to search other than /var/log/wtmp | 指定記錄文件,默認(rèn)是顯示/var/log目錄下的wtmp文件的記錄,但/var/log目錄下得btmp能顯示的內(nèi)容更豐富,可以顯示遠(yuǎn)程登錄,例如ssh登錄 ,包括失敗的登錄請求 |
| -i | This ?option ?is ?like -d in that it displays the IP number of the remote host, but it ?displays ?the ?IP ?number in numbers-and-dots notation. | -i顯示特定ip登錄的情況。跟蹤用 -i顯示特定ip登錄的情況。跟蹤用 |
| -o | Read ?an ?old-type wtmp file (written by linux-libc5 applications). | ? |
| -n | This is a count telling last how many lines to show. | -n <顯示列數(shù)>或-<顯示列數(shù)> 設(shè)置列出名單的顯示列數(shù) |
| -w | Display full user and domain names in the output | ? |
| -R | Suppresses the display of the hostname field | 不顯示登入系統(tǒng)的主機(jī)名稱或IP(省略 hostname 的欄位) |
| -t | Display ?the ?state ?of ?logins ?as of the specified time. ?This is useful, e.g., to determine easily who was ?logged ?in at a particular time -- specify that time with -t and look for "still logged in" | 顯示YYYYMMDDHHMMSS之前的信息 |
| -x | Display the system shutdown entries ?and ?run ?level ?changes. | 顯示系統(tǒng)關(guān)閉、用戶登錄和退出的歷史 |
【示例】:
1、基本用法:查看用戶登錄信息
[root@oldboy ~]# last
oldboy ??pts/0 ???????10.0.0.1 ????????Sun Mar 20 12:15 ??still logged in ??
reboot ??system boot ?2.6.32-573.el6.x Sun Mar 20 12:15 - 15:08 ?(02:53) ???
oldboy ??pts/1 ???????10.0.0.1 ????????Sat Mar 19 15:36 - down ??(06:49) ???
root ????tty1 ?????????????????????????Sat Mar 19 15:35 - down ??(06:50)
?
2、顯示最后登錄系統(tǒng)的N條記錄
[root@oldboy ~]# last -n 10
oldboy ??pts/0 ???????10.0.0.1 ????????Sun Mar 20 12:15 ??still logged in ??
reboot ??system boot ?2.6.32-573.el6.x Sun Mar 20 12:15 - 15:25 ?(03:10) ???
oldboy ??pts/1 ???????10.0.0.1 ????????Sat Mar 19 15:36 - down ??(06:49) ???
root ????tty1 ?????????????????????????Sat Mar 19 15:35 - down ??(06:50) ???
oldboy ??pts/0 ???????10.0.0.1 ????????Sat Mar 19 10:28 - 15:52 ?(05:24) ???
reboot ??system boot ?2.6.32-573.el6.x Sat Mar 19 10:28 - 22:25 ?(11:57) ???
root ????tty1 ?????????????????????????Sat Mar 19 10:27 - down ??(00:00) ???
oldboy ??pts/0 ???????10.0.0.1 ????????Sat Mar 19 10:20 - down ??(00:07) ???
oldboy ??pts/0 ???????10.0.0.1 ????????Sat Mar 19 10:19 - 10:20 ?(00:00) ???
reboot ??system boot ?2.6.32-573.el6.x Sat Mar 19 10:19 - 10:27 ?(00:08) ???
?
wtmp begins Thu Mar ?3 23:14:45 2016
?
3、將IP地址轉(zhuǎn)換成主機(jī)名稱
[root@oldboy ~]# last -n 5 -d
oldboy ??pts/0 ???????localhost ???????Sun Mar 20 12:15 ??still logged in ??
reboot ??system boot ?0.0.0.0 ?????????Sun Mar 20 12:15 - 15:27 ?(03:11) ???
oldboy ??pts/1 ???????localhost ???????Sat Mar 19 15:36 - down ??(06:49) ???
root ????tty1 ????????0.0.0.0 ?????????Sat Mar 19 15:35 - down ??(06:50) ???
oldboy ??pts/0 ???????localhost ???????Sat Mar 19 10:28 - 15:52 ?(05:24)
?
4、指定/var/log/btmp文件,查看登錄系統(tǒng)的用戶相關(guān)信息
[root@oldboy ~]# last -n 5 -f /var/log/btmp
?
btmp begins Thu Mar ?3 23:14:22 2016
?
?
43.?【命令】:lastlog
【功能說明】:
reports the most recent login of all users or of a given user ?#查看最近登錄的用戶信息
【語法格式】:
lastlog [options]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b, --before DAYS | Print only lastlog records older than DAYS | 顯示指定天數(shù)前的登錄信息 |
| -h, --help | Display help message and exit. | 顯示幫助 |
| -t, --time DAYS | Print the lastlog records more recent than DAYS | 顯示指定天數(shù)以來的登錄信息 |
| -u, --user LOGIN|RANGE | Print the lastlog record of the specified user(s) | 顯示指定用戶的最近登錄信息 |
【示例】:
1、基本用法:顯示最近登錄的用戶信息
[root@oldboy ~]# lastlog
Username ????????Port ????From ????????????Latest
root ????????????tty1 ?????????????????????Sat Mar 19 15:35:02 +0800 2016
bin ???????????????????????????????????????**Never logged in**
daemon ????????????????????????????????????**Never logged in**
adm ???????????????????????????????????????**Never logged in**
lp ????????????????????????????????????????**Never logged in**
sync ??????????????????????????????????????**Never logged in**
shutdown ??????????????????????????????????**Never logged in**
halt ??????????????????????????????????????**Never logged in**
mail ??????????????????????????????????????**Never logged in**
......
oldboy ??????????pts/0 ???10.0.0.1 ????????Sun Mar 20 12:15:35 +0800 2016
test ??????????????????????????????????????**Never logged in**
?
2、顯示某一個(gè)用戶最近登錄信息
[root@oldboy ~]# lastlog -u oldboy
Username ????????Port ????From ????????????Latest
oldboy ??????????pts/0 ???10.0.0.1 ????????Sun Mar 20 12:15:35 +0800 2016
?
?
44.?【命令】:df
【功能說明】:
report file system disk space usage ?#查看系統(tǒng)磁盤空間的使用情況
【語法格式】:
df [OPTION]... [FILE]...
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | include dummy file systems | 包含全部的文件系統(tǒng) |
| -B | use SIZE-byte blocks | 以指定的區(qū)塊大小來顯示區(qū)塊數(shù)目 |
| -h | print sizes in human readable format (e.g., 1K 234M 2G) | 以可讀性較高的方式來顯示信息 |
| -H | likewise, but use powers of 1000 not 1024 | 與-h相同,但在計(jì)算時(shí)是以1000Bytes為換算單位而非1024 Bytes |
| -i | list inode information instead of block usage | 顯示inode的信息 |
| -k | like --block-size=1K | 指定區(qū)塊大小為1024字節(jié) |
| -l | limit listing to local file systems | 僅顯示本地的文件系統(tǒng) |
| --no-sync | do not invoke sync before getting usage info (default) | 在取得磁盤使用信息前,不要執(zhí)行sync指令,此為預(yù)設(shè)值 |
| -P | use the POSIX output format | 使用POSIX的輸出格式 |
| --sync | invoke sync before getting usage info | 在取得磁盤使用信息前,先執(zhí)行sync指令 |
| -t | limit listing to file systems of type TYPE | 僅顯示指定文件系統(tǒng)類型的磁盤信息 |
| -T | print file system type | 顯示文件系統(tǒng)的類型 |
| -x | limit listing to file systems not of type TYPE | 不要顯示指定文件系統(tǒng)類型的磁盤信息 |
【示例】:
1、基本用法:查看磁盤空間使用情況
[root@oldboy ~]# df
Filesystem ????1K-blocks ???Used Available Use% Mounted on
/dev/sda3 ???????7149156 1494028 ??5285312 ?23% /
tmpfs ????????????243320 ??????0 ???243320 ??0% /dev/shm
/dev/sda1 ????????194241 ??40498 ???143503 ?23% /boot
[root@oldboy ~]# df -h
Filesystem ?????Size ?Used Avail Use% Mounted on
/dev/sda3 ??????6.9G ?1.5G ?5.1G ?23% /
tmpfs ??????????238M ????0 ?238M ??0% /dev/shm
/dev/sda1 ??????190M ??40M ?141M ?23% /boot
?
2、基本用法:查看inode的消耗情況
[root@oldboy ~]# df -hi
Filesystem ????Inodes IUsed IFree IUse% Mounted on
/dev/sda3 ???????452K ??55K ?397K ??13% /
tmpfs ????????????60K ????1 ??60K ???1% /dev/shm
/dev/sda1 ????????50K ???39 ??50K ???1% /boot
[root@oldboy ~]# df -i
Filesystem ????Inodes IUsed ?IFree IUse% Mounted on
/dev/sda3 ?????462384 56221 406163 ??13% /
tmpfs ??????????60830 ????1 ?60829 ???1% /dev/shm
/dev/sda1 ??????51200 ???39 ?51161 ???1% /boot
?
?
45.?【命令】:dumpe2fs
【功能說明】:
dump ext2/ext3/ext4 filesystem information ?#查看文件系統(tǒng)內(nèi)部信息(元數(shù)據(jù))
【語法格式】:
dumpe2fs [ -bfhixV ] [ -o superblock=superblock ] [ -o blocksize=block-
???????size ] device
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -b | print the blocks which are reserved as bad in the filesystem | 打印文件系統(tǒng)中預(yù)留的塊信息 |
| -o superblock=superblock | use the block superblock when examining ?the ?filesystem. ??This option ?is ?not usually needed except by a filesystem wizard who is examining the remains of a very badly corrupted filesystem | 指定檢查文件系統(tǒng)時(shí)使用的超級塊 |
| -o blocksize=blocksize | use blocks of blocksize bytes ?when ?examining ?the ?filesystem.This ?option is not usually needed except by a filesystem wizard who is examining the remains of a very badly corrupted ?filesystem | 檢查文件系統(tǒng)時(shí)使用指定的塊大小 |
| -f | force ?dumpe2fs ?to display a filesystem even though it may have some filesystem feature flags which dumpe2fs may not ?understand(and ?which can cause some of dumpe2fs’s display to be suspect) | ? |
| -h | only display the superblock information and not any of the block group descriptor detail information | 僅顯示超級塊信息 |
| -i | display ?the ?filesystem ?data ?from ?an ?image ?file created by e2image, using device as the pathname to the image file | 從指定的文件系統(tǒng)映像文件中讀取文件系統(tǒng)信息 |
| -x | print the detailed group information block numbers in ?hexadecimal format | 以16進(jìn)制格式打印信息塊成員 |
| -V | print the version number of dumpe2fs and exit. | ? |
【示例】:
1、基本用法:查看文件系統(tǒng)內(nèi)部信息
[root@oldboy ~]# dumpe2fs /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: ??<none>
Last mounted on: ?????????/boot
Filesystem UUID: ?????????3e368f7e-0775-4c00-afba-f8880d916366
Filesystem magic number: ?0xEF53
Filesystem revision #: ???1 (dynamic)
Filesystem features: ?????has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: ????????signed_directory_hash
Default mount options: ???user_xattr acl
......
Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
??Checksum 0x303a, unused inodes 2009
??Primary superblock at 1, Group descriptors at 2-2
??Reserved GDT blocks at 3-258
??Block bitmap at 259 (+258), Inode bitmap at 275 (+274)
??Inode table at 291-546 (+290)
??3785 free blocks, 2009 free inodes, 6 directories, 2009 unused inodes
??Free blocks: 4408-8192
??Free inodes: 40-2048
Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
......
?
?
46.?【命令】:tree
【功能說明】:
list contents of directories in a tree-like format ?#以樹的形式羅列目錄內(nèi)容
【語法格式】:
tree ?[-adfghilnopqrstuvxACDFNS] [-L level [-R]] [-H baseHREF] [-T title] [-o
???????filename] ?[--nolinks] ?[-P ?pattern] ?[-I ?pattern] ?[--inodes] ??[--device]
???????[--noreport] ?[--dirsfirst] ?[--version] ?[--help] [--filelimit #] [directory
???????...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | All files are printed. ?By default tree does not ?print ?hidden ?files(those ?beginning ?with ?a ?dot ‘.’). ?In no event does tree print the file system constructs ‘.’ ?(current ?directory) ?and ?‘..’ ?(previous directory) | 顯示所有文件和目錄 |
| -A | Turn on ANSI line graphics hack when printing the indentation lines | 使用ASNI繪圖字符顯示樹狀圖而非以ASCII字符組合 |
| -C | Turn colorization on always, using ?built-in ?color ?defaults ?if ?the LS_COLORS ?environment variable is not set. ?Useful to colorize output to a pipe | 在文件和目錄清單加上色彩,便于區(qū)分各種類型 |
| -d | List directories only | 只羅列目錄 |
| -D | Print the date of the last modification time for the file listed | 列出文件或目錄的更改時(shí)間 |
| -L | Max display depth of the directory tree | 羅列的層次深度 |
| -f | Prints the full path prefix for each file | 在每個(gè)文件或目錄之前,顯示完整的相對路徑名稱 |
| -F | Append ?a ?‘/’ for directories, a ‘=’ for socket files, a ‘*’ for executable files and a ‘|’ for FIFO’s, as per ls -F | 在執(zhí)行文件,目錄,Socket,符號(hào)連接,管道名稱名稱,各自加上"*","/","=","@","|"號(hào) |
| -g | Print the group name, or GID # if no group name is available, ?of ?the file. | 列出文件或目錄的所屬群組名稱,沒有對應(yīng)的名稱時(shí),則顯示群組識(shí)別碼 |
| -i | Makes ?tree ?not print the indentation lines, useful when used in conjunction with the -f option | 不以階梯狀列出文件或目錄名稱 |
| -I | Do not list those files that match the wild-card pattern | 不顯示符合范本樣式的文件或目錄名稱 |
| -l | Follows symbolic links if they point to directories, as if ?they ?were directories. ?Symbolic links that will result in recursion are avoided when detected | 如遇到性質(zhì)為符號(hào)連接的目錄,直接列出該連接所指向的原始目錄 |
| -n | Turn colorization off always, over-ridden by the -C option | 不在文件和目錄清單加上色彩 |
| -N | Print ?non-printable ?characters ?as ?is ?instead of the default caret notation | 直接列出文件和目錄名稱,包括控制字符 |
| -p | Print the file type and permissions for each file (as per ls -l) | 列出權(quán)限標(biāo)示 |
| -P | List only those files that match the ?wild-card ?pattern. ??Note: ?you must ?use ?the -a option to also consider those files beginning with a ?dot ‘.’ for matching. ?Valid wildcard operators are ‘*’ (any ?zero ?or more ?characters), ?‘?’ ?(any ?single ?character), ‘[...]’ (any single character listed between brackets (optional ?- ?(dash) ?for ?character range ?may be used: ex: [A-Z]), and ‘[^...]’ (any single character not listed in brackets) and ‘|’ separates alternate patterns | 只顯示符合范本樣式的文件或目錄名稱 |
| -q | Print non-printable characters in filenames as question marks ?instead of the default caret notation | 用"?"號(hào)取代控制字符,列出文件和目錄名稱 |
| -s | Print the size of each file in bytes along with the name | 列出文件或目錄大小 |
| -t | Sort the output by last modification time instead of alphabetically | 用文件和目錄的更改時(shí)間排序 |
| -u | Print the username, or UID # if no username is available, of the file | 列出文件或目錄的擁有者名稱,沒有對應(yīng)的名稱時(shí),則顯示用戶識(shí)別碼 |
| -x | Stay on the current file-system only. ?Ala find -xdev | 將范圍局限在現(xiàn)行的文件系統(tǒng)中,若指定目錄下的某些子目錄,其存放于另一個(gè)文件系統(tǒng)上,則將該子目錄予以排除在尋找范圍外 |
【示例】:
1、基本用法:以樹形羅列目錄
[root@oldboy ~]# tree oldboy
oldboy
├── ext
│?? └── oldboy
├── jeacen
├── oldboy
├── test
├── wodi.gz
├── xiaodong
├── xiaofan
├── xingfujie
└── yingsui.gz
?
2、只羅列目錄
[root@oldboy ~]# tree -d
.
├── data
│?? ├── dir1
│?? ├── dir2
│?? ├── dir3
│?? ├── dir4
│?? └── dir5
└── oldboy
????├── ext
????├── test
????├── xiaodong
????├── xiaofan
????└── xingfujie
?
3、只羅列目錄,顯示深度為1層
[root@oldboy ~]# tree -Ld 1
.
├── data
└── oldboy
?
4、顯示完整的相對路徑
[root@oldboy ~]# tree -f data
data
├── data/c.txt
├── data/dir1
├── data/dir2
├── data/dir3
├── data/dir4
├── data/dir5
├── data/d.txt
├── data/e.txt
├── data/oldboy.txt
└── data/test.txt
?
5、不以階梯狀形式顯示
[root@oldboy ~]# tree -i data
data
c.txt
dir1
dir2
dir3
dir4
dir5
d.txt
e.txt
oldboy.txt
test.txt
?
6、為顯示內(nèi)容添加提示符
[root@oldboy ~]# tree -F oldboy
oldboy
├── ext/
│?? └── oldboy
├── jeacen
├── oldboy
├── test/
├── wodi.gz
├── xiaodong/
├── xiaofan/
├── xingfujie/
└── yingsui.gz
?
?
?
47.?【命令】:id
【功能說明】:
print real and effective user and group IDs ?#顯示用戶ID及組ID
【語法格式】:
id [OPTION]... [USERNAME]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | ignore, for compatibility with other versions | ? |
| -Z | print only the security context of the current user | ? |
| -g | print only the effective group ID | 顯示用戶所屬群組的ID |
| -G | print all group IDs | 顯示用戶所有群組的ID |
| -n | print a name instead of a number, for -ugG | 顯示用戶所屬群組的名稱 |
| -r | print the real ID instead of the effective ID, with -ugG | 顯示實(shí)際ID |
| -u | print only the effective user ID | 顯示用戶ID |
【示例】:
1、基本用法:顯示用戶ID及組ID
[oldboy@oldboy ~]$ id oldboy
?
2、顯示用戶ID
[oldboy@oldboy ~]$ id -u oldboy
500
?
?
48.?【命令】:ln
【功能說明】:
make links between files ?#創(chuàng)建鏈接
【語法格式】:
ln [OPTION]... [-T] TARGET LINK_NAME ??(1st form)
ln [OPTION]... TARGET ?????????????????(2nd form)
ln [OPTION]... TARGET... DIRECTORY ????(3rd form)
ln [OPTION]... -t DIRECTORY TARGET... ?(4th form)
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -f | remove existing destination files | 鏈接時(shí)先將與dist同檔案名的檔案刪除 |
| -d | allow the superuser to attempt to hard link ?directories ?(note: ?will probably fail due to system restrictions, even for the superuser) | 允許系統(tǒng)管理者硬鏈接自己的目錄 |
| -i | prompt whether to remove destinations | 在刪除與dist同名的檔案時(shí)先進(jìn)行詢問 |
| -n | treat ?destination ?that ?is ?a symlink to a directory as if it were a normal file | 在進(jìn)行軟鏈接時(shí),將dist視為一般的檔案 |
| -s | make symbolic links instead of hard links | 創(chuàng)建軟鏈接 |
| -v | print name of each linked file | 在鏈接之前顯示其檔案名 |
| -b | like --backup but does not accept an argument | 將在鏈接時(shí)會(huì)被覆寫或刪除的檔案進(jìn)行備份 |
| -S | override the usual backup suffix | 將備份的檔案都加上SUFFIX的字尾 |
【示例】:
1、基本用法:創(chuàng)建文件硬鏈接
[root@oldboy ~]# ln oldboy.txt oldboy_hard_link
[root@oldboy ~]# ls
anaconda-ks.cfg ?install.log ????????log2.txt ?oldboy_hard_link ?oldboy.txt
data ????????????install.log.syslog ?oldboy ???oldboy.tar.gz ????test.txt
?
2、基本用法:創(chuàng)建文件軟鏈接
[root@oldboy ~]# ln -s oldboy.txt oldboy_soft_link
[root@oldboy ~]# ls
anaconda-ks.cfg ?install.log ????????log2.txt ?oldboy_hard_link ?oldboy.tar.gz ?test.txt
data ????????????install.log.syslog ?oldboy ???oldboy_soft_link ?oldboy.txt
?
?
49.?【命令】:du
【功能說明】:
estimate file space usage ?#查看文件和目錄大小
【語法格式】:
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| -a | write counts for all files, not just directories | 顯示目錄中所有文件大小 |
| -b | equivalent to ‘--apparent-size --block-size=1’ | 顯示目錄或文件大小時(shí),以byte為單位 |
| -c | produce a grand total | 顯示一個(gè)大小總和 |
| -k | like --block-size=1K | 以KB為單位輸出 |
| -m | like --block-size=1M | 以MB為單位輸出 |
| -s | display only a total for each argument | 僅顯示總計(jì),只列出最后加總的值 |
| -h | print sizes in human readable format (e.g., 1K 234M 2G) | 人類可讀 |
| -x | skip directories on different file systems | 以一開始處理時(shí)的文件系統(tǒng)為準(zhǔn),若遇上其它不同的文件系統(tǒng)目錄則略過 |
| -L | dereference all symbolic links | 顯示選項(xiàng)中所指定符號(hào)鏈接的源文件大小 |
| -S | do not include size of subdirectories | 顯示個(gè)別目錄的大小時(shí),并不含其子目錄的大小 |
| -X | exclude files that match any pattern in FILE | ? |
| --exclude=PATTERN | exclude files that match PATTERN | 略過指定的目錄或文件 |
| -D | dereference only symlinks that are listed on the command line | 顯示指定符號(hào)鏈接的源文件大小 |
| -H | equivalent to --dereference-args (-D) | 與-h參數(shù)相同,但是是以1000為換算單位 |
| -l | count sizes many times if hard linked | 重復(fù)計(jì)算硬鏈接的文件 |
【示例】:
1、基本用法:顯示目錄或文件所占空間
[root@oldboy ~]# du
4 ??????./oldboy/xiaofan
8 ??????./oldboy/ext
4 ??????./oldboy/xingfujie
4 ??????./oldboy/xiaodong
4 ??????./oldboy/test
40 ?????./oldboy
4 ??????./data/dir5
4 ??????./data/dir1
4 ??????./data/dir2
4 ??????./data/dir3
4 ??????./data/dir4
28 ?????./data
172 ????.
?
2、顯示指定文件所占空間
[root@oldboy ~]# du oldboy.txt
4 ??????oldboy.txt
?
3、顯示指定目錄所占空間
[root@oldboy ~]# du oldboy
4 ??????oldboy/xiaofan
8 ??????oldboy/ext
4 ??????oldboy/xingfujie
4 ??????oldboy/xiaodong
4 ??????oldboy/test
40 ?????oldboy
?
4、以易讀模式顯示
[root@oldboy ~]# du -h
4.0K ???./oldboy/xiaofan
8.0K ???./oldboy/ext
4.0K ???./oldboy/xingfujie
4.0K ???./oldboy/xiaodong
4.0K ???./oldboy/test
40K ????./oldboy
4.0K ???./data/dir5
4.0K ???./data/dir1
4.0K ???./data/dir2
4.0K ???./data/dir3
4.0K ???./data/dir4
28K ????./data
172K ???.
?
?
50.?【命令】:which
【功能說明】:
shows the full path of (shell) commands ?#從PATH變量所在路徑查找二進(jìn)制命令
【語法格式】:
which [options] [--] programname [...]
【選項(xiàng)參數(shù)】:
| 參數(shù) | 說明 | 簡解 |
| ? | ? | ? |
| ? | ? | ? |
| ? | ? | ? |
| ? | ? | ? |
【示例】:
1、基本用法:查找命令
[root@oldboy ~]# which cat
/bin/cat
?
轉(zhuǎn)載于:https://www.cnblogs.com/scoter2008/p/5470141.html
總結(jié)
以上是生活随笔為你收集整理的初识50个Linux命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Bootstrap验证控件的使用
- 下一篇: 两个div叠加触发事件发生闪烁问题