Linux 基础操作命令

时间:2023-03-10 04:40:41
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分钟后关机(重启同样用法)
shutdown -h : 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日 星期五 :: CST
[root@client ~]# date +%Y-%m-%d-%H:%M:%S
--28-01:54:

显示日历

[root@client ~]# cal   #不加参数显示当前日期的日历
二月
日 一 二 三 四 五 六 [root@client ~]# cal #加上月份和年份
一月
日 一 二 三 四 五 六 [root@client ~]# cal # 加上年份 一月 二月 三月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六 ……(以下内容省略)……

手动修改日期时间的命令

[root@client ~]# date -R    #查看当前时区
Fri, Feb :: + [root@client ~]# tzselect #修改当前时区 [root@client ~]# ls -l /etc/localtime #时区的存储文件位置
lrwxrwxrwx. root root 3月 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai [root@client ~]# date -s // #手动设置日期
2020年 03月 01日 星期日 :: CST
[root@client ~]# date -s :: #手动设置时间
2020年 03月 01日 星期日 :: 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 >&; /sbin/hwclock -w #5. 将以上自动同步时间写入定时任务执行
vim /etc/crontab 或者 crontab -e
* * * root /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null >&; /sbin/hwclock -w

计算器

[root@client ~]# bc
bc 1.06.
Copyright -, , , , , Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
+2 #输入1+2
3 #得出结果
*/+(+) 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) () bytes of data.
bytes from localhost (127.0.0.1): icmp_seq= ttl= time=0.017 ms
bytes from localhost (127.0.0.1): icmp_seq= ttl= time=0.030 ms
^C
--- client.immomo.com ping statistics ---
packets transmitted, received, % 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 : #系统中逻辑处理核的编号
vendor_id : GenuineIntel #CPU制造商
cpu family : #CPU产品系列代号
model : #CPU属于其系列中的哪一代的代号
model name : Intel(R) Xeon(R) CPU E5- v4 @ .20GHz #CPU属于的名字及其编号、标称主频
stepping : #CPU属于制作更新版本
microcode : 0xb00001f
cpu MHz : 2199.900 #CPU的实际使用主频
cache size : KB #CPU二级缓存大小
physical id : #单个CPU的标号
siblings : #一个物理CPU中的逻辑核数
core id : #当前物理核在其所处CPU中的编号,这个编号不一定连续
cpu cores : #一个物理CPU中的物理核数
apicid : #用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续

查看版本

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

查看Linux系统有哪些硬件

[root@study log]# lspci
:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev )
:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev )
:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev )
:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB
:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev )
:0d. SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev )
[root@study log]# lspci -v
:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev )
Flags: fast devsel :01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
Flags: bus master, medium devsel, latency :01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev ) (prog-if 8a [ISA Compatibility mode controller, supports both channels switched to PCI native mode, supports bus mastering])
Flags: bus master, fast devsel, latency
[virtual] Memory at 000001f0 (-bit, non-prefetchable) [size=]
[virtual] Memory at 000003f0 (type , non-prefetchable)
[virtual] Memory at (-bit, non-prefetchable) [size=]
[virtual] Memory at (type , non-prefetchable)
I/O ports at d000 [size=]
Kernel driver in use: ata_piix
Kernel modules: ata_piix, pata_acpi, ata_generic :02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter (prog-if [VGA controller])
Flags: fast devsel, IRQ
Memory at e0000000 (-bit, prefetchable) [size=16M]
Expansion ROM at <unassigned> [disabled] :03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev )
Subsystem: Intel Corporation PRO/ MT Desktop Adapter
Flags: bus master, 66MHz, medium devsel, latency , IRQ
Memory at f0000000 (-bit, non-prefetchable) [size=128K]
I/O ports at d010 [size=]
Capabilities: [dc] Power Management version
Capabilities: [e4] PCI-X non-bridge device
Kernel driver in use: e1000
Kernel modules: e1000 :04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
Flags: fast devsel, IRQ
I/O ports at d020 [size=]
Memory at f0400000 (-bit, non-prefetchable) [size=4M]
Memory at f0800000 (-bit, prefetchable) [size=16K] :05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
Subsystem: Dell Device
Flags: bus master, medium devsel, latency , IRQ
I/O ports at d100 [size=]
I/O ports at d200 [size=]
Kernel driver in use: snd_intel8x0
Kernel modules: snd_intel8x0 :06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB (prog-if [OHCI])
Flags: bus master, fast devsel, latency , IRQ
Memory at f0804000 (-bit, non-prefetchable) [size=4K]
Kernel driver in use: ohci-pci :07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev )
Flags: medium devsel, IRQ
Kernel driver in use: piix4_smbus
Kernel modules: i2c_piix4 :0d. SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev ) (prog-if [AHCI 1.0])
Flags: bus master, fast devsel, latency , IRQ
I/O ports at d240 [size=]
I/O ports at d248 [size=]
I/O ports at d250 [size=]
I/O ports at d258 [size=]
I/O ports at d260 [size=]
Memory at f0806000 (-bit, non-prefetchable) [size=8K]
Capabilities: [] Power Management version
Capabilities: [a8] SATA HBA v1.
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