Ubuntu(14.04LTS)學習劄記,ubuntu14.04lts
這篇博文是我在基於Ubuntu學習一些知識的劄記,方便日後進行不斷回顧,這裡進行統一記錄,當然當學到新的東西也會陸續更新!!!還請各位博主不要見笑,小弟在此謝過~\(≧▽≦)/~啦啦啦!!!!
1、Ubuntu的簡單配置:
由於個人原因,我並不喜歡在案頭上放一些很花哨的東西,追求簡約一直是我個人所推崇的。所以,我的Ubuntu系統配置也不例外,先上一張案頭的諜照:
sudo add-apt-repository ppa:numix/ppasudo apt-get updatesudo apt-get install numix-icon-theme-circle 1.2 常用軟體的安裝:
Unity Tweak Tool、新立得軟體包、搜狗IME,這三個軟體都可以在Ubuntu軟體中心和搜狗IME官網下載到,這裡不再贅述了,至於其他軟體我就不介紹了,因為我並沒有裝,需求不大。
Conky的安裝及配置:如果你想讓你的案頭能即時顯示一些資訊,Conky或許能夠幫到你。方便美觀便捷,你值得擁有。
//安裝:sudo apt-get install conky//配置://安裝好後Conky預設是不會為你建立對應的.conkyrc檔案,因此我們需要在當前的使用者目錄(我的是/home/hippiezhou)下建立一個對應的檔案。然後添加我們的配置代碼。
//我的配置代碼如下所示:use_spacer rightuse_xft yesfont Microsoft YaHei:size=8xftfont Microsoft YaHei:size=8#xftfont WenQuanYi Zen Hei:pixelsize=12override_utf8_locale yesupdate_interval 1.0own_window yesown_window_type normalown_window_transparent yesown_window_hints undecorated,below,sticky,skip_taskbar,skip_pagerdouble_buffer yesminimum_size 206 5maximum_width 400draw_shades yesdraw_outline nodraw_borders nodraw_graph_borders nodefault_color ffffffdefault_shade_color 000000default_outline_color 000000alignment top_rightgap_x 10gap_y 30cpu_avg_samples 2uppercase no # set to yes if you want all text to be in uppercaseTEXT${font Microsoft YaHei:style=Bold:pixelsize=30}${alignc}${time %H:%M:%S}${font Microsoft YaHei:pixelsize=18}${alignc}${time %b%d日 星期%a}${font Microsoft YaHei:pixelsize=12}${color #ffd700}${hr 1}$color${color #98c2c7}主機名稱:${color #db7093} $alignr$nodename${color #98c2c7}核心: ${color #db7093}$alignr$kernel${color #98c2c7}已開機: ${color #db7093}$alignr$uptime${color #98c2c7}IP地址: ${color #db7093} ${alignr} ${addr wlp1s0}${color #98c2c7}CPU使用率: ${color #db7093} $alignr$cpu%${color #78af78}$cpubar${color #ddaa00} ${top name 1}$alignr ${top cpu 1}${color lightgrey} ${top name 2}$alignr ${top cpu 2}${color lightgrey} ${top name 3} $alignr${top cpu 3}${color #98c2c7}實體記憶體:${color #4169e1}$alignr ${color}$mem ${color #98c2c7}/${color}$memmax${color #4169e1}${color #db7093}$memperc%${color #78af78}${membar}${color #98c2c7}根分區: ${color}${alignr}${fs_free /} / ${fs_size /}${color #78af78}${fs_bar 4 /}${color #98c2c7}Home分區: ${color}${alignr}${fs_free /home} / ${fs_size /home}${color #78af78}${fs_bar 4 /home}${color #98c2c7}下載速度:${color} ${downspeed wlp1s0} k/s${color #98c2c7}上傳速度:${color} ${upspeed wlp1s0} k/s${color #ffd700}${hr 1}$color
//為了保證Conky能在每次系統啟動的時候也啟動,我們需要為Conky添加系統啟動項。
//在你的Dash中搜尋“啟動應用程式”,然後把我們的Conky作為啟動項添加進去。
名稱:conky
命令:/usr/bin/conky -p 10
注釋:Load the conky
//註:如果你想手動啟動conky的話,只需要按住Ctrl+Alt+T然後輸入命令conky即可
1.3 禁用來賓模式:
vim /usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf
//在最後一行添加一句代碼:
allow-guest=false
//然後 ESC->:wq 進行儲存即可(可能需要sudo進行提權)
1.4 其他相關配置:
語言套件缺失:language-selector-gnome
flash安裝:sudo apt-get install flashplugin-installer(說實話,我安裝這個東西真的安裝很長時間,奇慢無比!)
2、Ubuntu命令:
sudo apt-get autoclean //清理舊版本的軟體緩衝
sudo apt-get clean //清理所有軟體緩衝
sudo apt-get autoremove //刪除系統不再使用的孤立軟體
uname -a //查看核心
sudo lshw //顯示當前硬體資訊
pstree //查看當前進程樹
//多線程下載
sudo apt-get install axel
axel -n 5 http://xxx.xxx.xxx.xxx/xxx.zip
或者
lftp -c "pget -n 5 http://xxx.xxx.xxx.xxx/xxx.zip“
//如何切換到 root 帳號
sudo -s
sudo -i
sudo su
cat 檔案名稱 //一屏查看檔案內容
cat /etc/vsftpd.conf |grep -v ^# //不顯示以#開頭的行
more 檔案名稱 //分頁查看檔案內容
less 檔案名稱 //可控分頁查看檔案內容
nl 檔案名稱 或者 cat -n 檔案名稱 //帶行號顯示檔案的內容
cut -c 5- a.py //去除檔案中的行號
cat file.txt |sort -u //刪除檔案中的重複行
touch filename //建立1個空檔案
rm -fr 檔案夾 //遞迴刪除嵌套目錄
file filename //查看檔案類型
stat filename //查看檔案的時間
diff file1 file2 //查看兩個檔案的區別
tar -zxvf xxx.tar.gz //解壓縮 xxx.tar.gz
tar -jxvf xxx.tar.bz2 //解壓縮 xxx.tar.bz2
tar -zcvf xxx.tar.gz aaa bbb //壓縮 aaa bbb 目錄為 xxx.tar.gz
tar -jcvf xxx.tar.bz2 aaa bbb //壓縮 aaa bbb 目錄為 xxx.tar.bz2
命令關機
sudo halt
sudo shutdown -h now //現在關機
定時關機
sudo shutdown -h 23:00 //晚上11點自動關機
sudo shutdown -h +60 //60分鐘後自動關機
命令重啟電腦
sudo reboot
sudo shutdown -r now
3、Git:
這一部分我不打算進行詳細的介紹,我覺得能滿足我基本的需求(clone、pull、push、merge)即可,至於一些高大上的操作各位還是參考園子的其他大牛吧。我這裡只列舉我常用到的幾個命令,方便我的溫故知新。
一、建立程式碼程式庫# 在目前的目錄建立一個Git程式碼程式庫$ git init# 建立一個目錄,將其初始化為Git程式碼程式庫$ git init [project-name]# 下載一個項目和它的整個代碼曆史$ git clone [project-path]二、配置Git的設定檔案為.gitconfig,它可以在使用者主目錄下(全域配置),也可以在項目目錄下(項目配置)。# 顯示當前的Git配置$ git config --list# 編輯Git設定檔$ git config -e [--global]# 設定提交代碼時的使用者資訊$ git config [--global] user.name "[name]"$ git config [--global] user.email "[email address]"三、增加/刪除檔案# 添加指定檔案到暫存區$ git add [file1] [file2] ...# 添加指定目錄到暫存區,包括子目錄$ git add [dir]# 添加目前的目錄的所有檔案到暫存區$ git add .# 刪除工作區檔案,並且將這次刪除放入暫存區$ git rm [file1] [file2] ...# 停止追蹤指定檔案,但該檔案會保留在工作區$ git rm --cached [file]# 改名檔案,並且將這個改名放入暫存區$ git mv [file-original] [file-renamed]四、代碼提交# 提交暫存區到倉庫區$ git commit -m [message]# 提交暫存區的指定檔案到倉庫區$ git commit [file1] [file2] ... -m [message]# 提交工作區自上次commit之後的變化,直接到倉庫區$ git commit -a# 提交時顯示所有diff資訊[Ctrl+X 然後Y退出]$ git commit -v# 使用一次新的commit,替代上一次提交# 如果代碼沒有任何新變化,則用來改寫上一次commit的提交資訊$ git commit --amend -m [message]# 重做上一次commit,並包括指定檔案的新變化$ git commit --amend ...五、分支# 列出所有本地分支$ git branch# 列出所有遠程分支$ git branch -r# 列出所有本地分支和遠程分支$ git branch -a# 建立一個分支,但依然停留在當前分支$ git branch [branch-name]# 建立一個分支,並切換到該分支$ git checkout -b [branch]# 建立一個分支,指向指定commit$ git branch [branch] [commit]# 建立一個分支,與指定的遠程分支建立追蹤關係$ git branch --track [branch] [remote-branch]# 切換到指定分支,並更新工作區$ git checkout [branch-name]# 建立追蹤關係,在現有分支與指定的遠程分支之間$ git branch --set-upstream [branch] [remote-branch]# 合并指定分支到當前分支$ git merge [branch]# 選擇一個commit,合并進當前分支$ git cherry-pick [commit]# 刪除分支$ git branch -d [branch-name]# 刪除遠程分支$ git push origin --delete $ git branch -dr六、標籤# 列出所有tag$ git tag# 建立一個tag在當前commit$ git tag [tag]# 建立一個tag在指定commit$ git tag [tag] [commit]# 查看tag資訊$ git show [tag]# 提交指定tag$ git push [remote] [tag]# 提交所有tag$ git push [remote] --tags# 建立一個分支,指向某個tag$ git checkout -b [branch] [tag]七、查看資訊# 顯示有變更的檔案$ git status# 顯示當前分支的版本曆史$ git log# 顯示commit曆史,以及每次commit發生變更的檔案$ git log --stat# 顯示某個檔案的版本曆史,包括檔案改名$ git log --follow [file]$ git whatchanged [file]# 顯示指定檔案相關的每一次diff$ git log -p [file]# 顯示指定檔案是什麼人在什麼時間修改過$ git blame [file]# 顯示暫存區和工作區的差異$ git diff# 顯示暫存區和上一個commit的差異$ git diff --cached []# 顯示工作區與當前分支最新commit之間的差異$ git diff HEAD# 顯示兩次提交之間的差異$ git diff [first-branch]...[second-branch]# 顯示某次提交的中繼資料和內容變化$ git show [commit]# 顯示某次提交發生變化的檔案$ git show --name-only [commit]# 顯示某次提交時,某個檔案的內容$ git show [commit]:[filename]# 顯示當前分支的最近幾次提交$ git reflog八、遠程同步# 下載遠程倉庫的所有變動$ git fetch [remote]# 顯示所有遠程倉庫$ git remote -v# 顯示某個遠程倉庫的資訊$ git remote show [remote]# 增加一個新的遠程倉庫,並命名$ git remote add [shortname] [url]# 取回遠程倉庫的變化,並與本地分支合并$ git pull [remote] [branch]# 上傳本地指定分支到遠程倉庫$ git push [remote] [branch]# 強行推送當前分支到遠程倉庫,即使有衝突$ git push [remote] --force# 推送所有分支到遠程倉庫$ git push [remote] --all九、撤銷# 恢複暫存區的指定檔案到工作區$ git checkout [file]# 恢複某個commit的指定檔案到工作區$ git checkout [commit] [file]# 恢複上一個commit的所有檔案到工作區$ git checkout .# 重設暫存區的指定檔案,與上一次commit保持一致,但工作區不變$ git reset [file]# 重設暫存區與工作區,與上一次commit保持一致$ git reset --hard# 重設當前分支的指標為指定commit,同時重設暫存區,但工作區不變$ git reset [commit]# 重設當前分支的HEAD為指定commit,同時重設暫存區和工作區,與指定commit一致$ git reset --hard [commit]# 重設當前HEAD為指定commit,但保持暫存區和工作區不變$ git reset --keep [commit]# 建立一個commit,用來撤銷指定commit# 後者的所有變化都將被前者抵消,並且應用到當前分支$ git revert [commit]十、其他# 產生一個可供發布的壓縮包$ git archive
4、Vim:
其實,Ubuntu系統已經內建了一個學習Vim的知道教程,你只需要在命令列中輸入vimtutor就可以。上面有非常詳細的教程,只要你肯耐心。這一部分我不打算進行詳細記錄,熟能生巧,經常練習,忘記的時候查看協助文檔多看看敲敲就差不多可以記住了。