cut |
截取的方式有三種,一是按照字符位置,二是按照字節位置,三是使用一個分隔符將一行分割成多個field,並提取指定的fields。 cut命令有5個參數,其中-c,-b,-f分別表示"character", "byte"以及"field"截取方式。當採用field模式截取時,需要用"-d"參數指定一個分隔符,分割符只能爲單個字符。另外還有一個"- s",suppress,表示如果行中沒有給出的分割符則不輸出該行 echo Long, long ago | cut -f 2,3 -d " " echo hello, world | cut -c 8-12 |
paste |
paste -d -s -file1 file2 -d 指定不同於空格或tab鍵的域分隔符。例如用@分隔域,使用- d @。 -s 將每個文件合併成行而不是按行粘貼, 多行轉成一行。 paste file1 file2 paste –d : file1 file2 paste -s pas1 pas2 (把第一個文件的多行轉成一行作爲第一行顯示,把第二個文件的多行轉成一行作爲第二行顯示) paste –s file1 (把文件中的多行轉成一行) ls /etc | paste –d " " (把一行的內容按指定分隔符放到一列顯示) |
cal |
cal 2004 cal 04 2004 |
who |
who whoami who am i |
date |
date +%Y%m%d date +%Y%m%d.%H%M%S |
clear |
|
tty |
Display the name of terminal one is using |
uname |
uname -a (顯示unix版本號) |
more |
Display each file pagewise. On pressing enter key, the 2nd file gets displayed.
more file1 file2 |
stty |
change and display terminal settings |
bc |
open arbitrary precision calculator |
printf |
|
type |
display description and location of a command type cat type vi |
which |
just display the location of the command. which cat which vi |
echo |
echo * | wc all files and directories in current directory. echo */ | wc all directories in current directory. echo *.* | wc all files which have extensions in current directory --above commands don’t count hidden files. |
ls |
-a, -l, -i, -r, -t, -s, -u(display and sort by atime instead of mtime) |
cp |
-r -i -f -a -U |
mv |
move the contents of file1 to file2. The file1 is deleted. |
pwd |
pwd -P |
cd |
cd .. cd test cd (change to user’s directory) cd ~ cd ~tmapbatch cd -
|
mkdir |
mkdir –p /test/test1/test2 mkdir –m 711 test |
rmdir |
-r -i -f |
rm |
Removal of a file needs write permission in its directory. -r -f -i |
ln |
(hardware link, Symbolic link & Soft Link) hardware link : ln cprog1 cprog1.bat have same i-node numbers symbolic link : ln -s cprog2 /tmp/cprog2.bat have diff i-node numbers
soft link can be used to link file on a different file system soft link can be used to link directories. |
touch |
可以修改atime, mtime touch –a file1 (update access time by current datetime) touch –m file1 (update modification time by current datetime) touch –t [[cc]yy]mmddhhmm[.ss] file1 (update both atime and mtime by specified datetime)
|
basename |
basename /home/dpmbatch/andytest/1.txt basename $0 .ksh (ignore the suffix) |
dirname |
dirname /home/dpmbatch/andytest/1.txt |
input 0 output 1 error 2 |
ls 1>infy is as same as ls > infy ls abcd 2>errors cat errors |
tr |
主要用於刪除文件中控制字符或進行字符轉換 tr -s -c -d ["string1"] ["string2"] input_file -c 用string1的字符集的補集替換此string1,要求字符集爲ASCII
tr -s "[a-z]" < oops.txt or cat oops.txt | tr -s "[a-z]"
tr -s “ ” “:” < oops.txt
\n -- \012 \t -- \011 \r -- \015
刪除空行 tr -s "[\012]" < testing > testing1 && mv testing1 testing
小寫到大寫 cat testing | tr "[a-z]" "[A-Z]" tr "[a-z]" "[A-Z]" < testing
刪除指定字符 刪除不是字母的內容,步驟爲先用換行符替代全部非字母的內容,然後刪除重複的換行符。其中,替換用-c,刪除重複用-s tr -cs "[a-z][A-Z]" "[\012*]" < diary.txt
匹配多個字符 tr "[0*4]" "*" < hdisk.txt
把4個0替換成4個* |
*, ?, [], [!] |
ls [!ab]* |
regular expressions |
[^a-z] ab\{2,4\} |
cmp |
it displays the byte and the line number of the first difference. -l display for each difference -s return 0 if same, 1 if different, 2 if file is inaccessible. |
sort |
-d dictionary order sort -n arithmetic/numeric order -r reverse order -k n Sorts on field n -b ignore leading blanks -t set the delimiter
sort –t ‘:’ –k 3 file1 |
comm |
compare 2 sorted files. return three-columnar output first column contains unique to the first file second column contains unique to the second file third column common to both files.
-1 does not print column 1 -2 does not print column 2 -3 does not print column 3
|
head |
head -5 file1 |
tail |
tail -5 file1 tail -f file1 參數-f使tail不停地去讀最新的內容,這樣有實時監視的效果 |
cat |
-A -n |
nl |
nl file1 |
tac |
|
more |
|
less |
|
od |
|
wc |
-l -c -w |
diff |
reports the difference between files. -b ignore trailing whitespaces and compare other strings of space characters.
diff file1 file2 |
uniq |
to remove adjacent repeated lines -u display only the lines not repeated in the file named input -d display only the lines that are repeated in the file input -c precede each line displayed by the number of times it occurs. +n ignore the first n characters including whitespace -m ignore the first m fields and any blanks.
uniq –u file1 |
|
tr -cs 'A-Za-z' '[\n*]' < test2 | tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr | head -20 |
grep |
-c report only the number of matching lines -l list only the names of files containing pattern. -v display all lines except those containing pattern. |
umask |
|
chown |
chmod user1 file1 |
chmod |
chmod ugo+rwx file1 |
chgrp |
|
default permission |
file 666 – 022 = 644
directory 777-022 = 655
if read permission is off, you cannot use ls; if execute permission is off, you cannot cd into direcotry |
vi |
/pattern ?pattern :s/ptn1/ptn2 (first occurrence) :s/ptn1/ptn2/g (all occurrence in current line) :m, n s/ptn1/ptn2/g (all occurrence from line m to n) :., $ s/ptn1/ptn2/g (all occurrence from current line to end of file) |
sed |
sed '/^$/d' hello sed '/^ *$/d' hello sed '/^[ ]*[\t]*$/d' hello or sed '/^[ ]*[ ]*$/d' hello sed -n '1,2p' hello sed -n '3,$p' hello |
sendmail |
SUBJ="Workflow ${WORKFLOW_NAME} failed!" TO=""
( echo To : "${TO}" echo Subject : "${SUBJ}"
echo "${1}\n${2}" echo "Workflow ${WORKFLOW_NAME} failed!"
)|/usr/lib/sendmail ${TO} |
UNIX 命令
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.