Linux基础
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux基础相关的知识,希望对你有一定的参考价值。
博客一、第一次写博客,希望大家多多包涵。如有不足,欢迎大佬们多多指点。纪念一下自己的学习经历。
二、Linux基础学习
查看LINUX系统版本
[root@centos7~]#cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
查看运行模式
[root@centos7~]#runlevel
N 5
init 0=poweroff=关机 init 6重启
查看主机名称
[root@centos7~]#hostname
centos7.5.localdomain
exit=logout=CTRL+D 退出
修改主机名为centos7.55.localdomain
[root@centos7sysconfig]#hostnamectl set-hostname centos7.55.localdomain
[root@centos7sysconfig]#hostname
centos7.55.localdomain
查看系统内核版本
[root@centos7sysconfig]#uname -r
3.10.0-862.el7.x86_64
读出的内核信息进行解释
[root@centos7sysconfig]#free -h
total used free shared buff/cache available
Mem: 1.0G 398M 274M 8.7M 359M 434M
Swap: 2.0G 0B 2.0G
[root@centos7sysconfig]#cat /proc/meminfo
MemTotal: 1057372 kB
MemFree: 281416 kB
MemAvailable: 444388 kB
Buffers: 2092 kB
Cached: 282076 kB
SwapCached: 0 kB
Active: 328384 kB
Inactive: 244428 kB
Active(anon): 289568 kB
Inactive(anon): 8032 kB
Active(file): 38816 kB
Inactive(file): 236396 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 288772 kB
Mapped: 91648 kB
Shmem: 8956 kB
Slab: 83664 kB
SReclaimable: 31396 kB
SUnreclaim: 52268 kB
KernelStack: 7136 kB
PageTables: 22740 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 2625832 kB
Committed_AS: 1934240 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 183508 kB
VmallocChunk: 34359310332 kB
HardwareCorrupted: 0 kB
AnonHugePages: 73728 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 96128 kB
DirectMap2M: 1013760 kB
DirectMap1G: 0 kB
查看CPU
[root@centos7sysconfig]#lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 94
Model name: Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
Stepping: 3
CPU MHz: 2303.997
CPU max MHz: 0.0000
CPU min MHz: 0.0000
BogoMIPS: 4607.99
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0,1
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt ibpb ibrs stibp dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp spec_ctrl intel_stibp
查看硬盘情况
[root@centos7sysconfig]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 20G 0 part /data
sr0 11:0 1 8.8G 0 rom
查看用户的UUID
[root@centos7sysconfig]#id -u root
0
[root@centos7sysconfig]#id -u zhang
1000
查看当前用户
[root@centos7sysconfig]#whoami
root
查看登录的主机
[root@centos7sysconfig]#who am i
root pts/0 2019-07-17 10:02 (192.168.13.1)
查看运行的程序
[root@centos7sysconfig]#w
10:36:56 up 34 min, 1 user, load average: 0.04, 0.04, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.13.1 10:02 0.00s 0.22s 0.03s w
查看当前系统使用的所有SHELL
[root@centos7sysconfig]#cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
查看当前使用的SHELL
[root@centos7sysconfig]#echo $SHELL
/bin/bash
修改当前SHELL为csh
[root@centos7sysconfig]#/bin/csh
[root@centos7 sysconfig]# echo $SHELL
/bin/bash
查看当前所在的位置
[root@centos7~]#pwd
/root
修改提示符 1是高亮;5是闪烁;41是背景颜色;33是字体颜色。只是暂时保存,永久保存放在/etc/profile.d/env.sh
[root@centos7 ~]#PS1="\[\e[1;5;41;33m\][\u@\h \W]\\$\[\e[0m\]"
系统自动的以某一个账户登录,
vim /etc/gdm/custom.conf
如图添加相应代码,重新启动就可以实现。
# GDM configuration storage
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=root
[security]
[xdmcp]
[chooser]
gedit 图形化
临时定义别名,如果需要永久生效,需要写在.bashrc(当前用户生效)/etc/bashrc(对所有用户生效)
[root@centos7~]#alias cdnet=‘cd /etc/sysconfig/network-scripts/‘
[root@centos7~]#cdnet
[root@centos7network-scripts]#
[root@centos7~]#vim .bashrc
alias cdnet=‘cd /etc/sysconfig/network-scripts/‘
开机自动连接网络,打开/etc/sysconfig/network-scripts/ifcfg-ens33,把里面的ONBOOT=no,改为yes即可。
[root@centos7~]#cd /etc/sysconfig/network-scripts/
[root@centos7network-scripts]#ls
ifcfg-ens33 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[root@centos7network-scripts]#vim ifcfg-ens33
date常用,
[root@centos7~]#date +‘%F %T‘
2019-07-17 20:53:20
date -d ‘-1 day‘只是显示当天前一天的时间,并不真正的修改当前的时间;建一个以前一天时间为名称的.log文件
建在/data/下,一般定时备份时使用。
[root@centos7~]#touch /data/`date -d ‘-1 day‘ +%F`.log
[root@centos7~]#ls /data/
2019-07-16.log
新添加的硬盘显示不出来,可以访问echo ‘- - -‘> /sys/class/scsi_host/host2/scan
[root@centos7~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 50G 0 part /data
sr0 11:0 1 10G 0 rom /run/media/root/CentOS 7 x86_64
[root@centos7~]#echo ‘- - -‘> /sys/class/scsi_host/host2/scan
[root@centos7~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 50G 0 part /data
sdb 8:16 0 20G 0 disk
sr0 11:0 1 10G 0 rom /run/media/root/CentOS 7 x86_64
主机名示例.北京-亦庄-节点1-IP后2位-公司名称
bj-yz-k8s-node1-100-10.magedu.com
which --skip-alias可以取消别名查看
[root@centos7 dev]#which ls
alias ls=‘ls --color=auto‘
/usr/bin/ls
[root@centos7 dev]#which --skip-alias ls
/usr/bin/ls
obase=2 在bc中,输入其他进制,输出2进制
inase=2 输入2进制,转化为10进制
centos7中mandb 建立whatis数据库,只能是root用户使用
centos6中makewhatis建立whatis数据库
查看所用的语言
[root@centos7 ~]#echo $LANG
en_US.UTF-8
在本机字符终端登录时,除显示原有信息外,再显示当前登录终端号,主机名和当前时间
root@centos7 ~]#vim /etc/issue
\S
time is \t
tty is \l
hostname is \n
Kernel \r on an \m
自动关机,并提示用户
[root@centos7 ~]#shutdown -t 072009552019 ;echo -e ‘\a‘;echo -e ‘\033[43;31;5m‘this computer is halt‘\033[0m‘
Shutdown scheduled for Sat 2019-07-20 09:44:44 CST, use ‘shutdown -c‘ to cancel.
this computer is halt
[root@centos7 ~]#
Broadcast message from root@centos7.6.localdomain (Sat 2019-07-20 09:43:44 CST):
The system is going down for power-off at Sat 2019-07-20 09:44:44 CST!
显示当前时间。+号和后面的中间不能有空格,否则不能执行。
[root@centos7 ~]#date +‘%F %T‘
2019-07-20 09:50:18
显示前天是星期几
[root@centos7 ~]#date -d ‘-2 day‘ +%A
Thursday
设置当前日期为2019-08-07 06:05:10
[root@centos7 ~]#date 080706052019.10
Wed Aug 7 06:05:10 CST 2019
enable 禁用内部命令
enable -n 解除内部命令
sz .bashrc 把Linux文件传到win上
hash -d uname 清楚uname的缓存
[root@centos7 data]#hexdump test.txt
0000000 6261 3163 3332 000a
0000007
[root@centos7 data]#cat test.txt
abc123
screen 的一些用法
建立一个新的会话
[root@centos7 data]#screen -S help
[detached from 8974.help]
查看所有的回话信息
[root@centos7 ~]#screen -ls
There is a screen on:
8974.help (Attached)
1 Socket in /var/run/screen/S-root.
加入第一个终端建立的screen回话
[root@centos7 ~]#screen -x help
以上是关于Linux基础的主要内容,如果未能解决你的问题,请参考以下文章