liunx的基础命令-02

liunx的基础命令

Linux(Ubuntu)基础命令021.echo 输出

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

2. 重定向

  • > 覆盖
  • >> 尾部追加
  • cat 查看
cat file # 一次查看所有的文件
cat file1  file2 # 一次查看两个命令

# >覆盖内容
doublechina@doublechina:~$ echo hello > 3.txt
#cat查看文本内容
doublechina@doublechina:~$ cat 3.txt
hello

# >尾部追加内容
doublechina@doublechina:~$ echo python java  >> 3.txt
doublechina@doublechina:~$ cat 3.txt
hello
python java

#cat 读取内容,写入其他文件
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查看多个文件
doublechina@doublechina:~$ cat 1.txt 3.txt

3.more | less

more filename # 分页查看 
- f向下翻页 
- b向上翻页 
- enter 逐行阅读 
- 翻到末页结束

less filename # 分页查看 
- f 向下 
- b 向上 
- 循环翻页,不会自动结束 
- 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 # 查看 二进制文件

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

whereis 可执行文件 # 二进制文件 、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 路径 参数

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

常用参数 
-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

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

-size # 按照大小 
find ./ -size +100k -size -10M # 在当前目录下找大于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 文本搜索(筛选内容)

grep 'content' filename 
- 常用参数 
- -v 显示不包含匹配文本的所有‘行’ (求反) 
- -n 显示匹配行及行号 
- -i 忽略大小写 
- 内容参数 
- ^hello 行首 搜索以hello开头的行 
- fi$ 行尾 索以wh结束的行

#显示带java字符的哪行
doublechina@doublechina:~$ grep "java" 3.txt
python java
# -n显示行号
doublechina@doublechina:~$ grep -n  "java" 3.txt
2:python java
#-i 不区分大小写
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
# $以什么结尾的
doublechina@doublechina:~$ grep -n  "fi$" 3.txt
9:fi

7. | 管道

一个命令的输出,可以通过管道符,做为另一个命令的输入

命令输出 | 命令处理

ls --help | less # 将输出,放入翻页模式中 
ls --help | grep -n 'txt' #将输出,放入‘筛选’模式中 
ls --help | grep -n 'txt' >> 3.txt #将输出,放入‘筛选’模式中,然后将重定向到3.txt

 ls --help 的输出内容,输出给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

#将输出内容,放入‘筛选’模式中,然后将重定向到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 创建链接文件

ln  file  hardlink # 硬链接
ln -s  file softlink  # 软链接

软链接: 相当于 window上的快捷方式 源文件删除则软链接失效

硬链接: 硬链接只能连接普通的文件 不能连接目录

注意 如果软链接文件和源文件不在同一个目录 源文件要使用绝对路径 不能使用相对路径

软链接:  相当于 `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

#硬链接,改了硬链接的内容,源文件内容也会改变
#删除源文件,硬链接还是存在
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 创建别名

  • 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


注意 这种定义别名的方式 只在当前登录有效 
如果要永久定义生效,可以通过修改~/.bashrc文件 
这个修改要下次登录才能生效,想要立即生效 可以输入source ~/.bashrc

10. vim 编辑器

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

模式之间切换

  • 当打开一个文件时处于命令模式
  • 在命令模式下,按 i 进入输入模式
/alias 

  • 在命令模式下,按 ‘/’ 定位搜索关键字

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

  • 在命令模式下,按shift+;,末行出现:冒号,则进入末行模式
#进入命令模式
doublechina@doublechina:~$ vim 1
#进入输入模式
输入一个i或者a 或者 o
#退出输入模式 ,按下ESC,进入命令模式

命令模式下,按`shift+; `,末行出现`:`冒号,则进入末行模式
进入末行模式,输入wq回车退出

进入与退出

vim filename 进入

当打开一个文件时处于命令模式

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

  • ! 强制 w 保存 q 退出
  • wq 保存退出
  • q! 不保存退出(强制退出)
  • wq! 强制保存退出
  • 搜索内容 :在命令模式下 / 内容。 例子:/kkkk

注意

  • 在vim下千万不要按Ctrl + s 。 不然就会卡死
  • 如果按了Ctrl + s,按Ctrl + q 可以退出

11.在Ubuntu14.04上安装Pip

步骤一: 在终端上使用以下命令,来保证你系统上所有的包都是最新的。 
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)
  • 发表于 2017-12-06 09:58
  • 阅读 ( 1890 )
  • 分类:linux

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
不写代码的码农
doublechina

IT

31 篇文章

作家榜 »

  1. 威猛的小站长 124 文章
  2. Jonny 65 文章
  3. 江南烟雨 36 文章
  4. - Nightmare 33 文章
  5. doublechina 31 文章
  6. HJ社区-肖峰 29 文章
  7. 伪摄影 22 文章
  8. Alan 14 文章