温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

linux基础之history、ls、cat、tac学习笔记

发布时间:2020-02-23 02:55:02 来源:网络 阅读:280 作者:李超超超超 栏目:系统运维
        5、history命令
        作用:查看和使用历史命令(最多纪录1000条)
        保存位置:~/.bash_history
        1、在启动终端的时候,会自动从~/.bash_history中读取历史命令,加载到内存中
        2、在终端中执行命令,命令的历史记录是保存在内存中
        3、在关闭终端的时候,会将内存中的历史命令自动保存到~/bash_history中
        history的快捷操作
        !num:执行历史命令中编号为num的历史命令
        !string:在历史命令中找以指定字符串为开头的命令执行一次,从下向上进行查找
        !!:执行的是上一个命令
        !-num:执行历史命令中倒数第num条命令
        如果保留了历史命令,******了我们的系统,通过历史命令,知道服务器进行了哪些操作。有些时候需要对历史命令进行控制。
        -c:清空历史命令 (内存中的)
        在启动终端的时候,会从~/.bash_history读取历史命令
        [root@localhost ~]# history -c
        [root@localhost ~]# 
        [root@localhost ~]# history
        1  history
        -a:手动将内存中的历史命令保存到文件中
        -r:重新从~/.bash_history中读取历史命令
        -d: num:删除指定编号的历史命令(***别人系统的时候,抹掉自己的操作命令)

        6、ls命令
        作用:显示当前或者指定目录下的文件
        选项
        -a:显示目录下的全部文件(包括隐藏文件)
        -l:显示文件和目录的详细属性
        -d:显示目录自身(如果不使用-d则是显示目录中的文件)
        -h:结合-l使用,以易读的方式显示目录的大小,(只显示
        文件的大小,不显示目录的大小)
        -t: 按照文件的修改时间排序,将最后修改的文件排在前边
        -r:结合-l -t使用,倒序排序
        例子:显示跟下有哪些文件
        [root@localhost ~]# ls /
        1.txt  2.txt  bin   cgroup  etc   lib    lost+found  misc  net  proc  sbin     srv  tmp  var
        1.xtx  3.txt  boot  dev     home  lib64  media       mnt   opt  root  selinux  sys  usr
        黑白颜色是一般文件,蓝颜色的是目录
        例子:显示当前目录下有哪些文件
        #ls ./
        #ls
        (当前位置是./,但是可以省略)
        例子:创建文件并查看文件的详细信息
        [root@localhost tmp]# mkdir book
        [root@localhost tmp]# touch book/{linux,python,go}
        [root@localhost tmp]# ls book/
        go  linux  python
        [root@localhost tmp]# ls -l book/
        total 0
        -rw-r--r-- 1 root root 0 Apr 12 18:03 go
        -rw-r--r-- 1 root root 0 Apr 12 18:03 linux
        -rw-r--r-- 1 root root 0 Apr 12 18:03 python
        例子:显示a.txt的详细属性
        #ls -l a.txt
        例子:显示book目录的详细属性
        [root@localhost tmp]# ls -ld book
        drwxr-xr-x 2 root root 4096 Apr 12 18:03 book
        [root@localhost tmp]# cd book/
        [root@localhost book]# ls
        go  linux  python
        [root@localhost book]# vi go
        [root@localhost book]# vi linux
        [root@localhost book]# vi python 
        [root@localhost book]# ls -l
        total 12
        -rw-r--r-- 1 root root 164 Apr 12 18:11 go
        -rw-r--r-- 1 root root  83 Apr 12 18:13 linux
        -rw-r--r-- 1 root root 165 Apr 12 18:13 python
        ls -lh
        total 45M  
        -rw-r--r-- 1 root root 164 Apr 12 18:11 go
        -rw-r--r-- 1 root root 45M Apr 12 19:01 linux  
        -rw-r--r-- 1 root root 98K Apr 12 18:48 python
        -h只显示文件的大小,不显示目录的大小
        例:
        [root@localhost book]# cd ..
        [root@localhost tmp]# ls -l -h
        total 4.0K
        drwxr-xr-x 2 root root 4.0K Apr 12 19:04 book
        显示目录的大小用du命令,此处不过多解释。讲解磁盘的时候会详情讲解。
        -t将最后修改的文件排在前面
        [root@localhost tmp]# cd book/
        [root@localhost book]# ls
        go  linux  python
        [root@localhost book]# ls -l
        total 45676
        -rw-r--r-- 1 root root      164 Apr 12 18:11 go
        -rw-r--r-- 1 root root 46661650 Apr 12 19:01 linux
        -rw-r--r-- 1 root root    99824 Apr 12 18:48 python
        [root@localhost book]# vi linux 
        [root@localhost book]# ls -l -t
        total 45676
        -rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux
        -rw-r--r-- 1 root root    99824 Apr 12 18:48 python
        -rw-r--r-- 1 root root      164 Apr 12 18:11 go
        [root@localhost book]# vi go 
        [root@localhost book]# ls -l -t
        total 45676
        -rw-r--r-- 1 root root      167 Apr 12 22:27 go
        -rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux
        -rw-r--r-- 1 root root    99824 Apr 12 18:48 python
        绝对路径和相对路径
        绝对路径:就是从根目录下开始查找
        相对路径:相对当前位置的路径
        在home目录下的a中创建一个文件a.txt
        [root@localhost home]# mkdir a 
        [root@localhost home]# touch /home/a/a.txt 绝对路径
        [root@localhost home]# touch ./a/a.txt 相对路径(前提必须在home之下)
        [root@localhost home]# touch a/a.txt   相对路径(前提必须在home之下)
        touch ./a/a.txt(前提必须在home之下)    
        touch a/a.txt  (前提必须在home之下)
        例子:切换到/etc/init.d目录下
        要求1:在init.d下新建目录abc
        要求2:在/etc下新建目录abc
        1:方法1:相对路径
        [root@localhost home]# cd /etc/init.d
        [root@localhost init.d]# mkdir abc
        [root@localhost init.d]# ls
        abc        autofs            cups        kdump         netconsole  ntpdate      rdisc        
        [root@localhost ~]# mkdir /etc/init.d/abc
        [root@localhost ~]# .ls /etc/init.d/
        abc        autofs            cups        kdump         netconsole  ntpdate      rdisc        rpcsvcgssd  sssd
        绝对路径:mkdir /etc/abc
        相对路径:mkdir ../abc
        7、cat命令 
        全称:concatenate(连接并显示:拼接多个文件)
        作用:显示一个文本文件中的内容
        格式:cat [选项] 文件
        选项:
        -n:在每行的前面显示行号
        361  cat /etc/init.d/halt
        362  cat -n /etc/init.d/halt
        -E:显示出来行结束符
        补充:windows中的文件的换行符:\n
        linux中的文件的换行符:$ 
        (这样的符号都是隐性符号-都是默认不可见的)
        8、tac命令
        作用:将一个文件中的内容倒序显示出来
      (最后一行变成第一行)
        [root@localhost tmp]# vi 1.txt
        11111
        2222
        3333
        444
        555
        [root@localhost tmp]# tac 1.txt
        555
        444
        3333
        2222
        11111
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI