Linux的其他操作(二)

目录

1、find 查找命令

 2、which & whereis 表示某个命令是否存在,作用是一样的

3、grep (重点) 查找的意思(后续详细讲解)

 4、Linux中的磁盘,内存等命令

5、关于时间的命令

6、开关机的命令

7、其他常见的操作


1、find 查找命令

find 后面有三个参数
        -name  根据名字查找
            find -name  'init'
        -size  根据文件的大小查找
        -type  根据文件的类型查找(文件/文件夹/链接)

[root@bigdata01 ~]# find /etc -name 'init'    --查找名字是init的文件
/etc/sysconfig/init
/etc/selinux/targeted/active/modules/100/init
[root@bigdata01 ~]# find /etc -name 'init???'  --查找名字是7个字符,前4个字符是init的文件
/etc/inittab
[root@bigdata01 ~]# find /etc -name 'init*'    --查找名字是init开头的文件
/etc/init.d
/etc/rc.d/init.d
/etc/inittab
/etc/sysconfig/init
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/selinux/targeted/active/modules/100/init
/etc/selinux/targeted/contexts/initrc_context
[root@bigdata01 ~]

200块,200block , 这里1kb =2block ,此处的200block=100kb

+表示大于这个数,-表示小于这个数。

[root@bigdata01 ~]# find /etc -size +200
/etc/udev/hwdb.bin
/etc/services
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/ssh/moduli
/etc/selinux/targeted/active/file_contexts
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/contexts/files/file_contexts
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31

可以通过du -sh `find /etc -size +200` 查看文件大小

[root@bigdata01 ~]# du -sh `find /etc -size +200`
7.5M    /etc/udev/hwdb.bin
656K    /etc/services
160K    /etc/pki/ca-trust/extracted/java/cacerts
260K    /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
216K    /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
176K    /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
572K    /etc/ssh/moduli
376K    /etc/selinux/targeted/active/file_contexts
3.6M    /etc/selinux/targeted/active/policy.kern
376K    /etc/selinux/targeted/contexts/files/file_contexts
1.3M    /etc/selinux/targeted/contexts/files/file_contexts.bin
3.6M    /etc/selinux/targeted/policy/policy.31

查看一个文件夹下的所以的某种类型的文件

[root@bigdata01 ~]# find /etc -type l
/etc/mtab
/etc/alternatives/libnssckbi.so.x86_64
/etc/alternatives/ld
/etc/alternatives/mta
/etc/alternatives/mta-mailq
/etc/alternatives/mta-newaliases
/etc/alternatives/mta-pam

        - 表示一个普通的文件        

        d 表示文件夹

        f 表示二进制文件

        c 表示字符文件

        l 表示链接文件 

 2、which & whereis 表示某个命令是否存在,作用是一样的

 通过whic和whereis可以查找linux中是否有某个命令。

[root@bigdata01 home]# whereis zip
zip: /usr/bin/zip /usr/share/man/man1/zip.1.gz
[root@bigdata01 home]# whereis ifconfig
ifconfig: /usr/sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
[root@bigdata01 home]# whereis cd
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz
[root@bigdata01 home]# which cd
/usr/bin/cd

3、grep (重点) 查找的意思(后续详细讲解)

linux shell 编程三剑客之一: grep 除此以外 sed awk

查找 类似于之前的 /查找的内容
grep -n ftp /etc/services
grep -n  表示查找的内容显示行号
grep -n 要查找的字符串  要在哪个文件中查找
一般不这么用。 

| 代表管道符,将ls查找到的内容传输给后面的grep。

ps -ef 的作用是查找linux里的所有线程,可以通过查看线程中是否含有某个名字判断某个任务是否运行。.

[root@bigdata03 home]# ls
abc  a.soft  a.txt  a.zip  b  b.txt  c.txt  u.hard
[root@bigdata03 home]# ls | grep a.txt
a.txt
[root@bigdata03 home]# ls | grep a
abc
a.soft
a.txt
a.zip
u.hard
[root@bigdata03 home]# ps -ef | grep mysql  --查找服务器中mysql是否启动
root      20642   2345  0 20:19 pts/0    00:00:00 grep --color=auto mysql

grep -v 取反的意思

grep -v -n ftp /etc/services

搜索哪些行不含有ftp 字样,就查找出来。

 4、Linux中的磁盘,内存等命令

du   -- 查看某个文件夹大小
df   --查看各个分区的使用情况
free --查看内存的使用情况

[root@bigdata01 home]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   36G   11G   25G   31% /
devtmpfs                 3.8G     0  3.8G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G   12M  3.8G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M   14% /boot
tmpfs                    781M     0  781M    0% /run/user/0
[root@bigdata01 home]# du -h /home
19M     /home/hivedata
8.0K    /home/out/user
12K     /home/out
19M     /home
[root@bigdata01 home]# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        4.9G        1.9G         11M        888M        2.4G
Swap:          3.9G          0B        3.9G

5、关于时间的命令

date   查看当前时间
date -s "2024-09-10 10:10:10"  手动设置时间
通过互联网同步时间
需要一个命令,这个命令是ntpdate
先按照这个服务
yum install -y ntpdate
哪个网址能记住,选哪个:
ntpdate time1.aliyun.com
ntpdate cn.pool.ntp.org
time1.aliyun.com cn.pool.ntp.org 它是一个互联网的网址,是时间服务器。
将时间写入硬件:
hwclock -w

还可以使用:
systemctl restart chronyd   这个命令需要等待一会儿时间才会同步

[root@bigdata01 home]# date
2024年 09月 10日 星期二 20:30:19 CST
[root@bigdata01 home]# date -s "2024-09-10 10:10:10"
2024年 09月 10日 星期二 10:10:10 CST
[root@bigdata01 home]# ntpdate time1.aliyun.com
10 Sep 20:31:42 ntpdate[85922]: step time server 203.107.6.88 offset 37244.434157 sec

6、开关机的命令

重启 reboot
也可以使用 init 6
关机   init 0  或者直接shutdown

下面这些了解一下:
shutdown -h now    立即关机 = init 0
shutdown -h 18:00  定时关机

7、其他常见的操作

ctrl + c 终止当前的进程
ctrl + l  清屏
clear 清屏    

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值