Linux中常用的命令有哪些?具体的用法及如何具体的使用?本文将给大家抛个砖
1. 压缩命令:tar
创建一个压缩文件:.
1 |
$ tar cvf archive_name.tar dirname/ |
解压一个tar文件.
1 |
$ tar xvf archive_name.tar |
查看一个tar文件.
1 |
$ tar tvf archive_name.tar |
2. 过滤命令:grep
在某个文件中查寻指定字符串
1 |
$ grep -i "the" demo_file |
打印出匹配的行以及其后的3行
1 |
$ grep -A 3 -i "example" demo_text |
递归的查找本目录下所有的内容中包含指定内容的文件
1 |
$ grep -r "ramesh" * |
3. 查找命令:find
通过文件名查找(忽略大小写)
1 |
# find -iname "MyCProgram.c" |
对查找到的文件执行指定命令
1 |
$ find -iname "MyCProgram.c" -exec md5sum {} \; |
查找所有的空文件
1 |
# find ~ -empty |
4. 远程登陆:ssh
登陆某远程主机:
1 |
ssh -l jsmith remotehost.example.com |
Debug 模式登陆某主机
1 |
ssh -v -l jsmith remotehost.example.com |
显示ssh的版本号
1 2 |
$ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003 |
5.文件处理:sed
When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.
当你拷贝一个DOS操作系统的文件到linux下的时候,我们需要替换掉 \r\n ,下面的例子是将DOS 文件转换程 linux文件
1 |
$sed 's/.$//' filename |
按照反序列打印文件内容
1 |
$ sed -n '1!G;h;$p' thegeekstuff.txt |
给所有非空行添加行号
1 |
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /' |
6. 文件处理:awk
删除重复行:
1 |
$ awk '!($0 in array) { array[$0]; print }' temp |
打印所有用户中uid和gid相同的行
1 |
$awk -F ':' '$3==$4' passwd.txt |
打印指定列:
1 |
$ awk '{print $2,$5;}' employee.txt |
7. 编辑器:vim
打开文件并定位到143行
1 |
$ vim +143 filename.txt |
定位到第一次匹配搜索的地方:
1 |
$ vim +/search-term filename.txt |
只读模式打开某文件
1 |
$ vim -R /etc/passwd |
8. 文件对比:diff
Ignore white space while comparing.
对比两个文件(忽略空格)
1 2 3 4 5 |
# diff -w name_list.txt name_list_new.txt 2c2,3 < John Doe --- > John M Doe > Jason Bourne |
9. 排序:sort
按照升序排列:
1 |
$ sort names.txt |
按照降序排列:
1 |
$ sort -r names.txt |
根据passwd文件的第三列进行排序:
1 |
$ sort -t: -k 3n /etc/passwd | more |
10. 环境变量的声明:export
查看已经声明的变量里包含ORACLE的变量:
1 2 3 4 5 |
$ export | grep ORACLE declare -x ORACLE_BASE="/u01/app/oracle" declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0" declare -x ORACLE_SID="med" declare -x ORACLE_TERM="xterm" |
声明一个环境变量
1 |
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0 |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021