加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱资讯网 (https://www.52junxun.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

Linux基本命令归纳整理

发布时间:2023-02-20 13:35:37 所属栏目:Unix 来源:
导读:  Linux 是一套免费使用和自由传播的类 Unix 操作系统,是一个基于 POSIX 和 UNIX 的多用户、多任务、支持多线程和多 CPU 的操作系统。严格来讲,Linux 这个词本身只表示 Linux 内核unix命令整理,但实际上人们已经
  Linux 是一套免费使用和自由传播的类 Unix 操作系统,是一个基于 POSIX 和 UNIX 的多用户、多任务、支持多线程和多 CPU 的操作系统。严格来讲,Linux 这个词本身只表示 Linux 内核unix命令整理,但实际上人们已经习惯了用 Linux 来形容整个基于 Linux 内核,并且使用 GNU 工程各种工具和数据库的操作系统。
 
  Linux基本命令归纳整理
 
  1. 帮助命令内建命令和外部命令
 
  在我们使用 Linux 操作系统的时候,经常会使用一些命令,但是由于时间长久的原因导致我们对于其使用方法的忘记。本文,就是为了解决这个问题而生的,授之以鱼不如授之以渔。
 
  实际上是 shell 程序的一部分,其中包含的是一些比较简单的 linux 系统命令,这些命令由 shell 程序识别并在 shell 程序内部完成运行,通常在 linux 系统加载运行时 shell 就被加载并驻留在系统内存中。内部命令是写在 bash 源码里面的,其执行速度比外部命令快,因为解析内部命令 shell 不需要创建子进程。比如:exit,history,cd,echo 等。
 
  escape@ubuntu:~\$ type cd
  cd is a shell builtin
  # 内建命令帮助获取方式
  escape@ubuntu:~$ help echo
  echo: echo [-neE] [arg ...]
      Write arguments to the standard output.
  外部命令是 linux 系统中的实用程序部分,因为实用程序的功能通常都比较强大,所以其包含的程序量也会很大,在系统加载时并不随系统一起被加载到内存中,而是在需要时才将其调用内存。通常外部命令的实体并不包含在 shell 中,但是其命令执行过程是由 shell 程序控制的。shell 程序管理外部命令执行的路径查找、加载存放,并控制命令的执行。shell 程序搜寻可执行程序文件的路径定义在PATH环境变量中,使用 echo $PATH 来查看。外部命令是在 bash 之外额外安装的,通常放在固定目录下。比如:ls,vi 等
 
  escape@ubuntu:~\$ type mount
  mount is /bin/mount
  which命令whereis命令
 
  escape@ubuntu:~\$ whatis date
  cal(1), ncal(1) - displays a calendar and the date of easter
  date(1) - display or set date and time
  iwidgets_datefield(n), iwidgets::datefield(n) - Create and manipulate a date field widget
  ntpdate(8) - set the date and time via NTP
  1.1 内建 hash 命令在 shell 搜中寻到的外部命令的路径结果会缓存至 key-value 存储中,而 hash 用来显示命令缓存。
 
  # 显示命令缓存次数
  [root@centos7 ~]# hash
       hits command
       2 /usr/bin/file
       8 /usr/bin/ls
  # 列出缓存过的命令
  [root@centos7 ~]# hash -l
       builtin hash -p /usr/bin/file file
       builtin hash -p /usr/bin/ls ls
  # 可以给命令建立缓存
  [root@centos7 ~]# hash -p /usr/bin/file f
  [root@centos7 ~]# hash -l
       builtin hash -p /usr/bin/file file
       builtin hash -p /usr/bin/file f
       builtin hash -p /usr/bin/ls ls
  # 删除某个命令的缓存
  [root@centos7 ~]# hash -d f
  [root@centos7 ~]# hash -l
       builtin hash -p /usr/bin/file file
       builtin hash -p /usr/bin/ls ls
  # 列出单个别名的路径
  [root@centos7 ~]# hash -t file
       /usr/bin/file
  # 删除所有命令缓存
  [root@centos7 ~]# hash -r
  [root@centos7 ~]# hash
       hash: hash table empty
  1.2 内建 history 命令history 命令用于管理命令历史。当登录 shell 时,会读取命令历史文件(~/.bash_history)中记录下的命令。当登录进 shell 后新执行的命令只会记录在缓存中,这些命令会用户退出时“追加”至命令历史文件中。
 
  # [命令选项]
  # 追加本次会话新执行的命令历史列表至历史文件中
  $ history -a
  # 删除历史中指定的命令
  unix 命令 修改文件权限_unix命令整理_unix 命令符 写入字符串
 
 
  $ history -d #
  # 清空命令历史
  $ history -c
  # [快捷操作]
  # 调用历史中第#条命令
  !#
  # 调用历史中最近一个以string开头的命令
  !string
  # 上一条命令
  !!
  1.3 外部 man 命令man 命令的配置文件 /etc/man.config。
 
  # 要查看指定章节中的手册
  man1: 用户命令
  man2: 系统调用
  man3: C库调用
  man4: 设备文件及特殊文件
  man5: 配置文件格式
  man6: 游戏
  man7: 杂项
  man8: 管理类的命令
  # 指明新的手册文件搜索位置
  $ MANPATH /PATH/TO/SOMEWHERE
  # 到指定位置下搜索COMMAND命令的手册页并显示
  $ man -M /PATH/TO/SOMEWHERE COMMAND
  # 帮助手册中的段落说明
  NAME
  SYNOPSIS
  DESCRIPTION
  OPTIONS
  EXAMPLES
  AUTHOR
  REPORTING BUGS
  SEE ALSO
  1.4 外部 info 命令
 
  # 查看帮助
  $ info COMMAND
  2. 日期时间Linux 中提供了什么我们日常操作所需要的基础命令,我们需要经常使用它们来提高我们的效率。本文将介绍几种 Linux 常用的命令以及操作,耐心看完肯定会对你有帮助的。2.1 date 命令系统时钟设定命令
 
  格式
 
  设置
 
  # 设置时间显示格式
  [root@centos7 ~]# date +"%F %T"
  2017-05-19 20:01:17
  [root@centos7 ~]# date +"%Y%m%d"
  20170519
  # 修改系统时间
  [root@centos7 ~]# date 122111112012.11
  Fri Dec 21 11:11:11 CST 2012
  # 显示昨天是星期几
  [root@centos7 ~]# date --date="yesterday" +%a
  Sun
  [root@centos7 ~]# date --date="yesterday" +%A
  Sunday
  unix 命令 修改文件权限_unix命令整理_unix 命令符 写入字符串
 
 
  # 显示当前时间,格式:2016-06-18 10:20:30
  [root@centos7 ~]# date +"%F %T"
  # 设置当前日期为2019-08-07 06:05:10
  [root@centos7 ~]# date 080706052019.10
  2.2 hwclock 命令clock 又或者 hwclock,是一样的命令。
 
  Linux 的两种时钟
 
  参数选项
 
  # hctosys
  $ hwclock -s
  # systohc
  $ hwclock -w
  2.3 ntpdate 命令前提是 IP 所在的那台机器启用了 NTP 服务!
 
  # 用于同步时间
  $ htpdate 172.17.0.1
  2.4 选择时区命令交互式命令:tzselect;非交互式命令:timedatectl
 
  CentOS 6/7 都支持的命令:tzselect,是一个交互式的命令,用于选择时区。
 
  unix命令整理_unix 命令符 写入字符串_unix 命令 修改文件权限
 
  Linux基本命令归纳整理 - 选择时区
 
  timedatectl 命令只支持 CentOS 7 系统。
 
  # 时间状态
  $ timedatectl status
  # 列出时区
  $ timedatectl list-timezones
  # 更改时区
  $ timedatectl set-timezones Asia/Shanghai
  # 在CentOS6/7都支持一个非交互式的方法
  $ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  3. 别名使用主要用到两个命令:alias & unalias
 
  [root@centos7 ~]# alias cdnet="cd /etc/sysconfig/network-scripts/"
  [root@centos7 ~]# cdnet
  [root@centos7 network-scripts]# pwd
  /etc/sysconfig/network-scripts
  [root@centos7 network-scripts]# alias
  alias cdnet='cd /etc/sysconfig/network-scripts/'
  alias grep='grep --color=auto'
  alias ll='ls -l --color=auto'
  [root@centos7 network-scripts]# unalias cdnet
  [root@centos7 network-scripts]# alias
  alias grep='grep --color=auto'
  alias ll='ls -l --color=auto'
  \COMMAND
  'COMMAND'
  '/PATH/TO/COMMAND'
  # 下面是某些alias设置
  alias vi ="vim"
  alias cdnet="cd /etc/sysconfig/network-scripts"
  alias vimnet1="vim /etc/syscofig/network-scripts/eth0"
  alias vimnet2="vim /etc/syscofnig/network-scripts/eth1"
  # 更改完成后,可以用`source`或`.`命令来使之立即生效,或者重启shell:
  [root@centos7 ~]# source ~/.bashrc
  [root@centos7 ~]# . ~/.bashrc
 

(编辑:我爱资讯网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章