Linux & Command line

Often Used

tail -f file check files that change often(log file)
head -2 file.txt first 2 lines
tail -1 file.txt last line
find /sbin -name *v find a file in sbin which ends in v. -iname means case insensitive
rmdir [-p] directory remove a directory
rm -rf directory recursively removes directory
mkdir -p dir1/dir2/dir3 -p represents creating parents
sudo -i login as root
echo "cd ~/Desktop/Java\ Files" >> ~/.bashrc set default directory in ubuntu
ps -fA | grep python 查看所有python進(jìn)程
killall -9 python kill所有python進(jìn)程,9代表force
cd change to HOME directory
ls -a list all hidden files
man ls display the manual page for the item
ls -l shows file or directory, size, long listing
ls -al long listing including hidden files
echo $PATH show path variables
!$ the last argument of the previous command
!! the last command
history print history command
![command id] or !-2(last last) execute command id
echo *.jpeg print files of a specific kind
file [filename] what is the type of this file
less [filename] see what is in filename = more [filename]
cat [filename] see the content of the file
cat是一次性顯示整個(gè)文件的內(nèi)容事哭,還可以將多個(gè)文件連接起來顯示瓜富,它常與重定向符號(hào)配合使用,適用于文件內(nèi)容少的情況与柑;
more和less一般用于顯示文件內(nèi)容超過一屏的內(nèi)容谤辜,并且提供翻頁的功能。more比cat強(qiáng)大丑念,提供分頁顯示的功能,less比more更強(qiáng)大脯倚,提供翻頁,跳轉(zhuǎn)推正,查找等命令恍涂。而且more和less都支持:用空格顯示下一頁植榕,按鍵b顯示上一頁。
ctrl + L = clear can be used when typing
ctrl + A move cursor to the command beginning
ctrl + E move cursor to the command end
echo "Test Page" > testpage type into testpage file

curl
curl --user name:password http://somesite.com -v login
curl --data "Username=xx&Password=xx&Login=Login" [url that your form submits] login
curl --user user:pass --cookie-jar ./somefile https://xyz.com/a save cookie to file
curl --cookie ./somefile https://xyz.com/b read cookie from file

ls -latr long listing including all files reverse sorted by time
ls -t list files by time, most recent first
ls -r reverse order
ls -R list directories recursively
tree list tree structure of the directory and files
tree -d only directory structure

ls -l "my notes.txt" Use double or single quotes to avoid space confusion

  • ls -F list files by type:
    / is a directory
    @ is a symbolic link
    * is an executable

Permissions

- regular file
d directory
l symbolic link

-rw-r--r--
first - is permission type
next three for user
next three for group
next three for other

chmod change mode
ugoa user category: user, group, other, all
+-= add, substract or set permissions
rwx read, write, execute

chmod g+rwx sales.data add rwx permissions to sales.data
chmod g+wx, u+rwx file, o= add to multiple groups, here o is ---

Permission order is in rwx.
Avoid 777(rwx) and 666(rw-).
chmod 400 my-cat400 only read permission for user, others no permissions
500 read + execute

chgrp sales sales.data change group to sales for this sales.data file

VIM

vi [file]
vim [file] strengthed vi
view [file] read mode

command mode
Use Esc to enter command mode
k,j,h,l up, down, left, right
^ go to the beginning
$ go to the end

insert mode
i insert at the cursor position
I insert at the beginning of the line
a append after the cursor position
A append at the end of the line

line mode
start with :
:w saves the file
:w! forces the file to be saved
q! quit without saving
wq! write and quit
:15 go to the 15th line
:$ position the cursor on the last line
:set nu turn on line numbering
:set nonu turn off line numbering

repeating commands
8k move up 8 lines

deleting text
x delete a character
dw delete a word
dd delete a line
D delete from the current position

changing text
r replace the current character
cw change the current word
cc change the current line
c$=C change the text from the current position
~ reverse the case of a character

copy & paste
yy copy the current line
y3w copy 3 words from the current position
p paste the most recent deleted or copied text

undo/redo
u undo
Ctrl+R redo

search
/the forward searching the word "the", n to go to the next item, N to go to the previous item

Manipulate files

rm file remove file
rm -r dir remove the directory and its contents recursively
rm -f file force removal
cp src_file dest_file
cp src_file [src_files] dest_dir
cp -r src_dir des_dir recursively copy from directory
mv src_file des_dir
mv src_file des_file
mv -i, cp -i interactive mode

tar archive
tar cxtvzf tarfile
c: create a tar archive
x: extract files from the archive
t: display the table of content
v: be verbose
z: use compression
f file use this file
tar cf target.tar [dir] - create a target.tar with dir content
tar tf tps.tar list content
tar xf target.tar extract content
tar xvf target.tar verbose version(list what is being extracted)
tar zcf target.tar.gz(tgz) directory create compressed directory

compression
gzip compress files
gunzip uncompress files
du -k file display sizes in kilobytes
du -h file display sizes in human readable format

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市寝衫,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌竞端,老刑警劉巖庙睡,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件属瓣,死亡現(xiàn)場(chǎng)離奇詭異莽红,居然都是意外死亡抡句,警方通過查閱死者的電腦和手機(jī)岛蚤,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門刚操,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蜀细,“玉大人贵扰,你說我怎么就攤上這事×鞑浚” “怎么了?”我有些...
    開封第一講書人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵枝冀,是天一觀的道長(zhǎng)耘子。 經(jīng)常有香客問我,道長(zhǎng)球切,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任吨凑,我火速辦了婚禮,結(jié)果婚禮上怀骤,老公的妹妹穿的比我還像新娘。我一直安慰自己蒋伦,他們只是感情好弓摘,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開白布痕届。 她就那樣靜靜地躺著,像睡著了一般研叫。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上嚷炉,一...
    開封第一講書人閱讀 51,274評(píng)論 1 300
  • 那天,我揣著相機(jī)與錄音申屹,去河邊找鬼绘证。 笑死,一個(gè)胖子當(dāng)著我的面吹牛嚷那,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播杆煞,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼决乎!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起构诚,我...
    開封第一講書人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎唤反,沒想到半個(gè)月后凳寺,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡肠缨,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了晒奕。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片闻书。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡脑慧,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出闷袒,到底是詐尸還是另有隱情坑律,我是刑警寧澤囊骤,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站也物,受9級(jí)特大地震影響宫屠,放射性物質(zhì)發(fā)生泄漏滑蚯。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一告材、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧创葡,春花似錦浙踢、人聲如沸绢慢。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至缚窿,卻和暖如春棘幸,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背误续。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工吨悍, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蹋嵌,地道東北人育瓜。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓躏仇,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親腺办。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354