• 最简洁明了的Linux常用命令


    Linux Logo 2

    1、ls 命令

    查看当前目录下可见的文件、文件夹及其相关权限
    常用参数:-l 列表式查看
              -al 查看所有,包括隐藏的文件、文件夹
    
    [root@qinshengfei bin]# ls --color 以彩色显示 
    [root@qinshengfei bin]# ls -l     详情列出目录文件
    [root@qinshengfei bin]# ls -a     显示所有文件,包括隐藏文件
    [root@qinshengfei bin]# ls -al    列表显示所有文件
    [root@qinshengfei bin]# ls -al|more 將目录內容分布显示
    

    2、mkdir 创建文件夹

    常用参数 : 直接接文件夹名称
    
    [root@qinshengfei /home]# mkdir test
    
    

    3、pwd 显示当前工作目录

    [root@qinshengfei bin]#  pwd
    /usr/bin  <== 显示当前工作目录
    

    4、cd 切换目录

    [root@qinshengfei /root]#  cd ..       <== 回到上一级目录
    [root@qinshengfei /]#  cd          <== 回到home目录
    [root@qinshengfei root]#  cd /usr/bin  <== 到 /usr/bin 目录
    
    

    5、rmdir 删除指定目录

    如果要删除的目录里面有文件或文件夹,是无法移动的,这时,就需要加上参数 -rf 来强制操作删除。
    
    [root@qinshengfei /root]#   rmdir ./test       <== 删除目录
    [root@qinshengfei /root]#  rmdir ./test2 -rf       <== 删除目录及子目录、文件
    

    6、rm 删除指令文件

    [root@qinshengfei /root]# rm test
    
    

    7、cp 就是 copy 的意思。例如我们要把 .bashrc 这个文件复制到/home目录下,可以:

    [root@qinshengfei /root]# cp .bashrc /home
    
    

    8、mv 移动文件、文件夹

    [root@qinshengfei /root]# mv test.txt /home
    
    

    9、cat 打印文件内容在控制台上,例如要打印mysql的配置文件到控制上

    [root@qinshengfei /mysql.conf.d]# cat mysqld.cnf
    
    

    10、tail 按行显示文件内容

    [root@qinshengfei /mysql.conf.d]# tail -n 5  mysqld.cnf
    
    

    11、less

    less命令可查看文件。 它使用起来速度更快,而且您不会无意间修改文件。 使用更少的光标,您可以使用向上和向下箭头键,PgUp和PgDn键以及Home和End键在文件中前后滚动。 按Q键退出。
    
    [root@qinshengfei /mysql.conf.d]# less  log.txt
    
    

    12、grep 管道,输出指定文件内容

    例如使用 ps -aux 查询进程,我们只需要知道 tomcat 有不有运行,就可以使用管道指令『|』加入 grep 这个命令同时操作。
    
    [root@qinshengfei /]# ps -aux|grep tomcat
    
    

    13、find 查找文件

    [root@qinshengfei /]#  find / -name bin
    
    
    

    14、tar -cvf 压缩文件

    [root@qinshengfei /root]# tar  -zcvf  app.tar.gz app 
    
    

    15、gzip 压缩

    也是一压缩命令,跟compress 很相似,指令的用法也相同!只是压缩后缀名 .gz !
    
    [root@qinshengfei /root]# gzip  -d  xxxxx.gz
    
    

    16、unzip 解压文件

    [root@qinshengfei /root]# unzip app.zip 解压一个叫做 'app.zip'的文件 
    
    

    18、exit 退出登录

    
    [root@qinshengfei /root]# exit
    

    19、ping 与windows下的ping 一样 ,测试两台电脑之间是否连通

    
    [root@qinshengfei /root]# ping baidu.com
    

    20、telnet 与windows下的一样 ,测试目标机端口开放

    [root@qinshengfei /root]# telnet 47.2.30.289 8080
    
    

    21、who 查看当前登录的所有用户

    [root@qinshengfei /root]# who
    
    

    22、su 切换用户

    [root@qinshengfei /root]# su  qinshengfei
    
    

    23、uname uname会显示出关于系统的重要信息,如内核名称、主机名、内核版本、处理机类型等等,使用uname -a可以查看所有信息。

    [root@qinshengfei /]# uname -a
    Linux qinshengfei 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    [root@qinshengfei /]# 
    
    

    24、alias

    使用alias命令可以给命令或命令序列指定自己的名称。 然后,您可以输入您的简称,然后Shell将为您执行命令或命令序列。
    
    [root@qinshengfei /]# alias pf="ps -e | grep $1"
    [root@qinshengfei /]# pf tomcat
    
    

    25、chmod 修改文件、文件夹权限的命令

    0: No permission
    1: Execute permission
    2: Write permission
    3: Write and execute permissions
    4: Read permission
    5: Read and execute permissions
    6: Read and write permissions
    7: Read, write and execute permissions
    
    [root@qinshengfei /]# chmod 777 app -r <== -r 连同子目录权限一起修改
    
    

    26、chown

    可以使用chown更改文件的所有者或组,或两者。 必须提供所有者和组的名称,以:字符分隔。 
    
    [root@qinshengfei /]# chown dave:mary example.txt
    

    27、curl

    curl命令是从统一资源定位器(URL)或Internet地址检索信息和文件的工具。
    
    [root@qinshengfei /]# curl http://www.baidu.com index.html
    
    

    28、echo

    echo命令将文本字符串打印(回显)到终端窗口。也可以将字符串打印到文件。
    
    [root@qinshengfei /]# echo "hello world"
    hello world
    [root@qinshengfei /]# 
    

    29、free

    free命令为您提供计算机内存使用情况的摘要。 它对主随机存取存储器(RAM)和交换存储器都执行此操作。 -h(人类)选项用于提供人类友好的数字和单位。 没有此选项,数字以字节为单位。
    
    [root@qinshengfei /]# free
                  total        used        free      shared  buff/cache   available
    Mem:        8000348     1554508     4549432         576     1896408     6194856
    Swap:             0           0           0
    [root@qinshengfei /]# 
    
    

    30、history

    history命令列出了您先前在命令行上发出的命令。 您可以通过键入感叹号来重复历史记录中的任何命令! 以及历史记录列表中的命令编号。
    
    [root@qinshengfei /]# 
    [root@qinshengfei /]# history
        1  yum install docker
        2  yum install nginx
        3  yum -y install docker-ce
       
    
    

    31、kill

    我们将使用上面关于别名命令的部分中的ps和grep技巧。 我们可以搜索快门过程并获取其PID,如下所示:

    [root@qinshengfei /]# ps -ef|grep nginx
    root     31884 22980  0 16:19 pts/0    00:00:00 grep --color=auto nginx
    root     32400     1  0 Feb18 ?        00:00:00 nginx: master process /usr/sbin/nginx
    nginx    32401 32400  0 Feb18 ?        00:00:00 nginx: worker process
    nginx    32402 32400  0 Feb18 ?        00:00:00 nginx: worker process
    [root@qinshengfei /]# kill -9 32400
    
    

    32、passwd

    passwd命令使您可以更改用户密码。 只需键入passwd即可更改您自己的密码。
    
    [root@qinshengfei /]# sudo passwd mary
    
    

    33、ssh

    使用ssh命令建立与远程Linux计算机的连接并登录到您的帐户。 要建立连接,您必须提供您的用户名以及远程计算机的IP地址或域名。 在此示例中,用户mary以192.168.4.23登录到计算机。 建立连接后,将要求她输入密码。
    
    [root@qinshengfei /]# ssh mary@192.168.4.23
    mary@192.168.4.23's password: 
    
    

    35、df 查看系统磁盘的使用情况

    [root@qinshengfei /]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    devtmpfs         3986836       0   3986836   0% /dev
    tmpfs            4000172       0   4000172   0% /dev/shm
    tmpfs            4000172     576   3999596   1% /run
    tmpfs            4000172       0   4000172   0% /sys/fs/cgroup
    /dev/vda1       52417516 4031296  48386220   8% /
    overlay         52417516 4031296  48386220   8% /var/lib/docker/overlay2/650e5470981551bdd57ee3f9da79da55ef5170d11017e282c318f801b5c5ac4b/merged
    tmpfs             800032       0    800032   0% /run/user/0
    [root@qinshengfei /]# 
    
    

    36、ps 显示系统进程

    ps命令列出了正在运行的进程。 使用不带任何选项的ps会导致它列出当前shell中正在运行的进程。
    
    [root@qinshengfei /]# ps
      PID TTY          TIME CMD
     9191 pts/0    00:00:00 ps
    16776 pts/0    00:00:00 bash
    17212 pts/0    00:00:00 mysql
    22980 pts/0    00:00:00 bash
    23524 pts/0    00:00:44 java
    [root@qinshengfei /]# 
    
    
    要查询关键字进程,可以结合管道命令。
    
    [root@qinshengfei /]# ps -ef|grep nginx
    root     10377 22980  0 16:26 pts/0    00:00:00 grep --color=auto nginx
    root     32400     1  0 Feb18 ?        00:00:00 nginx: master process /usr/sbin/nginx
    nginx    32401 32400  0 Feb18 ?        00:00:00 nginx: worker process
    nginx    32402 32400  0 Feb18 ?        00:00:00 nginx: worker process
    [root@qinshengfei /]# 
    
    

    37、top 显示系统进程

    [root@qinshengfei /]# top
    

    38、reboot 重新计算机

    [root@qinshengfei /]# reboot 
    

    39、shutdown

    使用不带参数的关机将在一分钟内关闭计算机。

    [root@qinshengfei /]# shutdown
    
    使用 now 参数 ,立刻关机
    
    [root@qinshengfei /]# shutdown -h now
    
    使用 -r 参数 重启 与reboot效果一样  ,shutdown -r  可以定时
    
    [root@qinshengfei /]# shutdown -r now
    

    40、yum

    centos环境下安装软件的命令
    
    [root@qinshengfei /]# yum install nginx
    
  • 相关阅读:
    android:id="@android:id/tabhost" 、android:id="@+id/llRoot" 、android:id="@id/llRoot" 之间的区别
    android:ellipsize的使用
    PopupWindow为什么要设置setBackgroundDrawable(new BitmapDrawable());
    android中LayoutInflater的3种使用以及getSystemService的API
    context 的理解
    Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别
    android Matrix 使用
    public private protected frientdly 作用域
    pyinstaller参数介绍以及总结
    MongoDB高级查询详细
  • 原文地址:https://www.cnblogs.com/qinshengfei/p/12336352.html
Copyright © 2020-2023  润新知