优快云仅用于增加百度收录权重,排版未优化,日常不维护。请访问:www.hceng.cn 查看、评论。
本博文对应地址: https://hceng.cn/2017/03/12/Linux常用命令/#more
本文主要汇总一些常用且不太熟练的Liunx命令,不定期更新。
1. tar
作用:打包(拆包)/压缩(解压)文件;
语法:tar [主选项+辅选项] 文件或目录
主选项:
- c :打包文件;
- x :拆包文件;
- t :列出包/压缩文件里有哪些文件。
辅选项: - z :具有 gzip 属性;格式为xx.tar.gz或xx. tgz;
- j :具有 bzip2 属性;格式为xx.tar.bz2;
- v :显示压缩文件过程;
- f :在其后必须是文件名;
- - -exclude xxx:打包除xxx文件之外的文件;
示例:
{% codeblock lang:shell %}
$ tar cf test.tar test #打包test文件/文件夹为test.tar;
$ tar xf test.tar #拆包test.tar;
$ tar czf test.tar.gz test #压缩test文件/文件夹为test.tar.gz;
$ tar xzf test.tar.gz #解压test.tar.gz;
$ tar cjf test.bzip2 test #压缩test文件/文件夹为test.bzip2;
$ tar xjf test.bzip2 #解压test.bzip2;
$ tar cf test.tar --exclude test.txt test #打包test文件夹里除test.txt之外的为test.tar
{% endcodeblock %}
2. grep
作用:查找字符串;
语法:grep [选项] ‘搜寻字符串’ 文件名
选项:
- -c :计算找到 ‘搜寻字符串’ 的次数;
- -i :忽略大小写;
- -n :顺便输出行号;
- -v :反向选择,即显示出没有 ‘搜寻字符串’ 内容的那一行;
示例:
{% codeblock lang:shell %}
$ grep -n ‘test’ test.txt #搜索test.txt中含test的行,且显示对应行号;
{% endcodeblock %}
3. find
作用:选项较多,这里暂仅使用name选项查找文件;
语法:find 路径 -name "文件名"
示例:
{% codeblock lang:shell %}
$ find -name “test” #在当前文件下找test文件;
{% endcodeblock %}
4. ifconfig
作用:网卡配置;
语法:ifconfig [网络设备] [参数]"
示例:
{% codeblock lang:shell %}
#设置网卡1的地址 192.168.1.44,掩码为255.255.255.0(即默认);
$ ifconfig eth0 192.168.1.44 netmask 255.255.255.0
#捆绑网卡1的第二个地址为 192.168.1.x
$ ifconfig eth0:x 192.168.1.x
#打开网卡1
$ ifconfig eth0 up
#关闭网卡1
$ ifconfig eth0 down
{% endcodeblock %}
5. mount
作用:目前只用来挂载NFS;
语法:mount -t nfs 服务器ip:挂载目录 挂载到本地哪里"
示例:
{% codeblock lang:shell %}
#把主机(192.168.1.44)的/work/hceng/nfs_rootfs挂载到本地/tmp目录下;
$ mount -t nfs 192.168.1.44:/work/hceng/nfs_rootfs /tmp
{% endcodeblock %}
6. 查看Linux版本信息
示例:
{% codeblock lang:shell %}
$ uname -a #显示电脑以及操作系统的相关信;
$ cat /proc/version #正在运行的内核版本;
$ cat /etc/issue #显示的是发行版本信息;
$ lsb_release -a #列出所有版本信息;
{% endcodeblock %}
7. 关闭防火墙
示例:
{% codeblock lang:shell %}
$ ufw disable #关闭ubuntu的防火墙 ;
$ ufw enable #开启防火墙;
{% endcodeblock %}
7. source
作用:免重启更新环境变量;
示例:
{% codeblock lang:shell %}
$ source /etc/environment
{% endcodeblock %}
8. vim
作用:vim里代码自动格式化;
示例:
{% codeblock lang:shell %}
gg
vG
{% endcodeblock %}