liunx的基础命令-02
来源:互联网 发布:淘宝透明下拉栏 编辑:程序博客网 时间:2024/04/30 09:58
Linux(Ubuntu)基础命令02
1.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.txthello# >>尾部追加内容doublechina@doublechina:~$ echo python java >> 3.txtdoublechina@doublechina:~$ cat 3.txthellopython java#cat 读取内容,写入其他文件doublechina@doublechina:~$ cat .bash_logout >> 3.txtdoublechina@doublechina:~$ ls3.txt aa bb cc ddcc eedoublechina@doublechina:~$ cat 3.txtdoublechina@doublechina:~$ echo hello >>1.txtdoublechina@doublechina:~$ ls1.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.txtif [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -qfihellopython 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....fihellopython java# ~/.bash_logout: executed by bash(1) when login shell exits.# when leaving the console clear the screen to increase privacy1.txt# f,b翻页,q退出
4. which / whereis
查找命令
which command
# 查看 二进制文件
doublechina@doublechina:~$ which ls/bin/ls
whereis 可执行文件 # 二进制文件 、man手册
doublechina@doublechina:~$ whereis lsls: /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:~$ ls1.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.txtpython java# -n显示行号doublechina@doublechina:~$ grep -n "java" 3.txt2:python java#-i 不区分大小写doublechina@doublechina:~$ grep -i "Java" 3.txtpython java#-v取反doublechina@doublechina:~$ grep -v "java" 3.txthello# ~/.bash_logout: executed by bash(1) when login shell exits.# when leaving the console clear the screen to increase privacyif [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -qfi# ^脱字符,以什么开头doublechina@doublechina:~$ grep -n "^hello" 3.txt1:hello# $以什么结尾的doublechina@doublechina:~$ grep -n "fi$" 3.txt9: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 | lessdoublechina@doublechina:~$ ls -l | grep -n "txt"2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec 5 16:27 1.txt3:-rw-rw-r-- 1 doublechina doublechina 238 Dec 5 13:13 3.txt#将输出内容,放入‘筛选’模式中,然后将重定向到3.txtdoublechina@doublechina:~$ ls -l | grep -n "txt" >> 3.txtdoublechina@doublechina:~$ ls1.txt 3.txt eedoublechina@doublechina:~$ cat 3.txthellopython java# ~/.bash_logout: executed by bash(1) when login shell exits.# when leaving the console clear the screen to increase privacyif [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -qfi2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec 5 16:27 1.txt3:-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.txtdoublechina@doublechina:~$ ls1.txt 3.txt ee softlink.txt soft.txtdoublechina@doublechina:~$ echo "cccc" >> soft.txtdoublechina@doublechina:~$ cat 3.txthellopython java# ~/.bash_logout: executed by bash(1) when login shell exits.# when leaving the console clear the screen to increase privacyif [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -qfi2:-rw-rw-r-- 1 doublechina doublechina 4052 Dec 5 16:27 1.txt3:-rw-rw-r-- 1 doublechina doublechina 238 Dec 5 13:13 3.txtccccdoublec#硬链接,改了硬链接的内容,源文件内容也会改变#删除源文件,硬链接还是存在doublechina@doublechina:~$ touch 2.txdoublechina@doublechina:~$ ls1.txt 2.tx 3.txt ee softlink.txtdoublechina@doublechina:~$ ln 2.tx hard.txtdoublechina@doublechina:~$ ls1.txt 2.tx 3.txt ee hard.txt softlink.txtdoublechina@doublechina:~$ echo aaa >> hard.txtdoublechina@doublechina:~$ cat hard.txtaaadoublechina@doublechina:~$ cat 2.txaaadoublechina@doublechina:~$ rm 2.txdoublechina@doublechina:~$ ls1.txt 3.txt ee hard.txt softlink.txtdoublechina@doublechina:~$ cat hard.txtaaa
9. alias
创建别名
alias
# 查看所有别名alias c3='cat 3.txt'
unalias
# 删除别名
doublechina@doublechina:~$ alias c1="cat 1.txt"doublechina@doublechina:~$ c1hellohello....doublechina@doublechina:~$ unalias c1doublechina@doublechina:~$ c1c1: 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 InReleaseHit:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InReleaseHit:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InReleaseGet: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 upgradeReading package lists... DoneBuilding dependency tree Reading state information... DoneCalculating 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-pipReading package lists... DoneBuilding dependency tree Reading state information... DoneThe 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 -Vpip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
- liunx的基础命令-02
- liunx的基础命令-03
- Liunx基础命令,你注意不到的
- Liunx基础命令
- liunx命令基础
- Liunx基础命令
- Liunx基础命令(2)
- liunx初学一些基础的命令使用技巧
- Liunx最基础的几个命令,值得学习
- liunx的管道命令
- 常用的liunx命令
- liunx的awk命令
- LIUNX 基础命令 (目录处理命令)
- liunx基础命令 一、系统管理与设置
- liunx下的解压缩命令
- 我的liunx命令集合
- 查看liunx版本的命令
- 第十一篇 最基础的dos命令和liunx、oracle、dreamweaver的安装
- delphi messagebox中string转ansichar 问题
- Android蓝牙开发【三】蓝牙Hid开发
- python 用turtle库绘制时钟
- MySQL中myisam和innodb的主键索引有什么区别?
- mysql导入导出
- liunx的基础命令-02
- 微信注册崩溃?appid签名无法注册or如何查看签名是否一致?如何注册appid?jks和keystore的区别?
- linux命令-date显示或设置时间
- bzoj1058 [ZJOI2007]报表统计
- 高铁、地铁这些轨道列车的动力来源是什么?
- HTML一些标签知识
- 漫无目的地工作,只会让我们慢慢走向平庸
- 动态改变class内的属性,使得div跟随指定目标移动
- Android后台定时提醒功能实现