Linux常用命令总结(二):常用命令

1、pwd:可以打印出当前所在的绝对路径
 
2、ls:列出目录结构,全称list

(1)ls -l /  
   - l代表以列表(详细信息)形式查看, 全屏long
(2)ls -lh /
   - h代表human,以kb的方式展示文件大小
(3)ls -ld /dev
   - d代表只查看指定的目录信息

3、mkdir:创建目录

mkdir -p dir/dir2
   - p选项可以创建多级目录

4、touch:创建文件

touch somefile.txt

5、rmdir:删除空文件夹(注意,只能删除空目录)

rmdir test_dir/

6、rm:删除目录或文件

(1)rm -r dir/
      - r代表删除的是目录,如果删除的是目录,必须要加
(2)rm -rf package/
      - f代表确认删除

7、cp:拷贝目录或文件

cp /etc/passwd .
   - .代表的当前目录

8、mv:剪切

mv passwd package/

9、查看文件命令

 (1)cat /etc/passwd
 (2)more /etc/services 查看多行文件,支持翻页,逐行查看,但不支持向上翻页回看
 (3)less /etc/services 查看多行文件,支持翻页,逐行查看,向上或向下翻页查看
 (4)head -n /etc/services 查看文件头n行,默认是10
 (5)tail -n /etc/services 查看文件后n行,默认是10
 (6)tail -f 加-f选项可以查看滚动的日志文件

10、find:查找特定的文件

基本语法

find path [options] exec

(1)如果不指定目录,则在当前目录或者子目录下进行搜索

[root@hadoop datas]# pwd
/opt/datas
[root@hadoop datas]# ls sh/
case.sh  for2.sh  if2-else.sh  link          parameter2.sh  parameter4.sh  while.sh
for1.sh  if1.sh   if3-elif.sh  linkwhile.sh  parameter3.sh  parameter.sh
[root@hadoop datas]# find -name "if2-else.sh"
./sh/if2-else.sh

(2)指定目录

[root@hadoop datas]# find / -name "if2-else.sh"
/opt/datas/sh/if2-else.sh

(3)查找指定文件打头的

[root@hadoop datas]# find / -name "if2-*"      
/opt/datas/sh/if2-else.sh

备注:忽略大小写,添加i

[root@hadoop datas]# find / -iname "if2-*"
/opt/datas/sh/if2-else.sh

11、grep:查找文件里符合条件的字符串

基本语法:

grep [ options ] pattern filefullpath

实例:
(1)检测当前目录下 target开头的文件

[root@hadoop test]# find ./ | grep target
./target2.sh
./target1.log

(2)检索包含固定短语hello的文件

格式:grep pattern filefullpath

[root@hadoop test]# cat target1.log 
hello world
hahahaha
[root@hadoop test]# grep 'hello' target*
target1.log:hello world

(3)管道筛选需要的内容,使用-o参数

[root@hadoop test]# grep 'hello' target* 
target1.log:hello world engine[234edfwert324234] engine[2asdfwergadf324]
[root@hadoop test]# grep 'hello' target* | grep -o 'engine\[[0-9a-z]*\]'
engine[234edfwert324234]
engine[2asdfwergadf324]

(4)剔除指定相关信息,通过-v参数

[root@hadoop test]# ps -ef | grep tomcat
root      29589  29165  0 19:47 pts/2    00:00:00 grep tomcat
[root@hadoop test]# ps -ef | grep tomcat | grep -v "grep"


 

 

 

 

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值