Linux 基础

安装系统

光盘安装:略过;

U盘安装:使用usbwriter将下载的IOS刻录到U盘中,然后安装(略过);

网络安装:使用kickstart软件,重点在于写好一个ks.cfg的一个应答文件(略过);

忘记密码的解决办法

https://www.cnblogs.com/wangzengyi/p/12492108.html

关机和注销

shutdown -h now 立刻关机
shutdown -r now 立刻重启
shutdown -h +1  1分钟后关机(重启同样用法)
shutdown -h 11:00 11点钟关机(重启同样用法)
shutdown -c 取消关机
shutdown -k 只发送关机告警不是真关机;
logout 退出当前用户,注销用户(ctrl+d)
exit  退出当前用户,注销用户(ctrl+d)

光标控制命令

ctrl+a 光标回到首行;
ctrl+e 光标回到行尾;
ctrl+k  剪切或删除 光标到行尾的字符;
ctrl+u  剪切或删除 光标到行首的字符;
ctrl+w 剪切或删除 光标前的一个单词;
ctrl+y  粘贴ctrl+k ctrl+u ctrl+w剪切的文本;
ctrl+c  中断正在执行的任务或者删除本行;
crtl+d 相当于exit #复制和粘贴命令根据操作系统不同命令也不同,具体使用前先通过鼠标操作复制粘贴确认正确的快捷键以后再使用,防止误操作;

帮助命令

man 命令
命令 --help
help 系统命令
搜索命令引擎使用顺序:www.google.com--->www.bing.com--->www.baidu.com

显示日期时间的命令

显示日期时间的命令

[root@client ~]# date
2020年 02月 28日 星期五 01:54:26 CST
[root@client ~]# date +%Y-%m-%d-%H:%M:%S
2020-02-28-01:54:52

显示日历

[root@client ~]# cal   #不加参数显示当前日期的日历
      二月 2020
日 一 二 三 四 五 六
                   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

[root@client ~]# cal 01 2020   #加上月份和年份
      一月 2020
日 一 二 三 四 五 六
          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

[root@client ~]# cal 2019  # 加上年份
                               2019

        一月                   二月                   三月
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
……(以下内容省略)……

手动修改日期时间的命令

[root@client ~]# date -R    #查看当前时区
Fri, 28 Feb 2020 02:00:47 +0800

[root@client ~]# tzselect   #修改当前时区

[root@client ~]# ls -l /etc/localtime   #时区的存储文件位置
lrwxrwxrwx. 1 root root 35 3月  28 2019 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

[root@client ~]# date -s 03/01/2020   #手动设置日期
2020年 03月 01日 星期日 00:00:00 CST
[root@client ~]# date -s 10:00:00       #手动设置时间
2020年 03月 01日 星期日 10:00:00 CST

[root@client ~]# hwclock -w       #将当前时间和日期写入blos,防止重启后丢失。
[root@client ~]# hwclock -r   #查看当前硬件时间
2020年03月01日 星期日 10时03分15秒  -0.454916

自动同步时间

#1. 自动同步时间的前提是找到NTP服务器,如下为NTP服务器
#中国国家授时中心:210.72.145.44   ----暂时无法使用
#NTP服务器(上海) :ntp.api.bz
#中国ntp服务器:cn.pool.ntp.org
#pool.ntp.org

#2. 时间同步工具
#rdate -s
#ntpdate -u(使用-u参数会返回误差,也可以使用-s)

#3. 自动同步时间举例:
[root@client ~]# tzselect  #配置正确时区
[root@client ~]# /usr/sbin/ntpdate -u cn.pool.ntp.org  #同步时间
[root@client ~]# hwclock -w   #将时间写入blos

#4. 将以上自动同步时间加入开机启动校验
vim /etc/rc.d/rc.local   
/usr/sbin/ntpdate -u cn.pool.ntp.org> /dev/null 2>&1; /sbin/hwclock -w

#5. 将以上自动同步时间写入定时任务执行
vim /etc/crontab  或者 crontab -e
00 09 * * * root /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1; /sbin/hwclock -w 

计算器

[root@client ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+2        #输入1+2
3          #得出结果
3*3/8+(1+3)
5
quit        #退出计算器的命令
[root@client ~]#

修改主机名

[root@client ~]# hostname study.linux.com    #修改主机名立即生效
[root@client ~]# vim /etc/hostname  #永久保存,或者编辑vim /etc/sysconfig/network
[root@client ~]# vim /etc/hosts #增加新的主机名和127.0.0.1的解析
[root@client ~]# hostname  #查看主机名
study.linux.com
[root@client ~]# ping study.linux.com  #检查效果,修改成功
PING client.immomo.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.030 ms
^C
--- client.immomo.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.017/0.023/0.030/0.008 ms
[root@client ~]#   #这里的提示符是需要注销后重新登录才能改变成新主机名的

查看内存的特殊指令

sudo dmidecode|grep -P -A5 "Memory Device" |grep Size  #查看内存槽数、哪个槽位插了内存,大小是多少
sudo dmidecode -t memory |grep "Maximum Capacity"  #查看最大支持内存数
sudo dmidecode|grep -A16 "Memory Device"|grep 'Speed'  #查看内存速率 

查看CPU的特殊指令

物理CPU个数:        cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l
        每个CPU物理核数:    cat /proc/cpuinfo |grep "cpu cores"|uniq
        每个CPU逻辑核数:    cat /proc/cpuinfo |grep "siblings"|uniq
        总CPU逻辑核数:        cat /proc/cpuinfo |grep -c "processor"
        CPU配置信息:frank@ubuntu:~/test/python$ cat /proc/cpuinfo
    processor       : 0                                               #系统中逻辑处理核的编号
    vendor_id       : GenuineIntel                                   #CPU制造商
    cpu family      : 6                                               #CPU产品系列代号
    model           : 79                                           #CPU属于其系列中的哪一代的代号
    model name      : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz        #CPU属于的名字及其编号、标称主频
    stepping        : 1                                               #CPU属于制作更新版本
    microcode       : 0xb00001f
    cpu MHz         : 2199.900                                       #CPU的实际使用主频
    cache size      : 25600 KB                                       #CPU二级缓存大小
    physical id     : 0                                               #单个CPU的标号
    siblings        : 20                                           #一个物理CPU中的逻辑核数
    core id         : 0                                               #当前物理核在其所处CPU中的编号,这个编号不一定连续
    cpu cores       : 10                                           #一个物理CPU中的物理核数
    apicid          : 0                                        #用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续

查看版本

cat /proc/version
cat /etc/redhat-release
uname -a

查看Linux系统有哪些硬件

[root@study log]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB
00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)
[root@study log]# lspci -v
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
    Flags: fast devsel

00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
    Flags: bus master, medium devsel, latency 0

00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01) (prog-if 8a [ISA Compatibility mode controller, supports both channels switched to PCI native mode, supports bus mastering])
    Flags: bus master, fast devsel, latency 64
    [virtual] Memory at 000001f0 (32-bit, non-prefetchable) [size=8]
    [virtual] Memory at 000003f0 (type 3, non-prefetchable)
    [virtual] Memory at 00000170 (32-bit, non-prefetchable) [size=8]
    [virtual] Memory at 00000370 (type 3, non-prefetchable)
    I/O ports at d000 [size=16]
    Kernel driver in use: ata_piix
    Kernel modules: ata_piix, pata_acpi, ata_generic

00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter (prog-if 00 [VGA controller])
    Flags: fast devsel, IRQ 10
    Memory at e0000000 (32-bit, prefetchable) [size=16M]
    Expansion ROM at <unassigned> [disabled]

00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
    Subsystem: Intel Corporation PRO/1000 MT Desktop Adapter
    Flags: bus master, 66MHz, medium devsel, latency 64, IRQ 19
    Memory at f0000000 (32-bit, non-prefetchable) [size=128K]
    I/O ports at d010 [size=8]
    Capabilities: [dc] Power Management version 2
    Capabilities: [e4] PCI-X non-bridge device
    Kernel driver in use: e1000
    Kernel modules: e1000

00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
    Flags: fast devsel, IRQ 11
    I/O ports at d020 [size=32]
    Memory at f0400000 (32-bit, non-prefetchable) [size=4M]
    Memory at f0800000 (32-bit, prefetchable) [size=16K]

00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
    Subsystem: Dell Device 0177
    Flags: bus master, medium devsel, latency 64, IRQ 21
    I/O ports at d100 [size=256]
    I/O ports at d200 [size=64]
    Kernel driver in use: snd_intel8x0
    Kernel modules: snd_intel8x0

00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB (prog-if 10 [OHCI])
    Flags: bus master, fast devsel, latency 64, IRQ 22
    Memory at f0804000 (32-bit, non-prefetchable) [size=4K]
    Kernel driver in use: ohci-pci

00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
    Flags: medium devsel, IRQ 9
    Kernel driver in use: piix4_smbus
    Kernel modules: i2c_piix4

00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02) (prog-if 01 [AHCI 1.0])
    Flags: bus master, fast devsel, latency 64, IRQ 21
    I/O ports at d240 [size=8]
    I/O ports at d248 [size=4]
    I/O ports at d250 [size=8]
    I/O ports at d258 [size=4]
    I/O ports at d260 [size=16]
    Memory at f0806000 (32-bit, non-prefetchable) [size=8K]
    Capabilities: [70] Power Management version 3
    Capabilities: [a8] SATA HBA v1.0
    Kernel driver in use: ahci
    Kernel modules: ahci

[root@study log]#
lspci

修改语系

1. 显示目前所支持的语系

[root@test ~]# echo $LANG

2. 修改语系成为英文语系

字体集目录:"/etc/sysconfig/i18n",编辑该文件,将字体集更改为“zh_CN.UTF-8”

马上生效的方法是:LANG='zh_CN.UTF-8' 

Linux X_window与文本模式的切换

用x_window启动的情况下的切换方法:

  • [Ctrl] + [Alt] + [F1] ~ [F6]  :文字接口登陆 tty1 ~ tty6 终端机; 
  • [Ctrl] + [Alt] + [F7]   :图形接口壁纸

用terminal启动情况下切换方法:

[root@test ~]# startx 
前提条件是:
  • 你的tty7并没有其他的窗口软件正在运行(tty7必须是空出来的); 
  • 你必须要已经安装了X Window system,并且X server是能够顺利启动的; 
  • 你最好要有窗口管理员,例如GNOME/KDE或者是阳春的TWM等; 
  • 启动X所必须要的服务,例如字型服务器(X Font Server, xfs)必须要先启动。

CentOS 7 修改启动级别

https://www.cnblogs.com/wangzengyi/p/12434572.html

linux和Windows的相互传递文件

1. Windows主机安装CRT,利用CRT ssh到linux主机;

2. linux主机安装lrzsz软件包

3. Windows上传文件到linux 使用rz---然后输入路径;linux下载文件到Windows使用sz 路径;

备注:不推荐在Windows上写文件上传到linux;

virtualbox  linux虚拟机修改mac地址

https://www.cnblogs.com/wangzengyi/p/12553991.html

查看系统SN信息和其他硬件信息

[root@www ~]# dmidecode -t 1
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: innotek GmbH
Product Name: VirtualBox
Version: 1.2
Serial Number: 0
UUID: 439b3674-df3f-4e8e-8dff-d40814bc02ae
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Virtual Machine

原文地址:https://www.cnblogs.com/wangzengyi/p/12376647.html