一、X Window与命令行模式切换
X Window:即X windows图形用户接口,提供GUI的软件系统和网络协议。
GNOME和KDE:基于X Window协议的桌面环境。
Linux默认情况下提供了6个终端来让用户登录(终端名为tty1~tty6),切换的方式为ctrl + alt + F[1~6],要切换回X Window可以用ctrl + alt + F7。
~符号:变量,表示用户的主文件夹。如root的主文件夹在/root,则~就代表/root;而用户axb的主文件夹在/home/axb,则~就表示/home/axb
切换到终端后,输入用户名和密码登录,登录后如果要注销就用exit命令。
二、命令行基础命令操作
在命令行登录后,运行的程序是shell,这个程序负责最外层的跟用户通信的工作。
在tty[1-6]中,默认情况下是不支持中文的(可以安装其他包来实现中文),先用
echo $LANG
命令来查看当前的语言,如果要换语言,则用
LANG=language
这条命令,如用英语的话,将language换成en_US。用locale命令可查看到底支持多少种语言。
1. 日期与时间命令
- cal month year:显示year年month月的日历,默认为当月;
- date (+%Y-%m-%d %H:%M:%S):显示时间,括号中的%x 形式可以自定义时间的显示格式。
用bc命令可以进入计算器,然后输入表达式就可以计算了。需要注意的是,bc计算器默认的小数点数为0,即1/3这种小数,它只会取整输出0(像两个int相除),为了输出整数,要在进入bc后,用命令scale=n指定有n位小数,如:
scale=2
1/2
输出:0.50
三、热键
1. Tab键:该键有命令提示与文件补齐功能
- 命令提示:在shell中输入一个字符串s,然后再输入两个Tab,它就会自动输出以s开关的命令(如果有的话);
- 文件提示:用ls命令,后面跟上一个字符串s,再输入两个Tab,则会出现以s开头的文件名。
- ctrl + c:中断当前程序;
- ctrl + d:键盘输入结束,相当于EOF。
我们可以用
man s
格式来查询命令s的用法,以date命令为例,介绍下man,下面是用
man date
命令得到的结果:
DATE(1) User Commands DATE(1)
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
display time described by STRING, not `now'
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-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', `sec‐
onds', 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
--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)
%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
......
......
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 alter‐
nate 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'
DATE STRING
The --date=STRING is a mostly free format human readable date string
such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or
even "next Thursday". A date string may contain items indicating cal‐
endar date, time of day, time zone, day of week, relative time, rela‐
tive date, and numbers. An empty string indicates the beginning of the
day. The date string format is more complex than is easily documented
here but is fully described in the info documentation.
AUTHOR
Written by David MacKenzie.
REPORTING BUGS
Report date bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report date translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Copyright © 2011 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for date is maintained as a Texinfo manual. If
the info and date programs are properly installed at your site, the
command
info coreutils 'date invocation'
should give you access to the complete manual.
GNU coreutils 8.12.197-032bb September 2011 DATE(1)
我们来看,第一行中开关有DATE(1),数字1表示命令的类型:
数字 | 含义 |
1 | 用户在shell环境下可以操作的命令或可执行文件 |
2 | 系统内核可调用的函数与工具 |
3 | 一些常用的函数 |
4 | 设备文件说明 |
5 | 配置文件或是某些文件的格式 |
6 | 游戏 |
7 | 协议 |
8 | 系统管理员可用的命令 |
9 | 跟kernel有关的文件 |
Title | 内容 |
NAME | 命令说明 |
SYNOPSIS | 该命令的执行语法 |
DESCRIPTION | 该命令完整的说明 |
OPTIONS | 针对SYNOPSIS中,列举的所有可用的选项说明 |
COMMANDS | 当该程序在执行时,可以在此程序中执行的命令 |
FILES | 这个程序或数据所使用或参考或连接到的某些文件 |
SEE ALSO | 与这个命令有关的其他说明 |
EXAMPLE | 范例 |
BUGS | 错误报告 |
在man page中,我们可以用空格来翻页,也可以用上下方向键来翻页或换行。如果需要在man page中查找字符串,则可以输入/string,那么就会高亮所有的string了,在查询过程中,可以输入n来查找下一个或用N来查找上一个string。输入q退出man。
四、关机
为了防止关机造成数据丢失,我们可以用who命令查看当前在线的用户,如果只有自己一个用户且数据都保存好了,再用shutdown命令就可以关机了,而reboot命令可以重启。在关机或重启前,系统会启用sync命令将数据同步到磁盘上,当然,为防止意外,我们也可以用sync命令先同步。但需要注意的是,普通用户的sync命令只会同步自己的数据,而root用户同步整个系统的数据。