linux basis (b)
- View System Information
- View release: cat / etc / centos-release or lsb_release -a
~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
- Modified version: nano (nano is a character-based interface to edit a text file)
~]# nano /etc/centos-release
CentOS Linux release 888 (Core)
ctro+o保存,ctro+x退出
~]# cat /etc/centos-release#为了生产安全,可以修改版本号
CentOS Linux release 888 (Core)
- Viewing the kernel version uname -r
~]# uname -r
3.10.0-957.el7.x86_64
- View cpu information
~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 8
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Stepping: 10
CPU MHz: 2207.999
CPU max MHz: 0.0000
CPU min MHz: 0.0000
BogoMIPS: 4415.99
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 9216K
NUMA node0 CPU(s): 0-7
~]# cat /proc/cpuinfo #<=该命令可以查看系统CPU有多少个核,频率,特性等等
- View Memory:
~]# cat /proc/meminfo
~]# free
~]# top |grep %free
~]# ps aux –sort -rss
~]# vmstat -s
- View Subdivision
~]# lsblk # -f可以列出分区类型
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 512M 0 part /boot
├─sda2 8:2 0 1G 0 part
└─sda3 8:3 0 48.5G 0 part /
~]# df
~]# fdisk -l #列出分区表
View card information:
~]# dmesg |grep eth
- Setting automatic login user mode (install a graphical interface).
- With nano (nano is a character-based interface to edit a text file) to open the file path nano /etc/gdm/custom.conf enter modification interface, increasing the passage below and save it
AutomaticLoginEnable=true
AutomaticLogin=root
- Check the system ID account.
0 for the root account, in centos6.10 in general account for the later 500, centos7.5 1000 in general account for the future. For example id - u user to view the current system accounts, id -u lv lv to view the account ID number.
centos 6.10:
~] # id -u tao
501
~]# id -u root
0
- CentOS 7.5:
~]# id -u tao
1001
~]# id -u root
0
Press ctrl + alt + f2-f6 to open the terminal in turn five, according to tty can be seen in the terminal login. You can also view information about all of it land terminals with who. Display a pseudo terminal is a pts of the remote landing, tty native landing (VMware console). whoami to display the currently logged in user, who am i to display detailed user login and at that terminal. w display more detailed login information. Chvt1-6 can also be used to switch the terminal.
~]# who root tty1 2019-08-16 16:33 root pts/0 2019-08-16 16:51 (192.168.100.1) #xshell连接上的 ~]# w 17:56:43 up 1:23, 2 users, load average: 0.00, 0.01, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 16:33 32:51 0.38s 0.38s -bash root pts/0 192.168.100.1 16:51 3.00s 0.10s 0.00s w ~]# whoami root ~]# lastb btmp begins Fri Aug 16 17:42:01 2019
init3 interface to switch to the character, init5 to switch interface. startx can also switch to a graphical interface, but not the mode switching, just open a program only.
Check the kind of shell running with echo $ SHELL. View system which supports several shell, cat / etc / shells.
CentOS7.5:
[root@centos7 ~]# echo $SHELL
/bin/bash
[root@centos7 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
CentOS6.10:
~]# echo $SHELL
/bin/bash
~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
- Change the command prompt. (# For the administrator login, $ for the general user login) displays a prompt format, echo $ PS1 prompt modified format, PS1 = "[\ e [1; 34m] [\ u @ \ h \ W] \ $ [ \ e [0m] "
~]# echo $PS1
\[\e[1;34m\][\u@\h \W]\$ \[\e[0m\]
~]# cat /etc/profile.d/zhu.sh
PS1="\[\e[1;34m\][\u@\h \W]\\$ \[\e[0m\]"
- To permanently save the file must be stored, after the nano /etc/profile.d/zhu.sh into the file in the PS1 parameter changes can be saved.
\e \033
\u当前用户
\h主机名简称
\H 主机名
\w 当前工作目录
\W 当前工作目录基名
\t 24小时时间格式
\T 12小时时间格式
\! 命令历史数
\# 开机后命令历史数
- After entering the command Enter: Submit type the command shell program finds an executable program or code corresponding to the analysis by submitting it to the kernel to allocate resources to run it up
Type the command:
Internal command: the shell comes, but also by providing some form of the command, use the help you can view a list of internal commands
help 内部命令列表 enable cmd 启用内部命令 enable –n cmd 禁用内部命令 enable –n 查看所有禁用的内部命令
External commands: a corresponding executable file in the file system path
查看路径:which -a |--skip-alias ; whereis
By type + cmd to see is an internal command or external command
~]# type cd cd is a shell builtin ~]# type ls ls is aliased to `ls --color=auto' ~]# type who who is /usr/bin/who
Or -a command with which you can choose to view all the way to see this figure who commands external command, enable the integration of internal shell commands.
~]# type enable
enable is a shell builtin
~]# enable |wc -l
61
~]# enable -n echo #enable命令用于启用和关闭shell内建echo指令,关闭内建命令echo
~]# enable |wc -l
60
~]# enable -a|wc -l
61
~]# type echo
echo is /usr/bin/echo
~]# enable echo # 启用内部命令echo
~]# type echo
echo is a shell builtin
- Use the help command can see in front of echo added a *
~]# help|grep echo
*echo [-neE] [arg ...] time [-p] pipeline
- You can count the number of rows of built-in commands
~]# enable -a |wc -l
- External command --help This command can get most of the external command cmd help
~]# who --help
- Internal command can help cmd
~]# help enable
- Note: The execution of external commands will be executed in order PASH list of variables, if not the error, but once the external command execution will be put hash in the cache, even if the second path changes, any course will follow the cache the paths of execution.
- hash cache
System Initial hash table is empty, when the external command, default look for that command from the PATH, find the path of this command will be recorded in the hash table, when the command again, the shell is first interpreter Check hash table, there is the execution of, if not, will find the path to pATH. Use the cache hash table can be greatly improved call rate command
- hash common usage:
- hash hash displays cache
- -l display buffer hash hash, may be used as an input
- hash -p path name will command the full path from the path alias name
hash -t name Print name of the cache path
- Clear name cache hash -d name
hash -r clear all caches
~]# hash -p /usr/bin/nano nane
~]# nane
~]# hash -l
builtin hash -p /usr/bin/nano nane
builtin hash -p /usr/bin/nano nane
~] # hash -p /usr/bin/nano nane
~] # hash ^C
~] # hash -t nane
/usr/bin/nano
~] # hash -l
builtin hash -p /usr/bin/nano nane
builtin hash -p /usr/bin/nano nane
~] # hash -d nane
~] # hash -r
~] # hash
hash: hash table empty
- Command aliases
alias command: Displays the current shell process all the available command aliases
Define an alias NAME, which corresponds to Run of VALUE
Alias NAME = 'of VALUE'Alias defined in the command line, valid only for the current shell process
If you want permanent, to be defined in the configuration file
- Current user only: ~ / .bashrc
- Effective for all users: / etc / bashrc
Defining an alias; alias cdnet = 'cd / etc / sysconfig / network-scripts /'
Edit the configuration of the new configuration will not take effect immediately given, it must be saved to a file using the
nano .bashrc
save with. Plus or source file to take effect. .bashrc/
orsource .bashrc
orexec bash
Undo Alias: unalias
unalias [-a] name [name ...]
-a cancel all aliases
~]# cat .bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
alias cdnet=cd /etc/sysconfig/network-scripts
~]# . .bashrc
- If you do not have to use the original command alias command input path can be found, plus '', plus, plus, "" could, for example; \ ls, 'ls', "ls", / bin / ls, command ls can which -alias- skip skip ls display only the alias cancellation path ualias + name aliases
Priority Name Command execution> internal command> external commands
When you use a command to find a time will follow a path behind the PATH, started after the first find, after use into the cache hash, when the second use is not looking but directly to the cache inside to find
Execution of the command (priority) process:
1. determines whether the command aliased, there are: corresponding to the alias command is executed.
2. determine whether it is an internal command
- 3. The external command determines whether
- Has been performed, find the PATH, the path had been cached hash to perform according to the time of the previous execution;
- Not performed, according to the list order echo $ PATH to search execution, if not search on the error;
- Format:
COMMAND [OPTIONS...][ARGUMENTS...]
Options: for a certain function or to enable or disable command
Short options: -c For example: -l, -h
- Long options: - word example: - all, --human-readable
- Parameters: command of the role of the object, such as file name, user name, etc.
- note:
- Whitespace separation between multiple options and multiple parameters and commands
- Cancel and end the command execution: Ctrl + c, Ctrl + d
- A plurality of commands can be used; separate symbol
- A command can be used \ multiple lines
- Time and clock
Linux two clocks
System clock: the work performed by the frequency of the CPU by the Linux kernel
Hardware clock: Motherboard
Related Commands
Display system time and date settings
date +%s
date -d @1509536033
hwclock, clock: hardware clock display
-s, subject to the hardware clock, clock correction system
-w, subject to the system clock, the hardware clock correction
A network time to calibrate system time; ntpdate 17220.0.1 (temporary force)
To boot calibration needs to write the configuration file
centos6:
vim /etc/ntp.conf 增加 server 172.20.0.1 iburst service ntpd start (立即启用服务生效) chkconfig ntpd on (每次开机都启用生效) tzselect 选择时区(centos6)
centos7:
vim /etc/chrony.conf 增加 server 172.20.0.1 iburst systemctl start chronyd (立即启用服务生效) systemctl enable chronyd (每次开机都启用生效) 时区:/etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai timedatectl 设置时区(centos7) sosreport收集系统配置及架构信息并输出诊断文档
Show calendar: cal -y
Setting the system time (only be changed under root)
date 031212122018.30 (2018 03 Yue 12 Ri 12:12:30)
~]# date 031212122018.30
Mon Mar 12 12:12:30 CST 2018
- date -s "mmddHHMMYYSS"
- date -s "str" (str input formats can also keep their format specified in quotation mark)
date -s "-1 day" +% F setup time
- date -d "str" (str own input formats can also keep the format specified in the quotation mark) display time
- date -d "-2 day" +% F show the first two days
date -d "5 day" +% F show time after five days
Displays detailed time date + "% Y-% m-% d% H:% M:% S" date + "% F% T" Both are.
Command switch 10 .linux
poweroff shutdown
halt shutdown
init 0 shutdown
init 6 reboot
reboot reboot
- -f: Force, do not call shutdown
- -p: cut off the power
Shutdown or restart shutdown
shutdown [OPTION]... [TIME][MESSAGE]
- -r:reboot
- -h: halt
- -c :cancel
TIME: None specified, the default is equivalent to +1
now: once, the equivalent +0
+ M: after a relative time notation, a few minutes; +3 e.g.
- hh: mm: absolute time representation indicating the specific time
- shutdown -c cancel shutdown
- shutdown +5 "hbdj" five minutes after the shutdown and prompted messages
Timing shutdown command shutdown -h 12:30