切換目錄 cd dirname
cd 進入主目錄
cd ~ 進入用戶主目錄
cd - 返回進入此目錄之前所在的目錄
cd .. 返回上級
cd ../.. 返回上兩級目錄
cd !$ 把上個命令的參數作爲cd參數使用
ls:顯示文件和目錄的信息
顯示文件和目錄的信息
ls 以默認方式顯示當前目錄文件列表
ls -a 顯示所有文件包括隱藏文件
ls -l 或 ll 顯示文件屬性,包括大小,日期,符號連接,是否可讀寫及是否可執行
ls -lc 列出文件的最後更改時間
ls -lu 列出文件的最後訪問時間
ls -lh 顯示文件的大小,以容易理解的格式印出文件大小 (例如 1K 234M2G)
ls -lt 顯示文件,按照修改時間排序
sed是一種流編輯器,它是文本處理中非常有用的工具,可以完美配合正則表達式使用。
格式: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space (不顯示自動輸出內容)
-e script, --expression=script
add the script to the commands to be executed (將腳本添加到要執行的命令中)
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed (添加腳本文件內容到要執行的命令中)
--follow-symlinks
follow symlinks when processing in place (處理到位時遵循符號鏈接)
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied) (就地編輯文件,如果提供後綴則進行備份)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command (爲 'l' 命令指定所需的換行長度)
--posix
disable all GNU extensions. (禁用所有GNU拓展)
-r, --regexp-extended
use extended regular expressions in the script. (在腳本中使用拓展正則表達式)
-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 (從輸入文件加載最小數量的數據並刷新輸出緩衝區)
-z, --null-data
separate lines by NUL characters (按數字字符分隔行)
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first 如果沒有指定 -e 或者 -f 選項,則第一個非選項參數被視作要解釋的seq腳本,其他剩餘參數作爲輸入文件的名字
non-option argument is taken as the sed script to interpret. all 如果沒有指定輸入文件,會讀取標準輸入
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
eg:
1、組合多個表達式
sed '表達式' | sed '表達式'
等價於
sed '表達式; 表達式'
2、引用
sed表達式可以使用單引號來引用,但是如果表達式內部包含變量字符串,就需要使用雙引號。
3、替換字符串
sed -i 's/需要替換的字符串/替代字符串/' filename 會替換所有匹配的字符串
4、替換行
sed -i '/匹配行/c 新內容' filename
eg: sed -i '/aba/c 11111' a.txt 將a.txt中包含aba字符的行替換爲 11111
file:確定文件類型
確定文件類型
Usage: file [OPTION...] [FILE...]
Determine type of FILEs.
--help display this help and exit
-v, --version output version information and exit (輸出版本信息並退出)
-m, --magic-file LIST use LIST as a colon-separated list of magic number files (使用LIST給magic number 文件以冒號分隔)
-z, --uncompress try to look inside compressed files (嘗試查看壓縮文件)
-b, --brief do not prepend filenames to output lines
-c, --checking-printout print the parsed form of the magic file, use in (輸出magic文件的解析格式,用於和-m一起在安裝新的magic文件前先調試它)
conjunction with -m to debug a new magic file
before installing it
-e, --exclude TEST exclude TEST from the list of test to be (從要對文件執行的測試列表中排除測試
performed for file. Valid tests are: 有效的測試是:apptype,ascii,cdf,compress,elf,encoding,soft,tar,text,tokens)
apptype, ascii, cdf, compress, elf, encoding,
soft, tar, text, tokens
-f, --files-from FILE read the filenames to be examined from FILE
-F, --separator STRING use string as separator instead of `:'
-i, --mime output MIME type strings (--mime-type and
--mime-encoding)
--apple output the Apple CREATOR/TYPE
--mime-type output the MIME type
--mime-encoding output the MIME encoding
-k, --keep-going don't stop at the first match (不在第一次匹配就停下來)
-l, --list list magic strength (列出magic強度)
-L, --dereference follow symlinks (default if POSIXLY_CORRECT is set) (遵循符號鏈接,未設置則默認爲POSIXLY_CORRECT)
-h, --no-dereference don't follow symlinks (default if POSIXLY_CORRECT is not set) (不遵循符號鏈接,未設置則默認爲POSIXLY_CORRECT)
-n, --no-buffer do not buffer output (不緩衝輸出)
-N, --no-pad do not pad output (不覆蓋輸出)
-0, --print0 terminate filenames with ASCII NUL (用 ASCII NUL 終止文件名)
-p, --preserve-date preserve access times on files
-P, --parameter set file engine parameter limits
indir 15 recursion limit for indirection
name 30 use limit for name/use magic
elf_notes 256 max ELF notes processed
elf_phnum 128 max ELF prog sections processed
elf_shnum 32768 max ELF sections processed
-r, --raw don't translate unprintable chars to \ooo (不將無法打印的字符轉化爲\ooo)
-s, --special-files treat special (block/char devices) files as ordinary ones (對特殊(塊字符設備)文件視爲一般文件)
-C, --compile compile file specified by -m (編譯由-m指定的文件)
-d, --debug print debugging messages (打印調試信息)
head:查看文件開頭內容
查看文件開頭內容
Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output. 打印每個文件的前十行到標準輸出
With more than one FILE, precede each with a header giving the file name. 超過一個文件,在每一個文件前加上文件名的頭
With no FILE, or when FILE is -, read standard input. 如果沒有文件,或者文件是-,讀入標準輸入
Mandatory arguments to long options are mandatory for short options too. 規定的長參數和短參數的是一樣的
-c, --bytes=[-]K print the first K bytes of each file; 打印每個文件開頭k字節的內容
with the leading '-', print all but the last 使用引導符-,打印除了最後k字節的所有內容
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first 10; 打印每個文件開頭K行的內容
with the leading '-', print all but the last 使用引導符-,打印除了最後k行的所有內容
K lines of each file
-q, --quiet, --silent never print headers giving file names 不打印文件名
-v, --verbose always print headers giving file names 打印文件名
--help display this help and exit 顯示這個幫助並退出
--version output version information and exit 輸出版本信息並退出
K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, k可以有多種後綴名
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
tail:查看文件末尾內容
查看文件末尾內容
Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output. 打印每個文件的最後1-行到標準輸出
With more than one FILE, precede each with a header giving the file name. 超過一個文件,在每一個文件前加上文件名的頭
With no FILE, or when FILE is -, read standard input. 如果沒有文件,或者文件是-,讀入標準輸入
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=K output the last K bytes; alternatively, use -c +K 輸出最後k字節,
to output bytes starting with the Kth of each file 使用-c +K 從每個文件的第K個開始輸出字節
-f, --follow[={name|descriptor}]
output appended data as the file grows; 隨着文件增長輸出附加數據
-f, --follow, and --follow=descriptor are
equivalent
-F same as --follow=name --retry 與 --follow=name --retry 相同
-n, --lines=K output the last K lines, instead of the last 10; 輸出後 K行, 使用-n +K 輸出從第K開始的行
or use -n +K to output lines starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not 使用 --follow=name 在N次(默認5次)迭代後重新打開一個未更改大小的文件,查看它是否已被
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.
--pid=PID with -f, terminate after process ID, PID dies 使用-f,在進程ID,PID結束後終止
-q, --quiet, --silent never output headers giving file names 不在輸出頭上打印文件名
--retry keep trying to open a file even when it is or 即使文件變得不可訪問或變得不可訪問也繼續嘗試打開該文件
becomes inaccessible; useful when following by
name, i.e., with --follow=name
-s, --sleep-interval=N with -f, sleep for approximately N seconds 使用-f在迭代之間睡眠大約N秒(默認爲1.0),使用inotify 和 --pid=P,每隔N秒至少檢查進程P一次
(default 1.0) between iterations.
With inotify and --pid=P, check process P at
least once every N seconds.
-v, --verbose always output headers giving file names 輸出帶文件名
--help display this help and exit
--version output version information and exit
If the first character of K (the number of bytes or lines) is a '+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file. K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end. This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation). Use --follow=name in that case. That causes tail to track the
named file in a way that accommodates renaming, removal and creation.