Linux命令基础四

1.vi
命令行模式:
dd 删除当前行
dG删除当前光标以下的所有行
ndd删除当前光标及一下的n-1行

gg跳转到第一行的首字母
G跳转到最后一行的首字母
shift+$ 行尾
0 行首

vi清空文件所有内容
gg+dG 真正清空 0字节 但是文件内容加入很大,加载很慢

echo “” > install.log 伪清空

搜索:
尾行模式 /xxx 按n下一行

想要跳转到最后1行编辑
G shift+$ shift+a/i
在这里插入图片描述
2.权限
chown 改变用户 用户组
chmod 改变读写执
drwxr-xr-x 2 root root 4096 Jun 12 Download
第一位字母:d文件夹 -文件 1连接

r 读4
w 写2
x 执行 1 shell脚本
‘- 0 没有任何权限

rwx r-x r-x
第一组 rwx 7 代表文件和文件夹所属的用户的权限:读写执
第二组 r-x 5 代表文件和文件夹所属的用户组的权限:读写执
第三组 r-x 5 代表其他组的所有用户对这个文件和文件夹的权限:读写执

root 用户
root 用户组

chown 改变用户 用户组
chmod 改变读写执

rw-r–r-- 644

针对文件夹操作
chown -R jepson:jepson ruozedata
chmod -R 777 ruozedata

-R参数: chmod chown
777 代表所有人都有最大权限 读写执

3.软连接
命令为ln -s 源文件路径 软链接所在路径,这个命令在实际上使用频率不太高,但是会有以下两个场景会用到。 第一个场景,比如你的代码中使用的是/xxx/ruozedatav1.0路径,但是某天需要升级要使用的路径变成了/xxx/ruozedatav2.0。你不可能会去改代码中的路径,所以这个时候就需要软链接。以下方式创建软链接,就可以避免改代码里的路径。

[root@hadoop002 ~]# ln -s /root/ruozedatav1.0/ /root/rz
[root@hadoop002 ~]# ll
lrwxrwxrwx. 1 root root    13 Jun 24 00:24 rz -> ruozedatav1.0
[root@hadoop002 ~]# rm -rf rz
[root@hadoop002 ~]# ln -s /usr/local/ruozedatav2.0/ /root/rz
[root@hadoop002 ~]# ll
lrwxrwxrwx. 1 root root    25 Jun 24 00:30 rz -> /usr/local/ruozedatav2.0/
[root@hadoop002 ~]#

第二个场景就是,当你代码中使用的路径磁盘快满了,需要更换到另一个容量较大的磁盘路径时。当然要注意权限与之前一致。

[root@hadoop002 data02]# mv ~/data01/ruozedata ~/data02/ruozedata
[root@hadoop002 data02]# ln -s ~/data02/ruozedata ~/data01/ruozedata
[root@hadoop002 data01]# ll
lrwxrwxrwx. 1 root root 22 Jun 24 00:34 ruozedata -> /root/data02/ruozedata

4.系统命令
df -h 查看磁盘使用情况

[root@hadoop002 data01]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        47G  3.3G   41G   8% /
tmpfs          1000M   80K 1000M   1% /dev/shm
/dev/sda1      1008M   62M  896M   7% /boot
/dev/sr0        4.2G  4.2G     0 100% /media/CentOS_6.5_Final

free -m 查看内存使用情况

[root@hadoop002 data01]# free -m
             total       used       free     shared    buffers     cached
Mem:          1998        923       1075          0         78        327
-/+ buffers/cache:        517       1481
Swap:         2047          0       2047

top 实时查看整个服务器情况
面板第一行有个load average: 0.00, 0.00, 0.00,这个三个数代表1min,5min,15min服务器的负载。
一般来说三个数在10以下都是比较稳定的。

[root@hadoop002 data01]# top
top - 00:51:07 up  1:53,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 142 total,   1 running, 141 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.7%us,  0.7%sy,  0.0%ni, 98.2%id,  0.3%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   2046592k total,   945676k used,  1100916k free,    80012k buffers
Swap:  2097144k total,        0k used,  2097144k free,   335636k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2970 root      20   0 15024 1216  888 R  2.0  0.1   0:00.01 top
    1 root      20   0 19364 1540 1232 S  0.0  0.1   0:01.96 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.06 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.22 watchdog/0
    7 root      20   0     0    0    0 S  0.0  0.0   0:04.89 events/0
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.01 khelper
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.06 sync_supers
   14 root      20   0     0    0    0 S  0.0  0.0   0:00.04 bdi-default
   15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0
   16 root      20   0     0    0    0 S  0.0  0.0   0:01.98 kblockd/0
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid
   18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_hotplug
   20 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata_aux
   21 root      20   0     0    0    0 S  0.0  0.0   0:00.40 ata_sff/0
   22 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksuspend_usbd
   23 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khubd
   24 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kseriod
   25 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md/0
   26 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md_misc/0
   27 root      20   0     0    0    0 S  0.0  0.0   0:00.00 linkwatch
   28 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd
   29 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kswapd0
   30 root      25   5     0    0    0 S  0.0  0.0   0:00.00 ksmd
   31 root      39  19     0    0    0 S  0.0  0.0   0:04.65 khugepaged
   32 root      20   0     0    0    0 S  0.0  0.0   0:00.00 aio/0

5.解压压缩
tar.gz和zip压缩格式是我们常见的,下面简单介绍两种的格式的压缩和解压命令:

unzip xxx.zip --> 解压
zip xxx.zip test/* --> 压缩

[root@hadoop002 ruozedata]# ll
total 4
drwxr-xr-x. 2 root root 4096 Jun 24 01:01 test
[root@hadoop002 ruozedata]# zip -r test.zip test/*
  adding: test/1.log (stored 0%)
[root@hadoop002 ruozedata]# ll
total 8
drwxr-xr-x. 2 root root 4096 Jun 24 01:01 test
-rw-r--r--. 1 root root  170 Jun 24 01:01 test.zip
[root@hadoop002 ruozedata]# rm -rf test
[root@hadoop002 ruozedata]# ll
total 4
-rw-r--r--. 1 root root 170 Jun 24 01:01 test.zip
[root@hadoop002 ruozedata]# unzip test.zip
Archive:  test.zip
 extracting: test/1.log
[root@hadoop002 ruozedata]# ll
total 8
drwxr-xr-x. 2 root root 4096 Jun 24 01:03 test
-rw-r--r--. 1 root root  170 Jun 24 01:01 test.zip

tar -zxvf xxx.tag.gz --> 解压,加上-C可以指定解压到某个路径
tar -cxvf xxx.tag.gz test/* --> 压缩

[root@hadoop002 ruozedata]# ll
total 8
drwxr-xr-x. 2 root root 4096 Jun 24 01:03 test
-rw-r--r--. 1 root root  170 Jun 24 01:01 test.zip
[root@hadoop002 ruozedata]# tar -czvf test.tar.gz test/*
test/1.log
[root@hadoop002 ruozedata]# ll
total 12
drwxr-xr-x. 2 root root 4096 Jun 24 01:03 test
-rw-r--r--. 1 root root  115 Jun 24 01:04 test.tar.gz
-rw-r--r--. 1 root root  170 Jun 24 01:01 test.zip
[root@hadoop002 ruozedata]# rm -rf test
[root@hadoop002 ruozedata]# tar -xzvf test.tar.gz
test/1.log

6.wget
wget url下载连接地址
window --》 sz 上传

7.调度
Linux中crontab经常用来做定时任务,下面就是常用到命令:

[root@hadoop001 tmp]# crontab -l
* * * * * /tmp/date.sh >> /tmp/date.log 

分 小时 日 月 周

* 表示 每

1.每隔2分钟
*/2 * * * *
2/* 错误

2.每隔10s执行
1min 6次

[root@hadoop001 tmp]# cat date.sh 
#!/bin/bash

for((i=1;i<=6;i++))
do
	echo "wwww.ruozedata.com"
	date
	sleep 10s
done

exit

8.后台执行
网上有些说只需在命令后面加上&就是后台执行,但并不是,执行 nohup 命令 & 才是

[root@hadoop002 tmp]# ./date.sh &
[1] 3161
[root@hadoop002 tmp]# wwww.ruozedata.com
Mon Jun 24 01:17:57 HKT 2019        <--- 还是前台展示
[root@hadoop002 tmp]# nohup ./date.sh &
[2] 3177
[1]   Done                    ./date.sh
[root@hadoop002 tmp]# nohup: ignoring input and appending output to `nohup.out'   <-- 输出放在这里
[root@hadoop002 tmp]# cat nohup.out
wwww.ruozedata.com
Mon Jun 24 01:19:05 HKT 2019

因为可能不止一个脚本后台运行,所以不能将输出都放在nohup.out里面,我们更多是将输出重定向。

nohup ./date.sh >> /tmp/date.log 2>&1 & 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值