liunx的基礎(chǔ)命令-02

Linux(Ubuntu)基礎(chǔ)命令02

1.echo 輸出

root@doublechina:~# echo "hello world"
hello world

2. 重定向

  • > 覆蓋
  • >> 尾部追加
  • cat 查看
cat file # 一次查看所有的文件
cat file1  file2 # 一次查看兩個(gè)命令
# >覆蓋內(nèi)容
doublechina@doublechina:~$ echo hello > 3.txt
#cat查看文本內(nèi)容
doublechina@doublechina:~$ cat 3.txt
hello

# >>尾部追加內(nèi)容
doublechina@doublechina:~$ echo python java  >> 3.txt
doublechina@doublechina:~$ cat 3.txt
hello
python java

#cat 讀取內(nèi)容,寫入其他文件
doublechina@doublechina:~$ cat  .bash_logout  >> 3.txt
doublechina@doublechina:~$ ls
3.txt  aa  bb  cc  ddcc  ee
doublechina@doublechina:~$ cat 3.txt

doublechina@doublechina:~$ echo hello >>1.txt
doublechina@doublechina:~$ ls
1.txt  3.txt  aa  bb  cc  ddcc  ee
#cat查看多個(gè)文件
doublechina@doublechina:~$ cat 1.txt 3.txt

3.more | less

more filename # 分頁查看

  • f向下翻頁
  • b向上翻頁
  • enter 逐行閱讀
  • 翻到末頁結(jié)束

less filename # 分頁查看

  • f 向下
  • b 向上
  • 循環(huán)翻頁,不會(huì)自動(dòng)結(jié)束
  • q 退出
#more分頁查看
doublechina@doublechina:~$ more 1.txt
if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
hello
python java
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

--More--(9%)  
#按回車鍵逐行閱讀 

#less 查看分頁
doublechina@doublechina:~$ less 1.txt
....
fi
hello
python java
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
1.txt
# f,b翻頁,q退出

4. which / whereis 查找命令

which command # 查看 二進(jìn)制文件

doublechina@doublechina:~$ which ls
/bin/ls

whereis 可執(zhí)行文件 # 二進(jìn)制文件 、man手冊

doublechina@doublechina:~$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz

幫助文檔:
1.man手冊 ,幫助文檔 man ls
2.ls --help

doublechina@doublechina:~$ man ls
#翻頁查看

doublechina@doublechina:~$ ls --help
#顯示所有的

5.find 查找文件

find 路徑 參數(shù)

doublechina@doublechina:~$ ls
1.txt  3.txt  ee
#find查出所有的文件,包含隱藏的文件
doublechina@doublechina:~$ find
.
./.viminfo
./.bash_history
./3.txt
./.profile
./.cache
./.cache/motd.legal-displayed
./.bash_logout
./1.txt
./.bashrc
./ee
./ee/ff
./.sudo_as_admin_successful

常用參數(shù)
-name # 按照名字

doublechina@doublechina:~$ find /home/doublechina -name 3.txt
/home/doublechina/3.txt
#用*必須帶上引號,要不查找不到
doublechina@doublechina:~$ find /home/doublechina -name '*.txt'
/home/doublechina/3.txt
/home/doublechina/1.txt

#全局搜索某個(gè)文件
doublechina@doublechina:~$ sudo  find / -name  "3.txt"
[sudo] password for doublechina: 
/home/doublechina/3.txt

-size # 按照大小
find ./ -size +100k -size -10M # 在當(dāng)前目錄下找大于100k 小于 10的文件

#找出家目錄中大于 3k的文件
doublechina@doublechina:~$ find ~ -size +3k
/home/doublechina
/home/doublechina/.cache
/home/doublechina/1.txt
/home/doublechina/.bashrc
/home/doublechina/ee
/home/doublechina/ee/ff

#找出家目錄中大于 3k小于5k的文件
doublechina@doublechina:~$ find ~ -size +3k -size  -5k
/home/doublechina
/home/doublechina/.cache
/home/doublechina/1.txt
/home/doublechina/.bashrc
/home/doublechina/ee
/home/doublechina/ee/ff

6. grep 文本搜索(篩選內(nèi)容)

grep 'content' filename

  • 常用參數(shù)
  • -v 顯示不包含匹配文本的所有‘行’ (求反)
  • -n 顯示匹配行及行號
  • -i 忽略大小寫
  • 內(nèi)容參數(shù)
  • ^hello 行首 搜索以hello開頭的行
  • fi$ 行尾 索以wh結(jié)束的行
#顯示帶java字符的哪行
doublechina@doublechina:~$ grep "java" 3.txt
python java
# -n顯示行號
doublechina@doublechina:~$ grep -n  "java" 3.txt
2:python java
#-i 不區(qū)分大小寫
doublechina@doublechina:~$ grep -i  "Java" 3.txt
python java
#-v取反
doublechina@doublechina:~$ grep -v  "java" 3.txt
hello
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
# ^脫字符,以什么開頭
doublechina@doublechina:~$ grep -n  "^hello" 3.txt
1:hello
# $以什么結(jié)尾的
doublechina@doublechina:~$ grep -n  "fi$" 3.txt
9:fi

7. | 管道

一個(gè)命令的輸出,可以通過管道符,做為另一個(gè)命令的輸入

命令輸出 | 命令處理

ls --help | less # 將輸出,放入翻頁模式中
ls --help | grep -n 'txt' #將輸出,放入‘篩選’模式中
ls --help | grep -n 'txt' >> 3.txt #將輸出,放入‘篩選’模式中,然后將重定向到3.txt

 ls --help 的輸出內(nèi)容,輸出給less使用
doublechina@doublechina:~$ ls --help | less

doublechina@doublechina:~$ ls -l | grep -n  "txt"
2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec  5 16:27 1.txt
3:-rw-rw-r-- 1 doublechina doublechina  238 Dec  5 13:13 3.txt

#將輸出內(nèi)容,放入‘篩選’模式中,然后將重定向到3.txt
doublechina@doublechina:~$ ls -l | grep -n  "txt" >> 3.txt
doublechina@doublechina:~$ ls
1.txt  3.txt  ee
doublechina@doublechina:~$ cat 3.txt
hello
python java
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec  5 16:27 1.txt
3:-rw-rw-r-- 1 doublechina doublechina  238 Dec  5 13:13 3.txt

8. ln 創(chuàng)建鏈接文件

ln  file  hardlink # 硬鏈接
ln -s  file softlink  # 軟鏈接

軟鏈接: 相當(dāng)于 window上的快捷方式 源文件刪除則軟鏈接失效

硬鏈接: 硬鏈接只能連接普通的文件 不能連接目錄

注意 如果軟鏈接文件和源文件不在同一個(gè)目錄 源文件要使用絕對路徑 不能使用相對路徑

軟鏈接:  相當(dāng)于 `window`上的快捷方式,源文件刪除則軟鏈接失效

doublechina@doublechina:~$ ln -s 3.txt soft.txt
doublechina@doublechina:~$ ls
1.txt  3.txt  ee  softlink.txt  soft.txt
doublechina@doublechina:~$ echo "cccc" >> soft.txt
doublechina@doublechina:~$ cat 3.txt
hello
python java
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec  5 16:27 1.txt
3:-rw-rw-r-- 1 doublechina doublechina  238 Dec  5 13:13 3.txt
cccc
doublec

#硬鏈接,改了硬鏈接的內(nèi)容,源文件內(nèi)容也會(huì)改變
#刪除源文件,硬鏈接還是存在
doublechina@doublechina:~$ touch 2.tx
doublechina@doublechina:~$ ls
1.txt  2.tx  3.txt  ee  softlink.txt
doublechina@doublechina:~$ ln 2.tx hard.txt
doublechina@doublechina:~$ ls
1.txt  2.tx  3.txt  ee  hard.txt  softlink.txt
doublechina@doublechina:~$ echo aaa >> hard.txt
doublechina@doublechina:~$ cat hard.txt
aaa
doublechina@doublechina:~$ cat  2.tx
aaa
doublechina@doublechina:~$ rm 2.tx
doublechina@doublechina:~$ ls
1.txt  3.txt  ee  hard.txt  softlink.txt
doublechina@doublechina:~$ cat hard.txt
aaa


9. alias 創(chuàng)建別名

  • alias # 查看所有別名 alias c3='cat 3.txt'
  • unalias # 刪除別名
doublechina@doublechina:~$ alias c1="cat 1.txt"
doublechina@doublechina:~$ c1
hello
hello
....
doublechina@doublechina:~$ unalias c1
doublechina@doublechina:~$ c1
c1: command not found


注意 這種定義別名的方式 只在當(dāng)前登錄有效
如果要永久定義生效,可以通過修改~/.bashrc文件
這個(gè)修改要下次登錄才能生效,想要立即生效 可以輸入source ~/.bashrc

10. vim 編輯器

工作模式:命令模式、輸入模式、末行模式

模式之間切換

  • 當(dāng)打開一個(gè)文件時(shí)處于命令模式
  • 在命令模式下,按 i 進(jìn)入輸入模式
/alias 
  • 在命令模式下,按 '/' 定位搜索關(guān)鍵字

  • 在輸入模式,按ESC回到命令模式。

  • 在命令模式下,按shift+;,末行出現(xiàn):冒號,則進(jìn)入末行模式

#進(jìn)入命令模式
doublechina@doublechina:~$ vim 1
#進(jìn)入輸入模式
輸入一個(gè)i或者a 或者 o
#退出輸入模式 ,按下ESC,進(jìn)入命令模式

命令模式下,按`shift+; `,末行出現(xiàn)`:`冒號,則進(jìn)入末行模式
進(jìn)入末行模式,輸入wq回車退出

進(jìn)入與退出

vim filename 進(jìn)入

當(dāng)打開一個(gè)文件時(shí)處于命令模式

在末行模式下輸入q退出文件

  • ! 強(qiáng)制 w 保存 q 退出
  • wq 保存退出
  • q! 不保存退出(強(qiáng)制退出)
  • wq! 強(qiáng)制保存退出
  • 搜索內(nèi)容 :在命令模式下 / 內(nèi)容。 例子:/kkkk

注意

  • 在vim下千萬不要按Ctrl + s 。 不然就會(huì)卡死
  • 如果按了Ctrl + s,按Ctrl + q 可以退出

11.在Ubuntu14.04上安裝Pip

步驟一: 在終端上使用以下命令,來保證你系統(tǒng)上所有的包都是最新的。
sudo apt-get update

doublechina@doublechina:~$ sudo apt-get update
[sudo] password for doublechina: 
Hit:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Fetched 102 kB in 3s (26.3 kB/s)  
Reading package lists... Done

sudo apt-get upgrade

doublechina@doublechina:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Calculating upgrade... Done
....
Do you want to continue? [Y/n] y  #填寫y就好了
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main i386 dpkg i386 1.18.4ubuntu1.3 [2,112 kB]
.....
Processing triggers for resolvconf (1.78ubuntu5) ...
Processing triggers for ca-certificates (20170717~16.04.1) ...
Updating certificates in /etc/ssl/certs...
17 added, 42 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

步驟二: 安裝Pip

安裝python3-pip和你所需要的包:

sudo apt-get install python3-pip

doublechina@doublechina:~$ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
....
Do you want to continue? [Y/n] y
....
Setting up python3-dev (3.5.1-3) ...
Setting up python3-pip (8.1.1-2ubuntu0.4) ...
Setting up python3-setuptools (20.7.0-1) ...
Setting up python3-wheel (0.29.0-1) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
安裝完成

檢查你所安裝Pip的版本:
pip3 -V

doublechina@doublechina:~$ pip3 -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容