写空到linux文件系统,谢烟客---------Linux之文件系统及其命令

文件系统的概述

文件系统的LHS

文件系统相关的命令

时间、开机、关机、登陆用户、终端、命令路径

文件管理

文件内容类型、元数据、内容查看、文本处理、文本编辑、字符串的显示

目录管理

pwd,cd,ls,cp,mv,mkdir,tree,rmdir

前言:

写这篇完之前,发现管道、引用、...都没有提出,这里居然在引用,定的什么靳羽西,所以下篇"谢烟客---------Linux之Bash基础特性"用于补全读懂此篇的基础,然而对于有基础的同学,可以忽略,....。

文件系统

一种逻辑上存储和组织数据的方式,文件系统使用文件和树形目录的抽象逻辑概念代替了硬盘和光盘等物理设备使用数据块的概念

由索引和索引能够定位的编址方式组成

文本内容类型

ASCII

directory

symbolic

ELF

block

character

socket

sticky

文件的数据类型

数据(data):文件的内容

元数据(metadata):文件的属性信息

文本文件查看工具对数据操作时,都必须将数据从磁盘加载至内存中

文件名特性:

1、区分大小写. file1, File1, FILE1是不同的文件

2、不能使用特殊字符,/ 表示根

3、字符不能超过255个字符[root@izpo45bh60h6bsz ~]# mkdir cjwRbtslPbQJdQSSEhXHyzdoNIrqUTsGQHObbNfOZyuFrhwKMZpsZFNmedOhWIclBdkWzcYzpaaDDUiRrbJepwPhrfoMACtADSvFpNKABxUIeCItFLiJZUYSpCbqVXxLzdUbhLOSkUeGnDCiIDINbCIwthNBcbWpWTJEyQOQFkeglwCeUkbYSKooIxdBsoGzMeMcvCOVzIRPKgVtckHWrIqwnlZHmTFpDOLHKISXPDJwZAAGzZeEYnyBHFtSMUPk

mkdir: cannot create directory ‘cjwRbtslPbQJdQSSEhXHyzdoNIrqUTsGQHObbNfOZyuFrhwKMZpsZFNmedOhWIclBdkWzcYzpaaDDUiRrbJepwPhrfoMACtADSvFpNKABxUIeCItFLiJZUYSpCbqVXxLzdUbhLOSkUeGnDCiIDINbCIwthNBcbWpWTJEyQOQFkeglwCeUkbYSKooIxdBsoGzMeMcvCOVzIRPKgVtckHWrIqwnlZHmTFpDOLHKISXPDJwZAAGzZeEYnyBHFtSMUPk’: File name too long

4、以.开头的文件,均为隐藏文件

路径

绝对路径:从根目录起始的路径

对路径:从当前位置起始的路径

工作目录:当前目录

当前位置:用 . 号表示

上一级目录:用 .. 号表示

LSB   (Linux Standard Base)   Linux的标准规范

LSB组织定义了Linux发行版必须遵循的规则,FHS (filesystem heirarchy structure)

参考网址: http://www.geeksforgeeks.org/linux-file-hierarchy-structure/

/boot: 引导加载程序文件,例如,内核,initrd,grub[root@localhost ~]# ls /boot

config-2.6.32-696.el6.i686  grub                               lost+found                      System.map-2.6.32-696.el6.i686

efi  initramfs-2.6.32-696.el6.i686.img  symvers-2.6.32-696.el6.i686.gz  vmlinuz-2.6.32-696.el6.i686

/bin: 供所有普通用户使用的基本命令,系统启动即会用到的命令。[root@localhost ~]# ls /bin

alsaunmute  cp dbus-send  ed    gettext  kbd_mode  mail nano  raw       sed        tar          umount         zcat

/sbin: 管理类的基本命令,系统启动即会用到的命令。[root@localhost ~]# ls /sbin

accton               ctrlaltdel       fsck.cramfs     installkernel            logsave        mingetty             plymouthd            service             umount.hal

/lib: 基本的共享库及内核模块文件(/lib/modules); 启动过程中的程序依赖的库。[root@localhost ~]# ls -ld /lib/modules/

dr-xr-xr-x. 3 root root 4096 Jul 18 13:06 /lib/modules/

/etc: 配置文件目录(纯文本文件)

opt 为安装在/opt下的第三方软件提供配置[root@localhost ~]# ls -ld /etc/opt

drwxr-xr-x. 2 root root 4096 Sep 23  2011 /etc/opt

X11 为x protocol(gnome,kde的图形显示基础),提供配置[root@localhost ~]# ls /etc/X11/ # x protocol,x manager, x program(gnome,kde,xfce)

applnk  fontpath.d  prefdm

sgml 为sgml标记语言

xml为xml标记语言

/home/USERNAME: 普通用户家目录  用户的家目录为与用户名同名的目录[root@localhost ~]# ls /home

jerry  lost+found  tom

/root: 管理员的家目录; 有些发行版没有/root目录,因为管理员权限过大,不应该登陆系统(sudo)

/media: 便携性移动设备挂载点

cdrom: 挂载光盘

usb: 挂载U盘

/mnt: 临时文件系统挂载点

/dev: 特殊文件和设备文件存放目录

特殊文件:软件模拟的设备,/dev/zero,/dev/null

设备文件

块设备: block device 随机访问brw-rw---- 1 root disk      8,   0 Jul 18 22:19 sda

字符设备: character device 线性访问:时序性crw-rw-rw- 1 root root      1,   5 Jul 18 13:19 zero

通常用于独立分区的目录:/boot,/home,/usr,/var

/usr: universal shared read only data,全局共享"只读"数据[root@izpo45bh60h6bsz usr]# ls -l

total 124

dr-xr-xr-x.   2 root root 36864 Jul 28 15:44 bin

drwxr-xr-x.   2 root root  4096 Aug 12  2015 etc

drwxr-xr-x.   2 root root  4096 Aug 12  2015 games

drwxr-xr-x.  46 root root  4096 Jun 14 16:17 include

dr-xr-xr-x.  34 root root  4096 Jun 22 10:09 lib

dr-xr-xr-x.  59 root root 36864 Jul 28 15:44 lib64

drwxr-xr-x.  25 root root  4096 Jul  9 19:01 libexec

drwxr-xr-x.  14 root root  4096 May 15 22:08 local

dr-xr-xr-x.   2 root root 20480 Jul  9 19:01 sbin

drwxr-xr-x. 109 root root  4096 Jul 28 15:44 share

drwxr-xr-x.   4 root root  4096 Feb 24 10:58 src

lrwxrwxrwx.   1 root root    10 Feb 24 10:58 tmp -> ../var/tmp

bin:所有用户使用,保证系统拥有完整功能提供的应用程序,配置文件/etc

sbin:管理员使用,保证系统拥有完整功能提供的应用程序,配置文件/etc

lib: 为/usr/bin,/usr/sbin提供库

lib64: 专用于x86_64位系统上

include: C程序的头文件(header files), 描述库文件的调用方式

share: 结构化独立的数据

man

doc

桌面的背景图片

src: 手动编译源码时,源码的存放路径

local:本地层级结构,取代opt的第三方应用程序的安装位置

/var: 可变数据文件

cache: 应用程序缓存数据目录,varnish,memcache

lib: 应用程序的状态信息

local: 为/usr/local下的第三方程序存储可变数据

lock: 应用程序的锁文件

log: 日志目录及文件

opt: 专用于/opt下的第三方程序存储可变数据

run: 与运行中的进程相关的数据,通常用于存放进程的pid文件

spool: 应用程序的缓冲池

tmp: 保存系统再次重启之间产生的临时数据

mail: 邮箱

文件系统相关的命令

命令:

首先如何获取命令使用方法:

由前面所讲:不同的命令类型,获取帮助的方法各有不同,

1)获取命令的类型

2)依据前面所讲的方法获取文件的帮助

3)时间命令的格式

4)时间命令的语法

时间相关的命令

系统时间和硬件时间和网络时间服务器的区别:

1)系统时钟:由石英晶体驱动,每秒振动几百万次,并且这个速度永远不会改变,通过这个振动记录处理器操作的时间。

2)硬件时钟:主板上由电池供电的那个主板硬件时钟,这个时钟可以在BIOS的“Standard BIOS Feture”项中进行设置。

3)网络时间服务器:一种小型的、可独立工作的基于NTP/SNTP协议的时间服务器,可以从GPS地球卫星上获取标准时钟信号信息,将这些信息在网络中传输。

date命令[root@izpo45bh60h6bsz ~]# type date

date is /usr/bin/date  #外部命令

[root@izpo45bh60h6bsz ~]# date --help

Usage: date [OPTION]... [+FORMAT]

or:  date [MMDDhhmm[[CC]YY][.ss]]

Display the current time in the given FORMAT, or set the system date.

.....

FORMAT controls the output.  Interpreted sequences are:

%a   locale's abbreviated weekday name (e.g., Sun)

%A   locale's full weekday name (e.g., Sunday)

%c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)

%D   date; same as %m/%d/%y

%F   full date; same as %Y-%m-%d、

%T   time; same as %H:%M:%S

%Y   year

%m   month (01..12)

%d   day of month (e.g., 01)

%H   hour (00..23)

%M   minute (00..59)

%S   second (00..60)

%s   seconds since 1970-01-01 00:00:00 UTC

使用示例:

查看系统时间:[root@izpo45bh60h6bsz ~]# date

Sat Jul 29 09:14:48 CST 2017

[root@izpo45bh60h6bsz ~]# date +"%Y %m %d %H %M %S %s"

2017 07 29 09 15 27 1501290927

设定系统时间:[root@izpo45bh60h6bsz ~]# date 0101120016.30

Fri Jan  1 12:00:30 CST 2016

[root@izpo45bh60h6bsz ~]# date

Fri Jan  1 12:00:33 CST 2016

hwclock命令[root@izpo45bh60h6bsz ~]# type hwclock

hwclock is /usr/sbin/hwclock

[root@izpo45bh60h6bsz ~]# hwclock --help

Usage:

hwclock [function] [option...]

Functions:

-s, --hctosys        set the system time from the hardware clock

-w, --systohc        set the hardware clock from the current system time

使用示例:

查看硬件时间[root@izpo45bh60h6bsz ~]# hwclock

Sat 29 Jul 2017 09:20:16 AM CST  -0.850814 seconds

将系统时间同步到硬件时间[root@izpo45bh60h6bsz ~]# date

Fri Jan  1 12:03:56 CST 2016

[root@izpo45bh60h6bsz ~]# hwclock -w

[root@izpo45bh60h6bsz ~]# hwclock

Fri 01 Jan 2016 12:04:46 PM CST  -0.302054 seconds

将硬件时间同步到系统时间[root@izpo45bh60h6bsz ~]# date

Thu Jan  1 10:00:31 CST 2015

[root@izpo45bh60h6bsz ~]# hwclock

Fri 01 Jan 2016 12:05:22 PM CST  -0.268483 seconds

[root@izpo45bh60h6bsz ~]# hwclock -s

[root@izpo45bh60h6bsz ~]# hwclock

Fri 01 Jan 2016 12:05:35 PM CST  -0.229454 seconds

cal命令[root@izpo45bh60h6bsz ~]# type cal

cal is /usr/bin/cal

[root@izpo45bh60h6bsz ~]# cal --help

Usage:

cal [[[day] month] year]

使用示例:[root@izpo45bh60h6bsz ~]# cal 1 6 1990

June 1990

Su Mo Tu We Th Fr Sa

1  2

3  4  5  6  7  8  9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

开机、关机

halt,poweroff,reboot和shutdown命令的区别

shutdown命令是一种较为安全的关机或重启方式,在关机前,可以提醒别的终端用户,并自动将内存中的数据写入磁盘中。

halt,poweroff,reboot用法halt,poweroff,reboot

-f,force 意味着不在调用shutdown安全关机或重启,它们都默认调用shutdown命令完成关机或重启

-p 关机后,断掉电源

shutdown用法shutdown [OPTIONS...] TIME [MESSAGE]

-h: halt,关机后切断电源

-r: reboot,关机不切断电源,重启

-c: cancel, 取消关机或重启操作

TIME:

now:立刻

+m:从命令提交开始,向后多少分钟

hh:mm: 绝对时间表示法,明确指明具体时间

登陆用户、终端、命令路径

who,whoami,w,whereis,which,whatis,mkwhatis,ttywhoami 显示当前登陆的有效用户

who 显示系统当前所有的登陆会话:用户、时间、关联的终端、主机

w 显示系统当前所有的登陆会话及所做的操

which 显示命令对应的程序文件路径

--skip-alias 禁止显示别名

whereis 定位二进制,源文件,手册页的路径

whatis 从whatis的数据库搜索命令的帮助手册路径

mkwhatis:当前系统上所有的帮助手册及与之对应关键字创建为一个数据库

tty 显示当前终端的文件名

文件管理类命令

文件内容类型、元数据、内容查看、文本处理、文本编辑、字符串的显示

文件内容类型显示,file命令[root@izpo45bh60h6bsz ~]# file /lib64/libgpgme.so.11.8.1

/lib64/libgpgme.so.11.8.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=fb5883bd42777a17af017e4b9cbf58cc1ea22693, stripped

文件的元数据,stat,touch命令

stat命令[root@izpo45bh60h6bsz ~]# type stat

stat is /usr/bin/stat

[root@izpo45bh60h6bsz ~]# stat --help

Usage: stat [OPTION]... FILE...

显示文件当前的状态

File: ‘文件名’

Size: 文件的大小(bytes)  Blocks: 数据块  IO Block: IO块  文件类型

Device: fd01h/64769Inode: Inode号码     Links: 硬链接次数

Access: (文件的权限)  Uid: (属主及UID)   Gid: (基本组及ID)

Access: 文件最近一次访问的时间

Modify: 文件最近一次修改的时间

Change: 文件最近一次元数据改变的时间

Birth: -

touch命令[root@izpo45bh60h6bsz ~]# type touch

touch is /usr/bin/touch

[root@izpo45bh60h6bsz ~]# touch --help

Usage: touch [OPTION]... FILE...

-c, --no-create   文件存在时,改变所有文件的元数据

-a          只改变最近一次访问的时间,但访问时间的改变会引起元数据的改变

-m          只改变最近一次修改的时间,但访问时间的改变会引起元数据的改变

-t STAMP               使用[[CC]YY]MMDDhhmm[.ss] 代替当前的时间,不会引起元数据的改变

文件查看工具:cat,tac,more,less,tail,head命令

cat命令[root@izpo45bh60h6bsz ~]# type cat

cat is /usr/bin/cat

[root@izpo45bh60h6bsz ~]# cat --help

Usage: cat [OPTION]... [FILE]...

连接文件输出至标准输出

-n, --number            为显示的行编号,并非改变文本内容

-E, --show-ends         显示行结束符连接文件:

[root@izpo45bh60h6bsz ~]# file /etc/fstab

/etc/fstab: ASCII text

[root@izpo45bh60h6bsz ~]# file /etc/issue

/etc/issue: ASCII text

[root@izpo45bh60h6bsz ~]# cat /etc/fstab /etc/issue

#

# /etc/fstab

# Created by anaconda on Fri Feb 24 02:58:22 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

\S

Kernel \r on an \m[root@izpo45bh60h6bsz ~]# cat -nE /etc/fstab

1$

2#$

3# /etc/fstab$

4# Created by anaconda on Fri Feb 24 02:58:22 2017$

5#$

6# Accessible filesystems, by reference, are maintained under '/dev/disk'$

7# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info$

8#$

9UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1$

tac命令 同cat用法,反向显示[root@izpo45bh60h6bsz ~]# tac /etc/fstab

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

#

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

# Accessible filesystems, by reference, are maintained under '/dev/disk'

#

# Created by anaconda on Fri Feb 24 02:58:22 2017

# /etc/fstab

#

more命令[root@izpo45bh60h6bsz ~]# type more

more is /usr/bin/more

[root@izpo45bh60h6bsz ~]# more --help

more: unknown option -help

Usage: more [options] file...

Options:

-d        display help

less命令[root@izpo45bh60h6bsz ~]# type less

less is /usr/bin/less

[root@izpo45bh60h6bsz ~]# less --help

同man的使用

tail命令[root@izpo45bh60h6bsz ~]# type tail

tail is /usr/bin/tail

[root@izpo45bh60h6bsz ~]# tail --help

Usage: tail [OPTION]... [FILE]...

Print the last 10 lines of each FILE to standard output.

-c, --bytes=K           显示文件后K个字节

-f, --follow[={name|descriptor}] 显示文件后10行,不退出等待追加内容

-n, --lines=K      显示文件后K行

使用示例

1)默认显示后10行[root@izpo45bh60h6bsz ~]# tail /etc/fstab

#

# /etc/fstab

# Created by anaconda on Fri Feb 24 02:58:22 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

2)显示 后10个字节[root@izpo45bh60h6bsz ~]# tail -c 10 /etc/fstab

1 1

3)显示后1行[root@izpo45bh60h6bsz ~]# tail -n 1 /etc/fstab

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

3)显示后,不退出,等待追加内容

head命令[root@izpo45bh60h6bsz ~]# type head

head is /usr/bin/head

[root@izpo45bh60h6bsz ~]# head --h

Usage: head [OPTION]... [FILE]...

Print the first 10 lines of each FILE to standard output.

-c, --bytes=K           显示文件前K个字节

-n, --lines=K      显示文件前K行

使用示例

1)默认显示前10行[root@izpo45bh60h6bsz ~]# head /etc/init.d/functions

# -*-Shell-script-*-

#

# functionsThis file contains functions to be used by most or all

#shell scripts in the /etc/init.d directory.

#

TEXTDOMAIN=initscripts

# Make sure umask is sane

umask 022

2)显示文件前K个字节[root@izpo45bh60h6bsz ~]# head -c 100 /etc/init.d/functions

# -*-Shell-script-*-

#

# functionsThis file contains functions to be used by most or all

#shell s[root@izpo45bh60h6bsz ~]#

3)显示文件前K行[root@izpo45bh60h6bsz ~]# head -n 2 /etc/init.d/functions

# -*-Shell-script-*-

#

文本处理命令,wc,cut,sort,uniq,tr

wc命令[root@izpo45bh60h6bsz ~]# type wc

wc is /usr/bin/wc

[root@izpo45bh60h6bsz ~]# wc --h

Usage: wc [OPTION]... [FILE]...

统计指定行的行数、单词数、字节数

-l, --lines 仅显示行数

-w, --words 仅显示单词数

-c, --bytes 仅显示字节数

使用示例

1)统计指定文件的行数、单词数、字节数[root@izpo45bh60h6bsz ~]# wc /etc/fstab

9  42 313 /etc/fstab

2)行数显示[root@izpo45bh60h6bsz ~]# wc -l /etc/fstab

9 /etc/fstab

3)单词数显示[root@izpo45bh60h6bsz ~]# wc -w /etc/fstab

42 /etc/fstab

4)字节数显示[root@izpo45bh60h6bsz ~]# wc -c /etc/fstab

313 /etc/fstab

5)注意如果不显示后面的文件可用管道命令[root@izpo45bh60h6bsz ~]# cat /etc/fstab | wc -l

9

[root@izpo45bh60h6bsz ~]# cat /etc/fstab | wc -w

42

[root@izpo45bh60h6bsz ~]# cat /etc/fstab | wc -c

313

cut命令[root@izpo45bh60h6bsz ~]# type cut

cut is /usr/bin/cut

[root@izpo45bh60h6bsz ~]# cut --h

Usage: cut OPTION... [FILE]...

Print selected parts of lines from each FILE to standard output.

-d, --delimiter=DELIM 用DELIM指定字段分隔符,默认为空白

-f, --fields=LIST 显示字段的列表

A  A-B A-B,C

--output-delimiter=STRING  用STRING指明输出字段分隔符,不给出时,默认为输入分隔符

使用示例

1)从标准输出挑选行的部分字段[root@izpo45bh60h6bsz ~]# cut -d':' -f1-3,5 /etc/passwd

root:x:0:root

bin:x:1:bin

.....

2)输出分隔符给定,缺省为空白[root@izpo45bh60h6bsz ~]# cut -d':' -f1-3,5 --output-delimiter=' ' /etc/passwd

root x 0 root

bin x 1 bin

daemon x 2 daemon

adm x 3 adm

lp x 4 lp

sync x 5 sync

....

sort命令[root@izpo45bh60h6bsz ~]# type sort

sort is /usr/bin/sort

[root@izpo45bh60h6bsz ~]# sort --h

sort: option '--h' is ambiguous; possibilities: '--human-numeric-sort' '--help'

Try 'sort --help' for more information.

[root@izpo45bh60h6bsz ~]# sort --help

Usage: sort [OPTION]... [FILE]...

Write sorted concatenation of all FILE(s) to standard output.

-r: 逆序排列

-f: 忽略字符的大小写

-n: 以数值大小排序

-t'分隔符'

-kFILEDS 以指定字段为标准排序

-u: 先排序,后去重。uniq唯一的,去重的,连续且相同,只保留一个.

注意:默认排序,依据ASCII码表排序

使用示例

1)默认比较每一行的第一个字母,按照字符在ASCII码表中以字符排列[root@izpo45bh60h6bsz ~]# cat a.txt #原文件内容

11

1

0

3

34

12

16

18

22

23

90

28

[root@izpo45bh60h6bsz ~]# sort a.txt #排序后的结果

0

1

11

12

16

18

22

23

28

3

34

90

2)以数值大小排序[root@izpo45bh60h6bsz ~]# sort -n a.txt

0

1

3

11

12

16

18

22

23

28

34

90

3)逆序排列[root@izpo45bh60h6bsz ~]# sort -r a.txt  #以ASCII码表,逆序

90

34

3

28

23

22

18

16

12

11

1

0

[root@izpo45bh60h6bsz ~]# sort -r -n a.txt  #以数值排序,逆序

90

34

28

23

22

18

16

12

11

3

1

0

4)忽略字符的大小写[root@izpo45bh60h6bsz ~]# sort b.txt

a

A

b

B

c

C

[root@izpo45bh60h6bsz ~]# sort -f b.txt

A

a

B

b

C

c

5)-t,-k使用,以字段分隔符分隔,仅对某字段排列[root@izpo45bh60h6bsz ~]# cat b.txt

a 1 b c

c 3 b c

d 10 c e

o 110 d f

l 2 f s

E 99 A D

A 77 D 1

SD 45 DF DF

ASDFDF 66 AD OOO

[root@izpo45bh60h6bsz ~]# sort -t' ' -k2 b.txt #以ASCII码排序第二个字段

d 10 c e

o 110 d f

a 1 b c

l 2 f s

c 3 b c

SD 45 DF DF

ASDFDF 66 AD OOO

A 77 D 1

E 99 A D

[root@izpo45bh60h6bsz ~]# sort -n -t' ' -k2 b.txt  #以数值排序第二个字段

a 1 b c

l 2 f s

c 3 b c

d 10 c e

SD 45 DF DF

ASDFDF 66 AD OOO

A 77 D 1

E 99 A D

o 110 d f

6)排序后去重。[root@izpo45bh60h6bsz ~]# sort a.txt

11

11

11

11

[root@izpo45bh60h6bsz ~]# sort -u a.txt

11

uniq命令uniq 命令: 去重的, 重复:“连续且完全相同方为重复”

uniq [OPTIONS...] FILE

-c: count 统计每一行重复的次数

-d: 仅显示重复出现的行,至少2次。

-u: 仅显示未曾重复的行

1)去重[root@izpo45bh60h6bsz ~]# cat d.txt  #不连续

whatis

whatis

whereis

whereis

which

which

which

whereis

which

which

who

which

who

which

who

yum

who

yum

which

yum

[root@izpo45bh60h6bsz ~]# sort d.txt  #经过排序,使之连续

whatis

whatis

whereis

whereis

whereis

which

which

which

which

which

which

which

which

who

who

who

who

yum

yum

yum

[root@izpo45bh60h6bsz ~]# sort d.txt | uniq #去重

whatis

whereis

which

who

yum

2) 统计每一行重复的次数[root@izpo45bh60h6bsz ~]# sort d.txt | uniq -c

1

2 whatis

3 whereis

8 which

4 who

3 yum

3)  仅显示重复出现的行,至少2次。[root@izpo45bh60h6bsz ~]# sort d.txt | uniq -c

1

2 whatis

3 whereis

8 which

4 who

3 yum

[root@izpo45bh60h6bsz ~]# sort d.txt | uniq -d

whatis

whereis

which

who

yum

4)显示不重复的行[root@izpo45bh60h6bsz ~]# sort d.txt | uniq -u

tr命令[root@izpo45bh60h6bsz ~]# type tr

tr is /usr/bin/tr

[root@izpo45bh60h6bsz ~]# tr --help

tr命令:转换或删除字符

tr [OPTIONS...] SET1 [SET2]

将SET1,SET2进行对位转换

-d 删除指定字符

tr -d 'SET1'

-dc 保留指定字符

tr -dc 'SET1'

-s 去重

tr -s 'SET1'

1)转换,SET1,SET2进行对位转换[root@izpo45bh60h6bsz ~]# tr 'abc' 'CBA'

abc

CBA

CBA

CBA

2)删除指定字符[root@izpo45bh60h6bsz ~]# tr -d 'a'

a pig

pig

bar

br

case

cse

2)保留指定字符[root@izpo45bh60h6bsz ~]# echo 'abccd' | tr -dc 'c'

cc

3)去重[root@izpo45bh60h6bsz ~]# echo 'aaaaabbbbbbbbbccccccdddd' | tr -s 'bcda'

abcd

文本编辑命令,nano^G Get Help

^O WriteOut 保存

^R Read File

^Y Prev Page

^K Cut Text 剪切

^C Cur Pos

^X Exit 退出

^J Justify

^W Where Is  搜索

^V Next Page

^U UnCut Text

字符串的显示命令,echo,printf[root@izpo45bh60h6bsz ~]# type echo

echo is a shell builtin

[root@izpo45bh60h6bsz ~]# help echo

echo: echo [-neE] [arg ...]

Write arguments to the standard output.

-n 不追加新街

-e 让逃逸符生效

\bbackspace

\nnew line

\thorizontal tab

\vvertical tab

使用示例:

1)不换行[root@izpo45bh60h6bsz ~]# echo "hello"

hello

[root@izpo45bh60h6bsz ~]# echo -n "hello"

hello[root@izpo45bh60h6bsz ~]#

[root@izpo45bh60h6bsz ~]# printf "hello"

hello[root@izpo45bh60h6bsz ~]# printf "hello\n"

hello

2)转义符[root@izpo45bh60h6bsz ~]# echo -e 'helloworld'

helloworld

[root@izpo45bh60h6bsz ~]# echo -e 'hello\tworld' #打印横向制表符

helloworld

[root@izpo45bh60h6bsz ~]# echo -e 'hello\vworld' #打印垂直制表符

hello

world

[root@izpo45bh60h6bsz ~]# echo -e 'hello\bworld' #退格键

hellworld

[root@izpo45bh60h6bsz ~]# echo -e 'hello\nworld' #换行

hello

world

目录管理命令:pwd,cd,ls,mkdir,rmdir,mv,cp

pwd命令[root@izpo45bh60h6bsz ~]# type pwd

pwd is a shell builtin

[root@izpo45bh60h6bsz ~]# help pwd

pwd: pwd

Print the name of the current working directory. 显示当前目录的名字

使用示例:[root@izpo45bh60h6bsz ~]# pwd

/root

[root@izpo45bh60h6bsz ~]# cd /etc

[root@izpo45bh60h6bsz etc]# pwd

/etc

cd命令[root@izpo45bh60h6bsz etc]# type cd

cd is a shell builtin

[root@izpo45bh60h6bsz etc]# help cd

cd: cd [dir]

Change the shell working directory.

使用示例:[root@izpo45bh60h6bsz ~]# pwd #当前目录

/root

[root@izpo45bh60h6bsz ~]# cd ~tom #切换至tom用户

[root@izpo45bh60h6bsz tom]# pwd #当前目录为tom的家目录

/home/tom

[root@izpo45bh60h6bsz tom]# cd ~ #切换至当前用户的家目录

[root@izpo45bh60h6bsz ~]# pwd #当前目录为root的家目录

/root

[root@izpo45bh60h6bsz ~]# cd /etc #切换至/etc/目录

[root@izpo45bh60h6bsz etc]# pwd #当前目录为/etc目录

/etc

[root@izpo45bh60h6bsz /]# cd /etc/sysconfig/network-scripts/ #切换至指定目录

[root@izpo45bh60h6bsz network-scripts]# pwd

/etc/sysconfig/network-scripts

[root@izpo45bh60h6bsz network-scripts]# cd . #切换为当前目录

[root@izpo45bh60h6bsz network-scripts]# pwd

/etc/sysconfig/network-scripts

[root@izpo45bh60h6bsz network-scripts]# cd .. #切换为上一级目录

[root@izpo45bh60h6bsz sysconfig]# pwd

/etc/sysconfig

[root@izpo45bh60h6bsz sysconfig]# cd -  #切换为上次所在的目录

/etc/sysconfig/network-scripts

[root@izpo45bh60h6bsz network-scripts]# pwd

/etc/sysconfig/network-scripts

[root@izpo45bh60h6bsz network-scripts]# cd -

/etc/sysconfig

[root@izpo45bh60h6bsz sysconfig]# pwd

/etc/sysconfig

[root@izpo45bh60h6bsz sysconfig]# cd #切换为当前登陆用户的家目录

[root@izpo45bh60h6bsz ~]# pwd

/root

ls命令[root@izpo45bh60h6bsz ~]# type ls

ls is aliased to `ls --color=auto'

[root@izpo45bh60h6bsz ~]# ls --help

Usage: ls [OPTION]... [FILE]...

Mandatory arguments to long options are mandatory for short options too.

-a, --all                  do not ignore entries starting with .

-A, --almost-all           do     not list implied . and ..

-d, --directory            list directories themselves, not their contents

-h, --human-readable       with -l, print sizes in human readable format

-l                         use a long listing format

-i, --inode                print the index number of each file

-r, --reverse              reverse order while sorting

-R, --recursive            list subdirectories recursively

-Z, --context              Display security context so it fits on most

示例:

1)显示所有文件,包括隐藏文件[root@izpo45bh60h6bsz tmp]# ls

a  b  c  d  e  f  fe  s

[root@izpo45bh60h6bsz tmp]# ls -a

.  ..  a  b  c  d  e  .ea  f  fe  .font-unix  .ICE-unix  s  .Test-unix  .X11-unix  .XIM-unix

2)显示所有文件,包括隐藏文件,除了.  ..[root@izpo45bh60h6bsz tmp]# ls -A

a  b  c  d  e  .ea  f  fe  .font-unix  .ICE-unix  s  .Test-unix  .X11-unix  .XIM-unix

3)详细信息[root@izpo45bh60h6bsz tmp]# ls -l

total 24

-rw-r--r-- 1 root root   313 Jan  1 14:35 fstab

-rw-r--r-- 1 root root 13948 Jan  1 14:36 functions

-rw-r--r-- 1 root root    23 Jan  1 14:35 issue

4)人类易懂[root@izpo45bh60h6bsz tmp]# ls -lh

total 24K

-rw-r--r-- 1 root root 313 Jan  1 14:35 fstab

-rw-r--r-- 1 root root 14K Jan  1 14:36 functions

-rw-r--r-- 1 root root  23 Jan  1 14:35 issue

5)只显示目录[root@izpo45bh60h6bsz tmp]# ls -d

.

[root@izpo45bh60h6bsz tmp]# ls -dl

drwxrwxrwt. 7 root root 4096 Jan  1 14:36 .

6)显示inode号[root@izpo45bh60h6bsz tmp]# ls -i

819202 a  819208 b  819209 c  819210 d  819211 e  819212 f  819217 fe  819219 fstab  819221 functions  819220 issue  819218 s

[root@izpo45bh60h6bsz tmp]# ls -il

total 24

819219 -rw-r--r-- 1 root root   313 Jan  1 14:35 fstab

819221 -rw-r--r-- 1 root root 13948 Jan  1 14:36 functions

7)显示安全上下文[root@izpo45bh60h6bsz tmp]# ls -Zl

total 24

-rw-r--r-- 1 ?                                root root   313 Jan  1 14:35 fstab

-rw-r--r-- 1 ?                                root root 13948 Jan  1 14:36 functions

-rw-r--r-- 1 ?                                root root    23 Jan  1 14:35 issue

8)逆序显示[root@izpo45bh60h6bsz tmp]# ls #ASCII码

a  b  c  d  e  f  fe  fstab  functions  issue  s

[root@izpo45bh60h6bsz tmp]# ls -r #逆序

s  issue  functions  fstab  fe  f  e  d  c  b  a

10)递归[root@izpo45bh60h6bsz tmp]# ls -R

.:

fstab  functions  issue

mkdir命令[root@izpo45bh60h6bsz ~]# type mkdir

mkdir is /usr/bin/mkdir

[root@izpo45bh60h6bsz ~]# mkdir --help

Usage: mkdir [OPTION]... DIRECTORY...

Create the DIRECTORY(ies), if they do not already exist.

-m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask

-p, --parents     no error if existing, make parent directories as needed

-v, --verbose     print a message for each created directory

1)创建目录,指定权限[root@izpo45bh60h6bsz tmp]# mkdir test1

[root@izpo45bh60h6bsz tmp]# mkdir -m 000 test2

[root@izpo45bh60h6bsz tmp]# ls -l

total 8

drwxr-xr-x 2 root root 4096 Jan  1 14:42 test1

d--------- 2 root root 4096 Jan  1 14:43 test2

2)创建目录,如果父目录不存在,自动创建[root@izpo45bh60h6bsz tmp]# mkdir a/b/c

mkdir: cannot create directory ‘a/b/c’: No such file or directory

[root@izpo45bh60h6bsz tmp]# mkdir -p a/b/c

[root@izpo45bh60h6bsz tmp]# tree a

a

└── b

└── c

2 directories, 0 files

3)创建目录,显示创建的过程[root@izpo45bh60h6bsz tmp]# mkdir -pv b/c/a/d/e

mkdir: created directory ‘b’

mkdir: created directory ‘b/c’

mkdir: created directory ‘b/c/a’

mkdir: created directory ‘b/c/a/d’

mkdir: created directory ‘b/c/a/d/e’

[root@izpo45bh60h6bsz tmp]# tree b

b

└── c

└── a

└── d

└── e

4 directories, 0 files

rmdir命令[root@izpo45bh60h6bsz tmp]# type rmdir

rmdir is /usr/bin/rmdir

[root@izpo45bh60h6bsz tmp]# rmdir --h

Usage: rmdir [OPTION]... DIRECTORY...

Remove the DIRECTORY(ies), if they are empty.

-p, --parents   remove DIRECTORY and its ancestors;

e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a'

-v, --verbose   output a diagnostic for every directory processed

1)如果删除当前空目录后,父目在为空,则递归删除[root@izpo45bh60h6bsz tmp]# rmdir -p a/b/c

[root@izpo45bh60h6bsz tmp]# ls

b  test1  test2

2)显示删除的过程[root@izpo45bh60h6bsz tmp]# rmdir -pv b/c/a/d/e

rmdir: removing directory, ‘b/c/a/d/e’

rmdir: removing directory, ‘b/c/a/d’

rmdir: removing directory, ‘b/c/a’

rmdir: removing directory, ‘b/c’

rmdir: removing directory, ‘b’

[root@izpo45bh60h6bsz tmp]# ls

test1  test2

mv命令[root@izpo45bh60h6bsz tmp]# type mv

mv is aliased to `mv -i'

[root@izpo45bh60h6bsz tmp]# mv --h

Usage: mv [OPTION]... [-T] SOURCE DEST

or:  mv [OPTION]... SOURCE... DIRECTORY

or:  mv [OPTION]... -t DIRECTORY SOURCE...

-f, --force                  do not prompt before overwriting

-i, --interactive            prompt before overwrite

使用示例:

1)单源文件,目标不存在:重命名文件[root@izpo45bh60h6bsz tmp]# file /tmp/fstab

/tmp/fstab: ASCII text

[root@izpo45bh60h6bsz tmp]# ls /tmp/abc

ls: cannot access /tmp/abc: No such file or directory

[root@izpo45bh60h6bsz tmp]# mv /tmp/fstab /tmp/abc

[root@izpo45bh60h6bsz tmp]# ls /tmp/

abc  test1  test2

2)单源目录,目标不存在:重命令目录[root@izpo45bh60h6bsz tmp]# file /tmp/test1

/tmp/test1: directory

[root@izpo45bh60h6bsz tmp]# ls /tmp/test3

ls: cannot access /tmp/test3: No such file or directory

[root@izpo45bh60h6bsz tmp]# mv /tmp/test1 /tmp/test3

[root@izpo45bh60h6bsz tmp]# ls /tmp/

abc  test2  test3

3)单源文件,目录存在为目录或文件[root@izpo45bh60h6bsz tmp]# cat abc #第一个文件

#

# /etc/fstab

# Created by anaconda on Fri Feb 24 02:58:22 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

[root@izpo45bh60h6bsz tmp]# cat b #第二个文件

1

[root@izpo45bh60h6bsz tmp]# mv abc b #文件存在时,提示是否覆盖

mv: overwrite ‘b’? y

[root@izpo45bh60h6bsz tmp]# ls #覆盖后,原文件消失

b  test2  test3

[root@izpo45bh60h6bsz tmp]# cat b #目标文件的内容为原文件的内容

#

# /etc/fstab

# Created by anaconda on Fri Feb 24 02:58:22 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults

[root@izpo45bh60h6bsz tmp]# cat b #文件b

#

# /etc/fstab

# Created by anaconda on Fri Feb 24 02:58:22 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=07151862-c2b9-45dc-bf7a-af8d2a6fa6c1 /                       ext3    defaults        1 1

[root@izpo45bh60h6bsz tmp]# file test3 #存在的目录

test3: directory

[root@izpo45bh60h6bsz tmp]# ls test3 #目录下无任何文件

[root@izpo45bh60h6bsz tmp]# mv b test3 #

[root@izpo45bh60h6bsz tmp]# ls test3 #移到后目录下为原文件

b

[root@izpo45bh60h6bsz tmp]# ls /tmp #移动后原文件消失

test2  test3

4)多源文件,目标存在为目录[root@izpo45bh60h6bsz tmp]# ls #当前目录下的内容

fstab  issue  test2  test3

[root@izpo45bh60h6bsz tmp]# ls test2 #目标目录下无任何文件

[root@izpo45bh60h6bsz tmp]# mv fstab issue test2 #移动

[root@izpo45bh60h6bsz tmp]# ls  #移动后原文件消失

test2  test3

[root@izpo45bh60h6bsz tmp]# ls test2 #目标目录下为原文件

fstab  issue

cp命令用法同mv,只是移动变复制,原文件保留

rm命令[root@izpo45bh60h6bsz tmp]# type rm

rm is aliased to `rm -i'

[root@izpo45bh60h6bsz tmp]# rm --h

Usage: rm [OPTION]... FILE...

Remove (unlink) the FILE(s).

-f, --force           ignore nonexistent files and arguments, never prompt

-i                    prompt before every removal

-r, -R, --recursive   remove directories and their contents recursively

示例:

1)删除文件[root@izpo45bh60h6bsz test2]# pwd #当前所在的目录

/tmp/test2

[root@izpo45bh60h6bsz test2]# ls #目录下的文件

fstab  issue

[root@izpo45bh60h6bsz test2]# file fstab #fstab为文件

fstab: ASCII text

[root@izpo45bh60h6bsz test2]# rm fstab #交互式:删除时,提示是否删除

rm: remove regular file ‘fstab’? ^C

[root@izpo45bh60h6bsz test2]# rm -f fstab #非交互式:删除时,不提示是否删除

[root@izpo45bh60h6bsz test2]# ls #目录下的文件被删除

issue

2)删除目录:-r[root@izpo45bh60h6bsz tmp]# pwd #当前所在的目录

/tmp

[root@izpo45bh60h6bsz tmp]# ls #目录下存在的文件

fstab  issue  test2  test3

[root@izpo45bh60h6bsz tmp]# rm test2 #删除目录,提示不能删除

rm: cannot remove ‘test2’: Is a directory

[root@izpo45bh60h6bsz tmp]# rm -r test2 #递归删除目录选项,提示是否删除

rm: descend into directory ‘test2’? ^C

[root@izpo45bh60h6bsz tmp]# rm -rf test2 #非交互式删除目录

[root@izpo45bh60h6bsz tmp]# ls #删除成功

fstab  issue  test3

tree命令[root@izpo45bh60h6bsz tmp]# type tree

tree is /usr/bin/tree

[root@izpo45bh60h6bsz tmp]# tree --help

usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]]

[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]

[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]

[--filelimit[=]#] [--si] [--timefmt[=]] []

-d 仅显示目录及子目录

-P pattern 显示指定目录下符合指定模式的文件

-L # 限制显示目录的层级

1)仅显示目录及子目录,默认显示文件和目录[root@izpo45bh60h6bsz ~]# tree -d /root

/root

├── bin

├── gentoo

│   └── hello

├── link_test1 -> test1

├── manifests

├── slackware

├── test1

├── tmpfile

├── tomcat

└── tomcat1

10 directories

2)显示指定目录下符合指定模式的文件

3)限制目录层级[root@izpo45bh60h6bsz ~]# tree -L 1 /root

/root

├── a.txt

├── bin

├── b.sh

├── b.txt

├── c.sh

[root@izpo45bh60h6bsz ~]# tree /root

/root

├── a.txt

├── bin

│   ├── addusers.sh

│   └── hello

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值