Linux系统结构及文件管理-cd、touch、mkdir、rm、cp、mv、cat、head、tail命令的使用

一、Linux系统结构
Linux是一个倒树型结构,最大的目录名称叫“/” (根目录)

(1)linux系统中的二级目录 

/bin

二进制可执行文件,系统常规命令

/boot

启动目录,存放系统自动启动文件,内核,初始化程序

/dev

系统设备管理文件

/etc

大多数系统配置文件存放路径

/home

普通用户家目录

/lib

函数库

/lib64

64位函数库

/media

临时挂载点

/mnt

临时挂载点

/run 

自动临时设备挂载点

/opt

第三方软件安装路径

/proc

系统硬件信息和系统进程信息

/root

超级用户家目录

/sbin

系统管理命令,通常只有root可以执行

/srv

系统数据目录

/var

系统数据目录

/sys

内核相关数据

/tmp

临时文件产生目录

/usr

用户相关信息数据 

二、文件管理命令
(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退出保存

[root@localhost Desktop]# vim file

②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)文件查看

1. cat    file             ##查看文件的全部内容

     cat    -b    file      ##  -b  显示行号

2. less  file             ##分页浏览

用法
  ↑ | ↓逐行移动
pageup | pagedown逐页移动
/关键字高亮显示关键字,n向下匹配,N向上匹配
v进入vim模式 在vim模式中按:wq 退回到less模式
q退出

3. head    file            ##显示文件前10行

     head  -n  5   file    ##显示文件前5行

 4. 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 ..                       ##进入当前目录的上级目录

当前用户家目录
~username指定用户的家目录
~+当前目录
~-进入当前目录之前所在目录(olddir)
[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  -a  dir     ##所有文件包含隐藏的

ls  -S  dir    ##查看并且按照大小排序

4.文件大小统计:wc

wc   -l     ##行数

wc  -w    ##单词数

wc  -m    ##字符数

wc   -c    ##字节数

(12)系统中历史的调用

history       ##查看历史,默认1000条

echo $HISTSIZE    ## 显示容量

history   -c     ##清空当前环境中的历史

!数字            ##调用此行历史,比如"!21"时执行历史中第21条命令

!字母            ##执行以 字母 关键字开头的最近一条历史,例:“!w”时执行历史中最近以w开头的命令

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用法(用man 查看date用法并显示2天后的日期,格式:如01/01)

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,4,7}3个1,4,7这三个数

例:

[kiosk@foundation60 Desktop]$ rm -fr file[!2-9]   #删除文件除了file2——file9

 

另:Ctrl+c       ##取消命令

       kill -9 PID(进程号)     ##杀死进程

       数据库:高级的Excel

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马克图布s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值