Linux基础命令

1. ls 列出文件目录,默认当前目录下 

     常用选项:

       -a  列出所有的文件,包括所有以.开头的隐藏文件

       -l  长输出

       -d  列出目录本身,并不包括目录中的文件(常与-l一起使用)

       -h  和-l一起使用,文件大小人类易读

            [root@localhost ~]# ls /root  #列出/root下的文件及目录                          

            anaconda-ks.cfg initial-setup-ks.cfg 公共 视频 文档 音乐 模板 图片 下载 桌面

       [root@localhost ~]# ls -a   #列出当前目录下的所有文件和目录

      . .bash_logout .cache .dbus initial-setup-ks.cfg 公共 图片 音乐
      .. .bash_profile .config .esd_auth .local 模板 文档 桌面
      anaconda-ks.cfg .bashrc .cshrc .ICEauthority .tcshrc 视频 下载

      [root@localhost ~]# ls -l  #列出当前目录下文件和目录的详细信息 

      总用量 8
      -rw-------. 1 root root 1698 4月 10 04:47 anaconda-ks.cfg
      -rw-r--r--. 1 root root 1726 4月 9 21:03 initial-setup-ks.cfg
      drwxr-xr-x. 2 root root 6 4月 9 21:03 公共
      drwxr-xr-x. 2 root root 6 4月 9 21:03 模板
      drwxr-xr-x. 2 root root 6 4月 9 21:03 视频
      drwxr-xr-x. 2 root root 6 4月 9 21:03 图片
      drwxr-xr-x. 2 root root 6 4月 9 21:03 文档
      drwxr-xr-x. 2 root root 6 4月 9 21:03 下载
      drwxr-xr-x. 2 root root 6 4月 9 21:03 音乐
      drwxr-xr-x. 2 root root 6 4月 9 21:03 桌面

      [root@localhost ~]# ls -ld  #列出当前目录中包含目录的详细信息

      dr-xr-x---. 14 root root 4096 4月 10 14:09 .

      [root@localhost ~]# ls -lh  #长输出列出的文件大小人类易读
      总用量 8.0K
      -rw-------. 1 root root 1.7K 4月 10 04:47 anaconda-ks.cfg
      -rw-r--r--. 1 root root 1.7K 4月 9 21:03 initial-setup-ks.cfg


2. pwd 显示出当前活动目录的名称

       [root@localhost ~]# pwd

      /root  #当前活动目录名称


3. mkdir 创建目录

       -p  创建级联目录

       [qing@localhost ~]$ ls

      Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
      [qing@localhost ~]$ mkdir wu  #创建目录wu
      [qing@localhost ~]$ ls   #列出当前目录下的文件,查看是否创建成功
      Desktop Documents Downloads Music Pictures Public Templates Videos wu
      [qing@localhost ~]$ mkdir -p 1/2/3  #创建级联目录
      [qing@localhost ~]$ ls
      1 Desktop Documents Downloads Music Pictures Public Templates Videos wu
      [qing@localhost ~]$ ls 1
      2
      [qing@localhost ~]$ ls 1/2
      3


4. cd 切换目录

     ..  切换至上级目录

     -   切换至上次所在目录

     ~   切换至用户家目录(直接cd也可切换至用户家目录)

      [root@localhost ~]# cd wu  #切换至wu目录

      [root@localhost wu]# ls
      text
      [root@localhost wu]# cd text
      [root@localhost text]# cd ..  #切换至上级目录
      [root@localhost wu]# cd -  #切换至上次所在目录
      /root/wu/text
      [root@localhost text]# cd ~  #切换至用户家目录
      [root@localhost ~]# cd -   
      /root/wu/text
      [root@localhost text]# cd  #切换至用户家目录
      [root@localhost ~]#


5. cp 复制文件、目录

       -p  保持属性不变 

       -r  递归复制目录 

       -a  复制时,尽可能保持文件的结构和属性. 等同于 -dpR      

      [root@localhost ~]# cp wu/text/test.txt test1.txt
      [root@localhost ~]# ls
      anaconda-ks.cfg   Downloads  original-ks.cfg Templates Videos
      Desktop initial-setup-ks.cfg Pictures test wu  test1.txt
      [root@localhost ~]# cp -p wu/text/test.txt test2.txt 
      [root@localhost ~]# cp -a wu/text/test.txt test3.txt

      [root@localhost ~]# ls -l wu/text
      total 0
      -rw-r--r--. 1 root root 0 Apr 10 18:34 test.txt

      [root@localhost ~]# ls -l
      total 16
      -rw-r--r--. 1 root root 0 Apr 10 23:59 test1.txt
      -rw-r--r--. 1 root root 0 Apr 10 18:34 test2.txt   #与test.txt属性一致
      -rw-r--r--. 1 root root 0 Apr 10 18:34 test3.txt   #与test.txt属性一致

      [root@localhost ~]# cp wu wu3
      cp: omitting directory ‘wu’  #复制目录时要加-r或-a选项,否则系统会提示报错

      [root@localhost ~]# cp -r wu wu1
      [root@localhost ~]# ls
      anaconda-ks.cfg  Downloads  original-ks.cfg Templates  wu
      Desktop  initial-setup-ks.cfg   Pictures  wu1
      [root@localhost ~]# ls wu1
      text
      [root@localhost ~]# ls wu1/text
      test.txt
      [root@localhost ~]# cp -a wu wu2
      [root@localhost ~]# ls -l
      total 16
      drwxr-xr-x. 3 root root 18 Apr 10 18:33 wu
      drwxr-xr-x. 3 root root 18 Apr 11 00:03 wu1
      drwxr-xr-x. 3 root root 18 Apr 10 18:33 wu2    #与源目录wu属性一致


     

6. mv 移动文件或修改文件名

7. rm 移除文件或目录

       -f  不作任何提示

       -r  或者-R递归移除目录

8. rmdir 删除空目录 

9. touch 创建文件

可查看文件内容的5个命令:more > less > cat > tail = head 

10. cat 连接文件并在标准输出上输出(用于内容较少的)

11. more 在显示器上阅读文件的过滤器(查看内容较多的)  more命令会在最下面使用百分比的形式来提示您已经阅读了多少内容

12. less 与 more 类似,但使用 less 可以随意浏览文件,而 more 仅能向前移动,却不能向后移动(pgup键),而且 less 在查看之前不会加载整个文件

13. head 输出文件的开始部分(默认前10行)

       -n  指定打印行的数量

14. tail 输出文件的末尾部分(默认十行)

       -n  指定打印行的数量

       -f  当文件增长时,输出后续添加的数据(持续刷新)

15. wc 统计文本信息

       -c  统计字节

       -w  统计单词数量

       -l  统计行数

16. echo 输出并显示一行文本

       -e  对特殊字符进行解释

17. alias 查看或设置别名

18. unalias 取消别名

19. date 打印或设置系统日期和时间

       "+%Y/%m/%d"  显示年/月/日("+%F"也可显示年月日)

       "+%H/%M/%S"  显示时:分:秒("+%T"也可显示时分秒)

20. man 命令帮助使用手册 (用法:man 命令)

        进入man命令界面后的常用按键:

      翻页工具:空格键 (向下翻一页)  PaGe_down(向下翻一页)  PeGe_up(向上翻一页)   home(翻至首页)  end(翻至尾页) 

      查找关键词:        / (从上至下搜索某个关键词)        ?(从下至上搜索某个关键词) 

      定位关键词:n (定位到下一个搜索到的关键词)       N(定位到上一个搜索到的关键词)

      退出man命令界面: q

        man命令帮助信息的结构及其代表含义

结构名称

代表含义                                                            

NAME

命令的名称

SYNOPSIS

参数的大致使用方法

DESCRIPTION

介绍说明

EXAMPLES

演示(附带简单说明)

OVERVIEW

概述

DEFAULTS

默认的功能

OPTIONS

具体的可用选项(带介绍)

ENVIRONMENT

环境变量

FILES

用到的文件

SEE ALSO

相关的资料

HISTORY                             

维护历史与联系方式

21. ps 查看系统中的进程状态

       aux  是用BSD的格式来显示

            显示的项目有:USER , PID , %CPU , %MEM , VSZ , RSS , TTY , STAT , START , TIME , COMMAND

       -ef  是用标准的格式显示

            显示的项目有:UID , PID , PPID , C , STIME , TTY , TIME , CMD

22. kill 终止进程(kill后面指定PID号码)

       -15  (默认选项)执行时可能出现3种情况:程序立即停止

                                               当程序释放相应资源后再停止

                                               程序可能仍然继续运行      

       -9  强制终止

23. clear 清屏

       清屏快捷键(Ctrl + L)

       强行终止(Ctrl + C)

24. history 查看历史命令(默认1000行)

25. poweroff 关机

26. reboot 重启

27. ping 向网络主机发送ICMP(检测主机是否在线)

       -c  发送包的数量

       -w  等待时间(当试图检测不可达主机时此选项很有用)

       -i  <间隔秒数>指定收发信息的间隔时间

28. uname 显示输出系统信息

       -a  显示所有信息

       -r  显示操作系统内核版本

       cat /etc/redhat-release  查看系统版本

29. hostname 显示或设置主机名

30. whoami 显示当前用户

31. who 显示当前登录的用户

32. w 显示登录本机的用户

33. which 显示命令的完整路径

34. du 显示文件及目录大小 。默认显示一个目录下的所有的文件,最后一行会有大小的总和。

       -s  仅显示总和

       -h  人类易读

35. df 报告文件系统磁盘空间的使用情况

       -h  人类易读

36. free 显示系统中已用和未用的内存空间总和

       -m  以兆(M)为单位

       -h  人类易读

       -s  <间隔秒数>持续观察内存使用状况

原文地址:https://www.cnblogs.com/-wzhq/p/10665907.html