您的位置:首页 > 运维架构 > Linux

Linux基础入门(三)

2017-03-01 16:21 176 查看
1.查看所用的shell的类型:[root@centos7 ~]# echo $SHELL/bin/bash
2.ss命令:功能:查看系统监听端口(socket)选项: -t:tcp协议 -u:udp协议 -n:解析服务名称 -l:监听端口号示例:[root@centos7 ~]# ss -tnl


3.ifconfig/ip addr list命令:功能:查看服务器IP地址示例:
[root@centos7 ~]# ifconfig[root@centos7 ~]# ip addr list


4.关机命令:CentOS 7:[root@centos7 ~]# systemctl poweroff[root@centos7 ~]# systemctl reboot
适用于所有系统:[root@test1 ~]# poweroff[root@test1 ~]# halt[root@test1 ~]# reboot
5.basename/dirname命令basename - strip directory and suffix from filenamesdirname - strip non-directory suffix from file name
[root@centos7 ~]# basename /etc/sysconfig/network-scripts/ifcfg-eno16777736 ifcfg-eno16777736[root@centos7 ~]# dirname /etc/sysconfig/network-scripts/ifcfg-eno16777736/etc/sysconfig/network-scripts

6.pwd命令:
功能:显示当前所在的工作目录:
pwd: printing working directory
示例:
[root@centos7 ~]# pwd
/root

7.cd命令:
功能:目录切换
cd:change directory
cd [/PATH/TO/SOMEDIR]
cd: 切换回家目录;
注意:bash中, ~表示家目录;
cd ~:切换回自己的家目录
cd ~USERNAME:切换至指定用户的家目录;
cd -:在上一次所在目录与当前目录之间来回切换;



相关的环境变量
$PWD:当前工作目录
$OLDPWD:上一次的工作目录




8.ls: list命令
功能:列出指定目录下的内容
格式:ls [OPTION]... [FILE]...
选项:
-a: 显示所有文件,包括隐藏文件;
[root@centos7 etc]# ls -a
-A:显示除.和..之外的所有文件;
-l: --long, 长格式列表,即显示文件的详细属性信息;
[root@centos7 log]# ls -l
-rw-r--r--. 1 root root 8957 10月 14 19:34 boot.log
-:文件类型,-, d, b, c, l, s, p
-,f:普通文件
d:目录文件
l:符号链接文件
c,b:设备文件
c:字符设备,线性设备。顺序获取
b:块设备,随机设备。随机访问
rw-r--r--
rw-:文件属主的权限;
r--:文件属组的权限;
r--:其它用户(非属主、属组)的权限;
1:数字表示文件被硬链接的次数;
root:文件的属主;
root:文件的属组;
8957:数字表示文件的大小,单位是字节;
10月 14 19:34 :文件最近一次被修改的时间;
boot.log:文件名
-h, --human-readable:对文件大小单位换算;换算后结果可能会非精确值;
-d:查看目录自身而非其内部的文件列表;
[root@centos7 log]# ls -ld /var
drwxr-xr-x. 19 root root 4096 Feb 20 16:42 /var
-r: reverse, 逆序显示;
-R: recursive,递归显示;
-i:显示文件磁盘块数
-t:按修改时间排序

文本文件查看工具:
9.cat/tac命令:
功能:文本文件查看工具
cat:正常显示内容

cat [OPTION]... [FILE]...
选项:

-n:给显示的文本行编号;
-E: 显示行结束符$;
示例:
[root@centos7 ~]# cat anaconda-ks.cfg

tac:逆序显示文件内容
tac [OPTION]... [FILE]...
示例:
[root@centos7 ~]# tac anaconda-ks.cfg

10.file命令:
功能:查看文件内容类型
file [FILE]...
示例:
[root@test1 ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII English text

11.echo命令:

功能:显示返回信息
echo [SHORT-OPTION]... [STRING]...
选项:
-n:不进行换行
[root@test1 ~]# echo -n "hi"
hi[root@test1 ~]#
-e:让转译符生效:
hi[root@test1 ~]# echo -e "hi\too"
hioo
转译符号类型:
\n:换行
\t:制表符
\r:回车符
STRING可以使用引号,单引号和双引号均可用;
单引号:强引用,变量引用不执行替换

[root@test1 ~]# echo '$SHELL'
$SHELL
双引号:弱引用,变量引用会被替换
[root@test1 ~]# echo "$SHELL"
/bin/bash

注意:变量引用的正规符号
${name}

日期相关的命令:
Linux:系统启动时从硬件读取日期和时间信息;读取完成以后,就不再与硬件相关联;
系统时钟
硬件时钟

12.date命令:
功能:显示/设置系统时间
显示日期时间:date [OPTION]... [+FORMAT]
[root@test1 ~]# date
Thu Feb 23 18:04:46 CST 2017
选项:
+%F:显示年月日
[root@test1 ~]# date +%F
2017-02-23
+%T:显示时间
[root@test1 ~]# date +%T
18:07:21
+%Y:显示年份
[root@test1 ~]# date +%Y
2017
+%m:显示月份
[root@test1 ~]# date +%m
02
+%d:显示日
[root@test1 ~]# date +%d
23
+%H:显示小时
[root@test1 ~]# date +%H
18
+%M:显示分钟

[root@test1 ~]# date +%M
08
+%S:显示秒钟
[root@test1 ~]# date +%S
15
+%s:时间戳(已1970年1月1日 00:00:00开始算起到今天时间经过的秒数)
[root@test1 ~]# date +%s
1487844499
+%c:显示(Thu 23 Feb 2017 06:11:17 PM CST)格式
[root@test1 ~]# date +%c
Thu 23 Feb 2017 06:11:17 PM CST

设定日期时间:date [MMDDhhmm[[CC]YY][.ss]]
MM:月
DD:日
hh:时
mm:分
[CC]YY]:年份。可简写(17)、可全写(2017)
.ss:秒
示例:
[root@test1 ~]# date 030916132017.00
Thu Mar 9 16:13:00 CST 2017

13.hwclock=clock命令:
功能:显示/设置硬件时钟
选项:
-s, --hctosys:以硬件为准,把系统调整为与硬件时间相同;
-w, --systohc:以系统为准,把硬件时间调整为与系统时钟相同;
示例:
[root@test1 ~]# hwclock -w

14.cal命令
功能:显示日历
cal:显示当月日历
cal 2017:显示2017整年日历
cal 03 2017:显示2017年3月份日历
示例:

[root@test1 ~]# cal
March 2017
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

课外

alias,which, whereis, who, w

命令类型:
外部命令
shell内嵌命令

type COMMAND:(在基础入门二简单提到过)
内部:builtin
外部:显示为命令文件路径;
注意:命令可以有别名;别名可以与原名相同,此时原名被隐藏;此时如果要运行原命令,则使用\COMMAND

15.alias命令
功能:命令别名
获取所有可用别名的定义:
[root@test1 ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'

定义别名:
alias NAME='COMMAND'
示例:
[root@test1 ~]# alias kk='cd /home/kk'
[root@test1 ~]# kk
[root@test1 kk]#
注意:仅对当前shell进程有效

撤销别名:
unalias NAME
示例:
[root@test1 kk]# unalias kk

16.which命令:
功能:获取指定命令路径
示例:

[root@test1 kk]# which ls
alias ls='ls --color=auto'
/bin/ls
注:如要忽略别名加上次选项(--skip-alias)

17.whereis命令:
功能:收索指定命令执行文件、配置、帮助手册位置
选项:
-b:只显示二进制路径
-m:只显示手册路径
示例:
[root@test1 kk]# whereis yum
yum: /usr/bin/yum /etc/yum.conf /etc/yum /usr/share/man/man8/yum.8.gz

18.who命令:
功能:显示当前系统所有登陆用户
选项:
-b:上一次系统启动的时间
-r:显示系统运行级别
示例:
[root@test1 kk]# who
root tty1 2017-02-21 15:10
root pts/0 2017-02-23 17:48 (192.168.60.10)
[root@test1 kk]# who -b
system boot 2017-02-21 15:09
[root@test1 kk]# who -r
run-level 3 2017-02-21 15:09

19.w命令:
功能:w是加强版who命令,显示的信息不同(可以查看用户执行什么操作)
示例:

[root@test1 kk]# w
16:36:30 up 2 days, 3:27, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 21Feb17 13days 0.36s 0.36s -bash
root pts/0 192.168.60.10 23Feb17 0.00s 0.20s 0.01s w
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux基础命令