一、Linux系统结构
1.Linux是一个倒树形结构,最大的目录名称叫根目录“/”。
2.Linux系统中的二级目录
/bin | 二进制可执行文件,系统常规命令 |
/boot | 启动目录,存放系统自动启动文件,内核,初始化程序 |
/dev | 系统设备管理文件 |
/etc | 大多数系统配置文件存放路径 |
/home | 普通用户家目录 |
/lib | 函数库 |
/lib64 | 64位函数库 |
/media | 临时挂载点 |
/mnt | 临时挂载点 |
/run | 自动临时设备挂载点 |
/opt | 第三方软件安装路径 |
/proc | 系统硬件信息和系统进程信息 |
/root | 超级用户家目录 |
/sbin | 系统管理命令,通常只有root可以执行 |
/srv | 系统数据目录 |
/var | 系统数据目录 |
/sys | 内核相关数据 |
/tmp | 临时文件产生目录 |
/usr | 用户相关信息数据 |
二、Linux系统中目录与文件的相关基础操作
1.文件建立
touch filename
注意:
touch不但可以建立文件也可以修改文件的时间戳
时间戳分为:
atime:文件内容被访问的时间标识
mtime:文件内容被修改的时间标识
ctime:文件属性或文件内容被修改的时间标识
修改文件时间戳(时间标识):touch -t
2.目录建立
mkdir directory
mkdir -p dir1/dir2/dir3 ## -p 建立递归目录,上层目录不存在自动建立
3.文件删除
rm file
rm -f file ## -f=force 表示强制删除不提示
4.目录删除
rm -r directory ## -r标示递归删除,也就是删除目录本身和里面的所有内容
rm -r -f dir ## 删除目录不提示
rm -rf dir = rm -fr dir ##在命令参数使用中,-a -b -c =-abc =-bac 。
5.编辑文件
(1)gedit
gedit file ##必须有图形
(2)vim
①vim file -->按[i]进入insert模式 -->书写内容 -->按[esc]退出insert模式 -->:wq退出保存
②vim异常退出
当vim异常退出时会生成.file.swp文件。
当再次打开此文件时会出现以下情况:
[O]pen Read-Only | 只读打开 |
---|---|
(E)dit anyway | 继续编辑 |
( R)ecover | 恢复数据 |
(D)elete it | 删除swap文件 |
(Q)uit | 退出 |
(A)bort | 退出 |
无论按[O] (E) ( R) (Q) (A) 任何一个都不会删除.swp文件,那么再次打开hello文件是还会出现以上界面,直到按(D) .swp文件被删除,vim恢复正常工作。
6.文件的复制
cp 源文件 目的地文件
cp -r 源文目录 目的地目录
cp 源文件1 源文件2 目的地目录 ##目的地目录必须存在
cp -r 源目录1 源目录2 目的地目录 ##目的地目录必须存在
7.文件移动
mv 源文件 目的地文件 ##重命名
mv 源目录 目的地目录
mv 源目录 . ## . 代表当前目录
注意:
相同磁盘的文件移动只是一个重明名过程。
不同磁盘的文件移动是复制删除过程。
8.文件查看
cat file ##查看文件的全部内容
cat -b file ## -b 显示内容与行号
less file ##分页浏览
↑ ↓ | 逐行移动 |
---|---|
pageup | pagedown |
/关键字 | 高亮显示关键字,n向下匹配,N向上匹配 |
v | 进入vim模式 在vim模式中按:wq 退回到less模式 |
q | 退出 |
head file ##显示文件前10行
head -n 5 file ##显示文件前5行
tail file ##显示文件后10行
tail -n 5 file ##显示文件后5行
tail -f file ##监控文件后10行内容的变化
9.文件的寻址
文件的地址分为:
(1 )相对路径:
相对与当前系统所在目录的一个文件名称的简写
此名称省略了系统当前所在目录的名称
此名称不以“/”开头
此名称在命令执行时会自动在操作对象前加入“PWD”所显示的值(pwd显示当前目录)
(2) 绝对路径:
绝对路径是文件在系统的真实位置;
此命令是以“/”开头的;
此命令在执行时系统不会考虑现在所在位置的信息。
例:/root//desktop/file
/desktop/file
注意:
①当操作对象是 对象1 空格 对象2 时,这两个对象之间没有任何关系。
例: fi le ##这是 2 个对象,fi 和 le
file ##这是 1 个对象,file
② 亲 ##动作是被系统执行的,不能作为名称出现
“亲” ##用引号的作用是把动作变成名称字符,这种方法叫引用
10.自动补齐
–TAB键
系统中的 TAB键可以实现命令的自动补齐,
可以补齐系统中存在的命令,文件名称,和部分命令的参数,
当一次 TAB补齐不了时,代表以此关键字开头的内容不唯一,
可以按两次 TAB来列出所有以此关键字开头的内容。
11.关于路径的命令
(1)显示路径 :pwd
(2)切换路径
cd 目录名称 ##进入到指定目录中
cd - ##当前目录和当前目录之前所在目录之间的切换
cd ~ ##进入当前用户家目录
cd ~username ##进入user家目录
cd … ##进入当前目录的上级目录
cd~+ ##当前目录
cd ~ - ##进入当前目录之前所在的目录
[kiosk@foundation60 ~]$ cd Desktop/
[kiosk@foundation60 Desktop]$ cd test
[kiosk@foundation60 test]$ cd ~-
[kiosk@foundation60 Desktop]$ cd -
/home/kiosk/Desktop/test
[kiosk@foundation60 test]$ cd ~-
[kiosk@foundation60 Desktop]$
(3)查看: ls
ls -l file ##文件属性和权限
ls dir ##目录中包含的内容
ls -d dir ##目录本身
ls -ld dir ##查看目录的权限
ls -a dir ##所有文件包含隐藏的
ls -S dir ##查看并且按照大小排序
(4)文件大小统计:wc
wc -l filename ##行数
wc -w filename ##单词数
wc -m filename ##字符数
wc -c filename ##字节数
12.系统中历史的调用
history ##查看历史输入命令,默认1000条
echo $HISTSIZE ## 显示容量
history -c ##清空当前环境中的历史
! 数字 ##调用此行历史,比如"!21"时执行历史中第21条命令
!字母 ##执行以 字母 关键字开头的最近一条历史命令
ctrl + r + 关键字 ##调用历史中最近一条含有此关键字的历史
13.在系统中获得帮助
(1)查看命令用途
whatis 命令 ##查看命令的用途
(2)查看命令的用法
命令 --help ##查看命令的基本用法,适用于多数命令
[ ] | 表示选项可以加也可以不加 |
---|---|
… | 表示选项加入的个数任意 |
< > | 表示选项是必须要加入的 |
Userage: | 表示命令用法 |
Opetions: | 对参数的作用做说明 |
例:cal 用法
(3)man查看命令或文件的说明手册
man 命令 ## 查看命令使用方法
man 5 文件名 ##查看文件使用方法
man的级别:
1 | 命令 |
---|---|
2 | 系统调用接口 |
3 | 函数库调用接口 |
4 | 特殊设备文件 |
5 | 系统配置文件 |
6 | 游戏规则说明 |
7 | 包说明 |
8 | 系统管理命令 |
9 | 内核调用规则 |
man的基本用法
↑ ↓ | 逐行查看 |
---|---|
pgup pgdn | 分页查看 |
/关键字 | 高亮显示关键字,n向下匹配,N上向匹配 |
:q | 退出 |
man -k 字符串 | 下看当前字符串在系统中拥有的man的级别 |
/usr/share/doc ##系统中所有安装过的软件的帮助文档
例:date用法
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.
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
--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 (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 alter-
nate representations if available, or O to use the locale's alternate
numeric symbols if available.
14.系统中的通用配置符号
* | 匹配0到任意字符 |
---|---|
? | 匹配单个字符 |
[[:alpha:]] | 单个字母 |
[[:lower:]] | 单个小写字母 |
[[:upper:]] | 单个大写字母 |
[[:digit:]] | 单个数字 |
[[:punct:]] | 单个符号 |
[[:space:]] | 单个空格 |
[[:alnum:]] | 单个数字或字母 |
[1-9] | 1位,这位是1-9的任意数字 |
[!3-5] | 1位,不是3-5的数字 |
[^3-5] | 1位,不是3-5的数字 |
[a-z] | 1位,a-z的任意字母 |
{1…3} | 3个,1 2 3 |
{1,5,6} | 3个1,5,6这三个数 |