本文只真对于自己学习中留下记录,以便于以后查看。
1、linux 三大分支
debian 系列 社区版系统有 unbuntu、kali
redhat 红帽一类 社区版系统有 centos fedroa
Slackware 很少在企业使用
原生系统你可以使用,但是服务收费,提供技术支持;社区版系统,你可以使用,不收取服务费,但是技术支持必须自己解决。
2、创建用户名
先查看当前系统版本
[11:47:02 root@centos7 ~]#cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
创建用户名并能登录
[11:53:40 root@centos7 ~]#id lcg
uid=10019(lcg) gid=10022(lcg) groups=10022(lcg)
[11:53:44 root@centos7 ~]#su - lcg
[11:54:31 root@centos7 ~]#usermod -s /bin/bash lcg
[11:54:41 root@centos7 ~]#su - lcg
Last login: Mon Aug 10 11:54:08 CST 2020 on pts/0
[11:54:44 lcg@centos7 ~]$
3、配置环境变量
[12:37:59 lcg@centos7 ~]$vim /etc/profile.d/env.sh
HISTTIMEFORMAT="%F %T "
[12:39:27 lcg@centos7 ~]$history
1 2020-08-10 12:35:18 cat /etc/passwd
2 2020-08-10 12:35:26 echo shell
3 2020-08-10 12:35:29 echo $shell
4 2020-08-10 12:35:35 echo $SHELL
5 2020-08-10 12:37:54 vim /etc/default/useradd
6 2020-08-10 12:38:44 vim /etc/profile.d/env.sh
7 2020-08-10 12:39:48 history
4、linux哲学思想
一切皆文件(包括硬件)
小型,单一用途的程序
链接程序,共同完成复杂的任务
避免令人困惑的用户界面
配置数据存储在文本中
5、常用命令格式
echo
[12:41:34 lcg@centos7 ~]$type echo
echo is a shell builtin
[12:41:39 lcg@centos7 ~]$help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Display the ARGs on the standard output followed by a newline.
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash escapes
`echo' interprets the following backslash-escaped characters:
\a alert (bell)
\b backspace
\c suppress further output
\e escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\0nnn the character whose ASCII code is NNN (octal). NNN can be
0 to 3 octal digits
\xHH the eight-bit character whose value is HH (hexadecimal). HH
can be one or two hex digits
Exit Status:
Returns success unless a write error occurs.
[12:41:47 lcg@centos7 ~]$echo $USER
lcg
[12:42:22 lcg@centos7 ~]$echo 'jiayou'
jiayou
[12:42:30 lcg@centos7 ~]$echo '$USER'
$USER
[12:42:38 lcg@centos7 ~]$echo "who am i"
who am i
[12:42:51 lcg@centos7 ~]$echo "who am i
"
root pts/0 2020-08-10 11:37 (192.168.44.1)
screen
[12:45:43 lcg@centos7 ~]$type screen
screen is /bin/screen
[12:45:52 lcg@centos7 ~]$ screen -h
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
-4 Resolve hostnames only to IPv4 addresses.
-6 Resolve hostnames only to IPv6 addresses.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-ls [match] or
-list Do nothing, just list our SockDir [on possible matches].
-L Turn on output logging.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-Q Commands will send the response to the stdout of the querying process.
-r [session] Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF-8 encoding.
-v Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x Attach to a not detached screen. (Multi display mode).
-X Execute
[12:47:41 lcg@centos7 ~]$screen -U
[screen is terminating]
[12:47:50 lcg@centos7 ~]$screen -ls
No Sockets found in /var/run/screen/S-lcg.
date
[12:48:33 lcg@centos7 ~]$type date
date is hashed (/bin/date)
[12:48:41 lcg@centos7 ~]$date --help
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
Mandatory arguments to long options are mandatory for short options too.
-d, --date=STRING display time described by STRING, not 'now'
-f, --file=DATEFILE like --date once for each line of DATEFILE
-I[TIMESPEC], --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.
TIMESPEC='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns' for date
and time to the indicated precision.
-r, --reference=FILE display the last modification time of FILE
-R, --rfc-2822 output date and time in RFC 2822 format.
Example: Mon, 07 Aug 2006 12:34:56 -0600
--rfc-3339=TIMESPEC output date and time in RFC 3339 format.
TIMESPEC='date', 'seconds', or 'ns' for
date and time to the indicated precision.
Date and time components are separated by
a single space: 2006-08-07 12:34:56-06:00
-s, --set=STRING set time described by STRING
-u, --utc, --universal print or set Coordinated Universal Time (UTC)
--help display this help and exit
--version output version information and exit
FORMAT controls the output. Interpreted sequences are:
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 20)
%d day of month (e.g., 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric time zone (e.g., -0400)
%:z +hh:mm numeric time zone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
By default, date pads numeric fields with zeroes.
The following optional flags may follow '%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros
^ use upper case if possible
#use opposite case if possible
After any flags comes an optional field width, as a decimal number;
then an optional modifier, which is either
E to use the locale's alternate representations if available, or
O to use the locale's alternate numeric symbols if available.
Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Show the time on the west coast of the US (use tzselect(1) to find TZ)
$ TZ='America/Los_Angeles' date
Show the local time for 9AM next Friday on the west coast of the US
$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'
GNU coreutils online help:
For complete documentation, run: info coreutils 'date invocation'
[12:50:53 lcg@centos7 ~]$date +%F-%T
2020-08-10-12:50:57
[12:51:24 lcg@centos7 ~]$type ifconfig
ifconfig is hashed (/usr/sbin/ifconfig)
[12:51:32 lcg@centos7 ~]$ifconfig --help
Usage:
ifconfig [-a] [-v] [-s]
[add [/
[del [/
[[-]broadcast []] [[-]pointopoint []]
[netmask ] [dstaddr ] [tunnel ]
[outfill
[hw
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start
[txqueuelen
[[-]dynamic]
[up|down] ...
[12:55:14 root@centos7 ~]#ifconfig ens32
ens32: flags=4163
inet 192.168.44.203 netmask 255.255.255.0 broadcast 192.168.44.255
inet6 fe80::20c:29ff:fe3e:6de6 prefixlen 64 scopeid 0x20
ether 00:0c:29:3e:6d:e6 txqueuelen 1000 (Ethernet)
RX packets 16258 bytes 18077664 (17.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6486 bytes 596763 (582.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[12:55:28 root@centos7 ~]#ifconfig -s ens32
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens32 1500 16277 0 0 0 6499 0 0 0 BMRU
export
[12:55:54 root@centos7 ~]#type export
export is a shell builtin
[12:57:44 root@centos7 ~]#export -h
-bash: export: -h: invalid option
export: usage: export [-fn] [name[=value] ...] or export -p
[12:57:52 root@centos7 ~]#export -p
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/root"
declare -x HOSTNAME="centos7"