Linux基础命令总结(CentOS6.9, CentOS7.3) - 课 2017-07-1-14

这篇博客详细总结了Linux系统的基础命令,涵盖了从基础操作、文件系统管理到用户组管理、网络属性、系统管理等多个方面。内容包括clear、hostname、ls、cat、whoami等常用命令的使用方法,适合Linux初学者参考学习。
摘要由CSDN通过智能技术生成

Linux基础命令学习总结,随着学习的前进,将不断完善。网友们,有错误之处,请给我留言改正喔,谢谢!

基础操作

clear hostname tty who whoami w whatis which whereis hash enable alias unalias date clock hwclock cal ldd uname timedatectl screen script chvt man


文件、目录、磁盘、文件系统

cd pwd ls cat tac nl head tail less more hexdump od cp mv rm mkdir rmdir dd gedit nano file type iconv


用户和组

id getent


BASHELL 特性

echo history hash history


网络属性

ifconfig ping rz sz


系统启动,关机

exit logout init quit reboot shutdown runlevel halt poweroff


进程

free lsblk lscpu


程序包管理

rpm . source



clear

clear the terminal screen 清空屏幕内容

hostname

Display the hostname 显示主机名
* hostname [-s|–short]
-s | –short Display the shourt host name, This is the hostname cut at the firs dot. 显示短主机名,取第一个点号之前的字符串

[centos6@root ~]# hostname
centos6.zhubiao.science
# -s 取第一个点号之前的字符串作为短主机名
[centos6@root ~]# hostname -s 
centos6

tty

print the file name of the terminal connected to standard input 显示当前工作终端下的终端的名字
* 终端分为:
* 物理终端
物理控制台:表示为 /dev/console, Linux单用户模式下显示为物理终端
* 虚拟终端
系统自带6个虚拟终端,表示为/dev/tty#, #为1-6
* 图形终端
* 伪终端
图形界面打开的命令行接口,通过ssh或telnet协议打开的命令行界面均为伪终端,表现为/dev/pts/#

# 将运行级别切换为单用户模式后,使用的将是物理终端,如下所示,当前运行级别为3的多用户模式,将其切换为1后查看终端。
[root@zb01 ~]# tty
/dev/tty1
[root@zb01 ~]# runlevel #查看运行级别
S 3
[root@zb01 ~]# init 1
...
[root@zb01 /]# runlevel
1 S
[root@zb01 /]# tty
/dev/console

who

Who is logged on 显示当前登录的用户
* who [options]
-b #系统登录的时间
-r #当前运行级别

[centos7@root dir]# who
root     tty1         2017-07-15 16:20
root     pts/0        2017-07-15 07:24 (gateway)
[centos7@root dir]# who -b
         system boot  2017-07-14 20:54
[centos7@root dir]# who -r
         run-level 3  2017-07-14 20:54                   last=5

whoami

显示当前登录的用户名
* who

[centos7@root dir]# whoami
root

w

Show who is logged on and what they are doing. 显示当前登录的用户和正在执行的命令
* w

[centos7@root dir]# w 
 17:08:16 up 12:09,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      16:20   47:20   0.04s  0.04s -bash
root     pts/0    gateway          07:24    0.00s  3.05s  0.01s w

whatis

查找外部命令的man手册帮助文档所在的章节
* whatis command #等同于man -f

[centos7@root ~]# whatis ls
ls (1)               - list directory contents
ls (1p)              - list directory contents

[centos7@root ~]# whatis cp
cp (1)               - copy files and directories
cp (1p)              - copy files

[centos7@root ~]# whatis ifconfig
ifconfig (8)         - configure a network interface

[centos7@root ~]# man -f ls
ls (1)               - list directory contents
ls (1p)              - list directory contents

[centos7@root ~]# man -f cp
cp (1)               - copy files and directories
cp (1p)              - copy files

which

按照PATH路径查找命令后显示其完整路径
* which [options] [command]
-a 显示命令所有PATH路径
–skip-alias 不显示别名

[centos6@root test]# which --skip-alias ls
/bin/ls
[centos6@root test]# which -a ls
alias ls='ls --color=auto'
    /bin/ls

whereis

查找命令所在路径,源码路径,帮助手册路径
whereis [options] [command]

[centos6@root test]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

[centos6@root test]# whereis -b mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql

[centos6@root test]# whereis -m mysql
mysql: /usr/share/man/man1/mysql.1.gz

cd

Change the shell working dirctory 切换工作目录
* cd [-P] DIR
-P 若DIR为符号链接目录,cd DIR切换到实际的工作目录,而不是符号链接目录
cd - #切换到上一个工作目录
cd ~ #切换到当前用户的家目录
cd ~USER #切换到USER用户的家目录,只有root有权限切换到任意用户的家目录
cd .. #切换到上一级目录

[centos6@root test]# pwd
/root/test
[centos6@root test]# cd ~  
[centos6@root ~]# pwd
/root
[centos6@root ~]# cd -
/root/test
[centos6@root test]# pwd
/root/test
[centos6@root test]# cd ~zb10
[centos6@root zb10]# pwd
/home/zb10
[centos6@root zb10]# cd ..
[centos6@root home]# pwd
/home
[centos6@root home]# 
# -P 切换到实际路径的工作目录下
[centos6@root test]# ll dir
lrwxrwxrwx. 1 root root 6 Jul 15 17:16 dir -> a/b/c/
[centos6@root test]# cd dir
[centos6@root dir]# pwd
/root/test/dir
[centos6@root dir]# cd -
/root/test
[centos6@root test]# cd -P dir
[centos6@root c]# pwd
/root/test/a/b/c

pwd

print the name of the current working dirctory 显示当前工作目录
* pwd [-P]
-P - 若当前工作目录为符号链接路径,加-P选项显示实际路径

[centos7@root test]# pwd
/root/test  #显示当前工作目录
# -P 显示出实际路径而不是符号链接的路径
[centos7@root test]# mkdir -p a/b/c 
[centos7@root test]# ln -s a/b/c dir  
[centos7@root test]# ll dir
lrwxrwxrwx. 1 root root 5 Jul 15 15:33 dir -> a/b/c
[centos7@root test]# cd dir 
[centos7@root dir]# pwd  
/root/test/dir
[centos7@root dir]# pwd -P  #加了-P选项,显示实际路径
/root/test/a/b/c

ls

List dirctory contents 列出当前或指定目录(或所有子目录)下的内容
* ls [options] [dirs]
- l 列出详细内容
-a | –all 列出所有内容包括. ..
-A 列出所有内容,不包括. ..
-d 仅列出指定的目录
–full-time 列出完整的修改时间格式

[centos6@root test]# ls
a dir
[centos6@root test]# ls -l
total 4
drwxr-xr-x. 3 root root 4096 Jul 15 17:15 a
lrwxrwxrwx. 1 root root 6 Jul 15 17:16 dir -> a/b/c/
[centos6@root test]# ll
total 4
drwxr-xr-x. 3 root root 4096 Jul 15 17:15 a
lrwxrwxrwx. 1 root root 6 Jul 15 17:16 dir -> a/b/c/
[centos6@root test]# ls -a
. .. a dir
[centos6@root test]# ls -A
a dir
[centos6@root test]# ls /root/test/
a dir
[centos6@root test]# ls --full-time /root/test/
total 4
drwxr-xr-x. 3 root root 4096 2017-07-15 17:15:41.550009093 +0800 a
lrwxrwxrwx. 1 root root 6 2017-07-15 17:16:44.490009154 +0800 dir -> a/b/c/

cat

Concatenate files and print on the standard output # 读取一个或多个文件(也可以从键盘输入) 并输出
* cat [options] [files]
-n # 在每行(包括空行)前面加上行号
-b # 在非空行前面加上行号

[centos7@root dir]# cat /etc/resolv.conf 
# Generated by NetworkManager
search magedu.com zhubiao.science

nameserver 192.168.17.1

nameserver 172.18.0.1
# -n 加入行号,包括空行
[centos7@root dir]# cat -n /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science
     3  
     4  nameserver 192.168.17.1
     5  
     6  nameserver 172.18.0.1
# -b非空行前加入行号
[centos7@root dir]# cat -b /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science

     3  nameserver 192.168.17.1

     4  nameserver 172.18.0.1

tac

Concatenate and print files #倒叙显示文件内容,即从文件尾页到首页的顺序显示内容
* tac

# 如正常顺序显示/etc/resolv.conf 如下:
[centos7@root dir]# cat /etc/resolv.conf 
# Generated by NetworkManager
search magedu.com zhubiao.science

nameserver 192.168.17.1

nameserver 172.18.0.1
#使用tac 将倒序输出文件内容,如下:
[centos7@root dir]# tac /etc/resolv.conf 
nameserver 172.18.0.1

nameserver 192.168.17.1

search magedu.com zhubiao.science
# Generated by NetworkManager

nl

读取文件内容后输出左侧加入行号的内容
* nl [options] [files]
* -b #与选项a, t一起使用,控制行号的输出
a #-b a 所有行都有行号
t #-b t 空行不输出行号
n #-b n 所有行均不输出行号
* -n #与ln, rn, rz一起使用控制行号位置及补0的输出
ln #-n ln 行号在所在字段的左侧
rn #-n rn 行号在所在字段的右侧
rz #-n rz 行号在所在字段的右侧,左侧补0

[centos7@root dir]# nl /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science

     3  nameserver 192.168.17.1

     4  nameserver 172.18.0.1
[centos7@root dir]# nl -b a /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science
     3  
     4  nameserver 192.168.17.1
     5  
     6  nameserver 172.18.0.1
[centos7@root dir]# nl -b t /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science

     3  nameserver 192.168.17.1

     4  nameserver 172.18.0.1
[centos7@root dir]# nl -b n /etc/resolv.conf 
       # Generated by NetworkManager
       search magedu.com zhubiao.science

       nameserver 192.168.17.1

       nameserver 172.18.0.1
[centos7@root dir]# nl -n ln /etc/resolv.conf 
1       # Generated by NetworkManager
2       search magedu.com zhubiao.science

3       nameserver 192.168.17.1

4       nameserver 172.18.0.1
[centos7@root dir]# nl -n rn /etc/resolv.conf 
     1  # Generated by NetworkManager
     2  search magedu.com zhubiao.science

     3  nameserver 192.168.17.1

     4  nameserver 172.18.0.1
[centos7@root dir]# nl -n rz /etc/resolv.conf 
000001  # Generated by NetworkManager
000002  search magedu.com zhubiao.science

000003  nameserver 192.168.17.1

000004  nameserver 172.18.0.1
[centos7@root dir]# nl -n rz -w2 /etc/resolv.conf 
01  # Generated by NetworkManager
02  search magedu.com zhubiao.science

03  nameserver 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值