Shell(二)常用命令和技巧
命令列一些技巧:
*
表示任意字元(也可以無字元)
?
任意一個單字元
[a-z]
包含一個字元範圍中的任一字元
[^a-z]
不包含此範圍的字元
Tab鍵
補齊命令名稱或其他名稱
history
重新輸入以前執行過的指令
!+序號
^
替代上個命令中的某一段字元
如^2^1 將上個命令中的1替換為2
~
進入家目錄(home directory)
~root
~user1
$
變數名
如 echo $HOME
{}
排列組合
a{a,b}=aa,ab
`` or $()
優先執行的命令
echo "Hostname: `hostname`"
$[]
進行數學計算
echo $[$a + $b]
\
後面的命令接著前面的
"
禁止所有特殊資源的功能,除了$ \ ` !
’
禁止所有特殊資源的功能
+. or +.
補齊上個命令的最後一個引數
set -o/+o vi
切換編輯模式
常用命令:
date
cal: calendar
pwd: parent working directory
cd: change directory
ls: list directory contents
cp: copy files and directories
mv: move and/or rename files and directories
rm: remove files
touch: create empty files or update file timestamps
mkdir: make a directory
rmdir: remove an empty directory
file: check file type
cat: view an entire text file
less: view text page by page
cut: display specific columns of file data
sort: sort text to standard out - original file unchanged
chmod: change access modes
df: report disk space usage(free)
du: report disk space usage(used)
tar: create/extract an archive
gzip: compress
bzip: compress
gunzip: extract
bunzip: extract
passwd: change password
su: start a new shell as a different user
sed: search and replace
head: display first few lines(default 10 lines) of text in a file
tail: display last few lines(default 10 lines) of text in a file
wc: “count lines, words and characters”
uniq: “remove successive, duplicate lines in a file”
paste: paste files together
tr: character translator
diff: version comparison
sdiff: version comparison
aspell: spell checking
expand: expand tabs into spaces
fmt: reformat text into paragraphs
pr: reformat text for printing
top: display snapshot of processes
vmstat: report virtual memory stats
free: summary of system memory usage
renice: change priority of a process
kill: send system signal to a process
fdisk: create partitions
partprobe: reinitialize the kernel in memory of the partition table
mke2fs: filesystem creation
lsattr: display file attributes
chattr: change file attributes
ln: linkname
alias: create shortcuts to commands
whoami: find out who you are
groups: find out what groups you belong to
id: find out what groups you belong to
users: find out who is logged in
who: find out who is logged in
w: find out who is logged in
last: login/reboot history