一天一Linux command

Linux command 縮寫對照

♘ ♘ ♘

▨ cd: change directory

cd /home/yourFile

 
▨ cp: copy file
cp src dst -r

 
▨ rsync
#比cp好用, 速度更快
rsync -ravP src dst

 
▨ rm: remove file

rm yourFile -rf

 
▨ mv: move file
mv src dst

 
▨ ln: link files

▨ ls: list files

ls -al   #list all files
ls -alh   #list all files(include file size)

 
▨ mkdir: make directory
mkdir filename
 
#加了這個 -p 的選項,可以自行建立多層目錄

 
▨ pwd: print work directory
▨ su: switch user

▨ file

▨ find

#找檔案, i:ignore大小寫
find /home/yourpath -iname "yourfile"

 
▨ grep
#找程式裡的內文, i:ignore大小寫, n:列印行數, r:recursive
grep -inr 'symbol' filename

 
▨ cat: concatenate
cat file  #print it out
 
cat file1 file2 >> file3 
#把文件1和文件2的内容連接起來放到文件3

 
▨ man: manual
man xxx

 
▨ poweroff
▨ reboot
▨ shutdown

▨ ps

#report process status
ps -ef | grep xxx

 
▨ df: disk free
#列出所有 filesystem 整體磁碟使用量
#-h : 以人們較易閱讀的 GBytes, MBytes, KBytes 等格式自行顯示
df -h

 
▨ du: disk usage
#列出檔案或目錄的使用空間
du

 
▨ dumpe2fs
#裝置的檔案系統內容
dumpe2fs /dev/sda1 -h

 
▨ mount
mount src dst

 
▨ umount
umount -l /path/yourFile/
#Device is busy
fuser -m /media/share
fuser -m -v -i -k /media/share

 
▨ who
who        #show who is logged on
who -b    #time of last system boot

 
▨ ssh: secure shell
ssh rickymax@140.118.192.198
ssh 140.118.192.198 -l rickymax

 
▨ scp: secure copy
scp src root@dst-ip:~

 
▨ rpm: rpm package manager
rpm -Uvh *.rpm

 
▨ ifconfig
#列出目前已經被啟動的卡 (無論有無賦予IP)
#取得網路卡狀態 修改網路卡狀態 工具
ifconfig

 
▨ ping
ping xxx.xxx.xxx.xxx

 
▨ wget
#non-interactive download of files from the Web
wget http://xxx.com/xxx.xxx

 
▨ history
export HISTTIMEFORMAT='%F %T '
history
#相較於history查看過去打過的指令
#另外一個方法就是 Ctrl+r 去搜尋打過的指令
#找下一個(Ctrl+r), 結束按左或右

 
▨ dd
dd if=/dev/sda of=/dev/sdb #備份至sdb, sdb甚至也不需分割與格式化
dd if=/dev/zero of=./hello bs=1M count=1024 #產生一個1Ghello檔到此目錄下

 
tmux

  
▨ fuser
fuser -a /PATH
ps -ef | grep ????c
ps -ef | grep ????
kill -9 ???

 

git

Git intro.

#列出 當前擁有的所有分支
git branch
 
#列出 遠端所有分支
git branch -a
 
#偷 gitconfig
cp /home/adamchen01/.gitconfig /home/rickymax/
#偷完記得回去改成自己的路徑
 
#查看 git log
git log
 
#或是貼心的人寫好的
git lg
 
#Note: push 之前要先 pull

git diff

▨ 設定
用了之後就可以 git 結合 diffmerge

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true

只要設定一次就可以

 
▨ git diff
換成使用 difftool

git difftool

git difftool file.c

 
▨ git merge
換成使用 mergetool
git mergetool

 

vim

tutorial


  • 搜尋
/

在想追蹤的變數上面按下不起眼的星號「 * 」,接著用 n 往下搜尋,N 往上搜尋。

在函式的左大括號按下 「%」 ,馬上就會跳到對應的右大括號了

「gd」找到此變數,區域變數宣告的地方

「gD」找到此變數,全域變數宣告的地方

 

  • 取消搜尋
:noh

 
  • 搜尋特定的字
/\<Word\>

 
  • 搜尋包含空白的字 (用.表示任意字)
/hello.world

 
  • mark label
m
 
熱鍵

 
  • 搜尋射過的熱鍵
"
 
熱鍵

.vimrc

nnoremap <silent> <F5> :NERDTree<CR>
nnoremap <silent> <F3> :TlistToggle<CR>
nnoremap <silent> <F4> :wincmd p<CR>
nnoremap <silent> <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
nnoremap <silent> <F6> :!make<CR>
nnoremap <silent> <F7> :set nonumber<CR>
nnoremap <silent> <F8> :set number<CR>

set nocp
filetype plugin on
set number
set tags+=~/std.tags
au BufNewFile,BufRead *.md set filetype=lisp
au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.def set filetype=cpp
au BufNewFile,BufRead *.cpp set syntax=cpp11

let Tlist_Exit_OnlyWindow = 1

" \t = 4 space
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4

" High light unwanted spaces in end of line
highlight ExtraWhitespace ctermbg=darkred guibg=darkcyan
autocmd BufEnter * if &ft != 'help' | match ExtraWhitespace /\s\+$/ | endif
autocmd BufEnter * if &ft == 'help' | match none /\s\+$/ | endif

" High light over length in a line
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>79v.\+', -1)

" status bar
set ls=2
set statusline=%<%f\ %m%=\ %h%r\ %-19([%p%%]\ %3l,%02c%03V%)%y
highlight StatusLine ctermfg=blue ctermbg=white

" search word match with hilight
set hlsearch

 

新增硬碟或分割槽

see: http://www.gtwang.org/2012/02/linux.html


-列出硬碟的 partition table

fdisk -l

 
-分割 sda 磁碟
fdisk /dev/sdb     // 不可加編號, sdc or sdd  or ...
#進入互動模式, m for help
1. 新增分割區,輸入 nEnter2. 輸入 pEnter(如果新硬碟只需要一個分割區)
3. 選擇 Partition numberprimary 分割區最多可以有四個,輸入 1Enter4. 輸入開始的 cylinder,用預設值就可以了,直接按 Enter5. 輸入結束的 cylinder,若是要用最大的容量,就直接按 Enter6. 最後將分割表寫入硬碟,輸入 w 再按 Enter

 
-Format the partition
mkfs -t ext4 /dev/sdb1

 
-Format the partition by xfs (optional)
apt-get install xfsprogs
mkfs.xfs -i size=512 /dev/sdb1

 
-Mount the partition (as a Gluster "brick")
mkdir -p /export/sdb1
mount /dev/sdb1 /export/sdb1
mkdir -p /export/sdb1/brick

 
-Add an entry to /etc/fstab
echo "/dev/sdb1 /export/sdb1 xfs defaults 0 0"  >> /etc/fstab

 

建立軟體 RAID

-Prerequisites

yum install mdadm

 
-Identifying available data disks
fdisk -l

 
-creating the RAID 0
mdadm -Cv /dev/md0 -l0 -c128 -n2 /dev/sd{b,c}

-C  建立
-v  查看過程
-c128  chunk size
-n2   # of component devices

 
-Checking

cat /proc/mdstat

 
-Partitioning the RAID 0
fdisk /dev/md0

 
-Checking
fdisk -l

 
-Creating the file system on the RAID 0
mkfs -t ext4 /dev/md0p1

 
-Mount this RAID
mkdir /mnt/md0p1
mount /dev/md0p1 /mnt/md0p1

 

 
-RAID detail info

mdadm --detail /dev/md0p1

 
-Update config file
mdadm --detail --scan >> /etc/mdadm.conf

 
-Removing a RAID device
mdadm --stop /dev/md0
mdadm --remove /dev/md0
mdadm --zero-superblock /dev/sd{b,c}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License