• Linux基础命令1


    命令的格式:
    ls options file1


    1.ls
      作用:列出当前目录下的文件
      选项:
      -l: list 长输出,显示文件的详细信息
      -h: human-readable 人类易读的方式显示文件的大小
      -a: all 显示所有文件包括以.开头的隐藏文件
      -d: directory 显示目录详细信息

      例子1:查看当前目录下的文件
      [root@kuying2 ~]# ls
      anaconda-ks.cfg gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm

      例子2:查看文件详细信息包括权限,属主和属组,创建日期
      [root@kuying2 ~]# ls -l
      total  270640
      -rw-------. 1 root root 1246 Apr 4 06:53 anaconda-ks.cfg
      -rw-r--r-- 1 root root 277130277 Nov 13 2018 gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm

      例子3:以人类易读的方式显示文件大小
      方法一:
      [root@kuying2 ~]# ls -l -h
      total 265M
      -rw-------. 1 root root 1.3K Apr 4 06:53 anaconda-ks.cfg
      -rw-r--r-- 1 root root 265M Nov 13 2018 gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm


      方法二:
      [root@kuying2 ~]# ls -lh
      total 265M
      -rw-------. 1 root root 1.3K Apr 4 06:53 anaconda-ks.cfg
      -rw-r--r-- 1 root root 265M Nov 13 2018 gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
      drwxr-xr-x 2 root root 6 Jul 8 22:47 kuying

      注意:
      1.短选项可以合并在一起写!
      2.短选项就是以一个-开头的
      3.长选项就是以两个-开头的
      4.长选项不可以合并在一起写!
      5.短选项是工作中用的最多的。


      例子4:显示所有的文件
      [root@kuying2 ~]# ls -a
      . anaconda-ks.cfg .bash_logout .bashrc gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm .pki .viminfo
      .. .bash_history .bash_profile .cshrc kuying .tcshrc

      例子5:显示所有文件的详细信息
      [root@kuying2 ~]# ls -la
      total 270672
      dr-xr-x---. 4 root root 217 Jul 8 22:47 .
      dr-xr-xr-x. 17 root root 224 Apr 4 06:52 ..
      -rw-------. 1 root root 1246 Apr 4 06:53 anaconda-ks.cfg

      例子6:显示所有文件的详细信息并以人类易读的方式显示大小
      [root@kuying2 ~]# ls -lah
      total 265M
      dr-xr-x---. 4 root root 217 Jul 8 22:47 .
      dr-xr-xr-x. 17 root root 224 Apr 4 06:52 ..
      -rw-------. 1 root root 1.3K Apr 4 06:53 anaconda-ks.cfg

      例子7:查看目录的信息
      [root@kuying2 ~]# ls -ld kuying
      drwxr-xr-x 2 root root 137 Jul 8 22:54 kuying

    2.man
      命令帮助手册

      使用格式:man CMD

      例子1:查看ls命令的使用方法
      man ls

    3. pwd
      显示当前的工作目录 (print working directory)

      例子1:显示当前工作目录
      [root@kuying2 ~]# pwd
      /root

    4.cd
      切换工作目录(change directory)

      例子1:切换到/tmp目录下
      [root@kuying2 ~]# cd /tmp
      [root@kuying2 tmp]#

      root: 表示登录的用户
      kuying2: 主机名
      tmp: 当前所处的工作目录
      #: root标识符
      $: 普通用户标识符

      例子2:切换回上次所处的工作目录
      [root@kuying2 tmp]# cd -

      例子3:切换到上一级工作目录 !
      [root@kuying2 4]# cd ..

      例子4:切换到用户家目录
      方法一:
      [root@kuying2 2]# cd

      方法二:
      [root@kuying2 tmp]# cd ~

    5.mkdir  创建目录

      选项:
      -p 创建级联目录2/3/4 及多级目录

      例子1:创建目录kuying
      [root@kuying2 ~]# mkdir kuying1

      例子2:创建级联目录2/4/5
      [root@kuying2 ~]# mkdir 2/4/5 -p

    6.touch  

      创建普通文件

      例子1:创建普通文件test
      [root@kuying2 ~]# touch test

    7.echo
      输出一段文本
     选项:
      -e 解释特殊字符

      例子1:输出hello world
      [root@kuying2 ~]# echo "hello world"
      hello world


      例子2:颜色输出hello world
      [root@kuying2 ~]# echo "hello world"
      hello world
      [root@kuying2 ~]# echo -e "33[32mHello World33[0m"
      Hello World

      例子3:换行输出
      [root@kuying2 ~]# echo "hello Kitty"
      hello Kitty
      [root@kuying2 ~]# echo -e "hello Kitty"
      hello
      Kitty

    8.rm
      删除文件

      选项:
      -r 删除目录时使用
      -f 强制删除

      例子1:删除test文件
      [root@kuying2 ~]# rm test
      rm: remove regular empty file ‘test’? y

      例子2:强制删除
      [root@kuying2 ~]# rm -f test

      例子3:删除目录
      [root@kuying2 ~]# rm -rf kuying

    9.mv
      移动文件或者改名

      例子1:移动test文件至/tmp下
       [root@kuying2 ~]# mv test /tmp

      mv 源文件 目标路径
      想把那个文件移动到哪里去

      [root@kuying2 ~]# mv /tmp/test .

      注意:一个.表示当前目录

      例子2:改名
      [root@kuying2 ~]# mv test test1

      例子3:移动多个文件
      [root@kuying2 ~]# touch {1..10}.txt #创建1.txt,2.txt,3.txt,4.txt....
      [root@kuying2 ~]# ls
      10.txt 2.txt 4.txt 6.txt 8.txt anaconda-ks.cfg test1
      1.txt 3.txt 5.txt 7.txt 9.txt gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
      [root@kuying2 ~]# mkdir kuying
      [root@kuying2 ~]# ls
      10.txt 2.txt 4.txt 6.txt 8.txt anaconda-ks.cfg kuying
      1.txt 3.txt 5.txt 7.txt 9.txt gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm test1
      [root@kuying2 ~]# mv {1..10}.txt kuying #移动1.txt,2.txt,3.txt...到kuying目录下

      mv kuying kuying1
      注意:
      1.如果当前目录下有kuying1目录就会把kuying目录移动到kuying1目录下
      2.如果当前目录下没有kuying1目录就会把kuying目录改名为kuying1

    10.cp
      复制文件
      选项:
      -a 复制目录时使用,并且保持属性不变 ,已经包含了-rp(属性就是权限,属主和属组)
      -r 复制目录时使用,但是不可以保持属性不变
      -p 不可以复制目录,但是可以保持属性不变


      例子1:复制test文件
      [root@kuying2 ~]# cp test1 test2

      例子2:复制目录
      方法一:
      [root@kuying2 ~]# cp -r kuying kuying1

      方法二:
      [root@kuying2 ~]# cp -a kuying kuying1

    11. rmdir
      删除空目录

      例子1:删除空目录

      [root@kuying2 ~]# rmdir cn


    12. cat

      查看文本内容,适合查看小文件
      选项:

      例子1;查看文本内容
      [root@kuying2 ~]# cat test1
      123

      例子2:显示行号
      [root@kuying2 ~]# cat -n /etc/passwd

    13.more
      查看文本内容,适合查看较大的文本
      会显示读取文章的百分比

      例子1:
      [root@kuying2 ~]# more /etc/init.d/functions

    14.less
      查看文本内容,适合查看中等大小的文本
      支持翻页

      查看文件大小顺序:
      more --》less --》cat

    15.tail
      默认查看后十行内容
      选项:
      -f 持续刷新文本内容
      -n 指定显示的行数

      例子1:查看文本后十行
      [root@kuying2 ~]# tail /etc/init.d/functions

      例子2:查看文本后3行
      方法一:
      [root@kuying2 ~]# tail -n 3 /etc/passwd
      git:x:997:995::/var/opt/gitlab:/bin/sh
      gitlab-redis:x:996:994::/var/opt/gitlab/redis:/bin/nologin
      gitlab-psql:x:995:993::/var/opt/gitlab/postgresql:/bin/sh

      方法二:
      [root@kuying2 ~]# tail -3 /etc/passwd
      git:x:997:995::/var/opt/gitlab:/bin/sh
      gitlab-redis:x:996:994::/var/opt/gitlab/redis:/bin/nologin
      gitlab-psql:x:995:993::/var/opt/gitlab/postgresql:/bin/sh

      例子3:持续检测文本test #监测文本文件内容的变化 !
      [root@kuying2 ~]# tail -f test1

    16. head

      默认查看前10行
      例子1:查看文本前10行
      [root@kuying2 ~]# head /etc/passwd

      例子2:显示前三行
      [root@kuying2 ~]# head -3 /etc/passwd

    17. clear
      清屏

      清屏快捷键:ctrl l
      强制终止:ctrl c

    18. reboot
      重启系统

    19. poweroff
      关机

  • 相关阅读:
    如何使用Jquery 引入css文件
    html如何绘制带尖角(三角)的矩形
    让HTML标签、DIV、SPAN拥有focus事件和blur事件,聚焦和失焦
    html如何引用另一个html的内容
    HTML中块级元素与内联元素有什么区别 ?
    一个js文件如何加载另外一个js文件
    在线工具-程序员的工具箱-在线Cron表达式生成器
    oracle fm格式化
    html如何让label在div中的垂直方向居中显示?
    服务发现框架选型: Consul、Zookeeper还是etcd ?
  • 原文地址:https://www.cnblogs.com/biht/p/11163760.html
Copyright © 2020-2023  润新知