WE
date-prin1orseLLh亡syslemdaleahdtinn*
SYMTSiS
date[OmtML…[+FCRNAT1
date[~u]一uIc--univtrsa11[MtCDhhrmf[GCJYY][.ss]I
:
DESCKIPTICN
Displaythecurrentlintintherven,orseIlhesystemdaic.
2.10假设你的主目录是/usr/student,利用In-s/usr/student/file1slink进行符号
连接。
然后,利用Is-Ifilelslink显示有关filel和slink的信息。
2.11运行ls-l/bin命令显示目录的内容。
文他編辑(E)査看©?
转到匹)帝助(H)
[roolO'locaihos
t
/]»Is
-1/bm
总用附5512
-rwlxir
I
1'o<>t
r«oL
-rwxr-xr-x
I
1oot
root
-rwtr^xr-x
t
1ool
root
-rgLxir
I
ro<>I
『GOI
1mrwxrwx
I
root
rcol
-rwtr^xr-x
t
1ooi
root
-rgL*ir
I
ro<>I
『GOI
2644
2003-02-25
arth
92444
2003*02-06
ash
49296«
2003-02-06
葬山*&iic
10456
200S-01-25
aumiK^minim1
4
2010-01-08
avJt->gav>k
1084^
2OOS-02-19
bqspiisiiv
丫他仙囲
2003-02-11
bash
2.12利用ls-l/bin|more命令行分屏显示/bin目录的内容。
]CXJt.j4o2diJlM)SL/
文件習确好®
ft4x
终瑞⑴
Iron网1neaIhost
Is-1
/bin-/mre
总用景5S12
1
-rw^r-xr-x
1
IOC1
root
2644
2005-02-25
arch
-ru^r-xr-x
1
roel
root
92444
2003*02-06
ash
-r^wr-xr-x
1
rooI
root
492968
2003-02-06
ash.slatic
-r\wr-xr-x
I
rooi
loot
104S6
2(X)3-0)^25
auinix^nmninfB1
11\w『昭r曲
1
ICOI
rooL
4
2D1O-OH08
auk->gawk
-rwxr-xi■一览
1
rooI
]oot
1084S
2003-02*19
basenanp
-r-x
]
rooi
root
62602&
2003-02-H
hash
11wr曲r曲
1
loci
rooL
4
2010-01-04(
bash2->bash
3、文件操作
3.1利用find命令查找文件和目录
mike@Jocalhost:
/home/mike
FileEditViewSearchTerminalHelp
[root^localhostmike]#Is
DesktopDownleadsexam,cMusicPublictest
DocumentsexamfilelPicturesTemplatesVideos
[root^lcicalhostmike]#find./-name"P***-print►/Pictures
,/Public
[root^lacalhostmike]#|
3.2查找文件中指定的内容
mike@localho5t:
/home/mjke
FileEditViewSearchTerminalHelp[root^localhostmike]#grepmike/etc/passwdmike:
x:
S88:
590:
MikeCentQS:
/hone/nike:
/bin/bash[root^localhostmike]#[
4、文件与目录存取权限
,more,file
mail,cp等。
4.1文件读权限(r):
允许指定的用户可以打开文件并阅读其内容。
如cat
和cp命令等。
回mike@localhost:
/home/mjke
FileEditViewSearchTerminalHelp{rcot)@localho5tmike]#Is
E
r?
sktopDo..nloadsPicturesTc-pKite\.test.txt
ocunentsMusicPublictestVideos
[root^localhostmike]#Is-Itest
*rw-r—r**.1rootroot5Det702:
43test[root^localhostmike]#cattestdate
4.2文件写权限(w):
允许指定的用户可以打开文件并修改其内容。
如vi,
[root(3localhostmike]#vitest
(roatflocalhostmike]#|
mike@localhost7horne/mike1
FileEditView
SearchTerminalHelp
Sate
—
—
hte$t"1LP5C
4.3文件执行权限(x):
允许指定的用户运行(即执行)一个二进制文件或者把一个shell脚本文件当作命令来运行。
当你通过输入命令名来调用命令时,你必须具有该命令文件的执行权限。
mike@localhost:
/home/mike
FileEditViewSearchTerminalHelp[rcot@localhostmike]#chmod744test[root(aiocalho5tmike]#Is-Itest-rwxr--r--*1root5Dec792:
43[root(3localhostmike]#./testMedDec762149:
07P5T2016(rcotflocalhostmike]#|
4.4目录读权限(r):
允许你列出相应目录中所存放的文件的名字(即目录的内容表)
mike@]ocalhost:
/home/mike
FileEditViewSearchTerminalHelp
[root(aiocalhostmike]#pwd
/hoRie/mike
[roat(aiocalhostmike]#Is-dl/home/mike
drwx*托mikemike4096Dec702:
43hore/mike
[root^localhostmike]#|
[root(aiQCalhostmikej#Is/home/mike
DesktopDo./nloadsPicturesTemplatestest,txt
DocumentsNusicPublictestVideos
[roct^localhostmike]#|
4.5目录写权限(w):
允许你从目录中删除已有文件或者把新文件添加到目录中
mike@localhost:
/home/mike
FileEditViewSearchlernninalHelp
rQQt@lacal.ho5tFhome/mike
root^localhostiindevhome)ootetclib;root^localhost;root^localhost
mlke]fpwd
mike]#Is/
lost+foundmntprocsbinmediaoptrootselinux
mike]#cp/test.txt/home/mikemikej#Is
irtest+txt
usr
var
desktop
Jocuments
DownloadsMusic
PicturesPublic
Templatestest
test.txtVideos
cd命令把工作目录放到它这里
rootfaiocalhostmike]#
4.6目录查询权限(x):
允许你在目录中进行查找和使用
mi民e四申acainusi:
/nome/mikc
FileEditViewSearchTerrriinaiHelp
[root^localhcistf
[root^localhost[root@localhosthome/mike
[rcot^localhost
/]#pwd
/]#cd/home/mikemike]#pwd
mike]#|
4.7修改文件或目录权限
[root@localhostmike]#chmod744test[root@localhostmike]#Is-1test
-rwxr--r--.1rootroot5Dec792:
43
[rcat^Iocalhostmike]#
[root^localhastmike]#chmodu-xtest[root^localhostmike]#Is-1test
-rw-r--r--,1rootroot506C792:
43test
[root^localhostmike]#|
mike@localho5t:
/home/mike
FileEditviewsearchTtrminaJHelp
[rcot@localhostmike]#Is-dl/home/rnike
drwx・26mikemike4096Dec123:
85/home/mike
root^localhostmike]#chmod744/home/mike
rcot@localhostmike]#Is-dl/home/mike
drwxr--r*-.26mikemike4096Dec123:
S5'hcie/niike[rcQt^Xcicalhostmike]#|
二、LINUX文件系统编程
1.1、在VMware运行Linux(CentOS),并打开Terminal
mike@localhost:
/home/mike
FileEditViewSearchTerminalHelpfroot^lacalhostmike]#|
1.2、新建eaxm.c文件,并使用C语言进行编程
[root^localhastmike]#vimexam.c
mike@localhost:
/home/mike-□
FileEditViewSearchTerminalHelp
#includecstdio.hj
#include
#includ&<;unistd.h>
#includecfcntl.h>
#include
#include
#include
#include
defineMAX12B
丄ntchmdf);
intchmdf)
{
intc;
modetmodelsIWU5R;
printfC*e.e706\n1,04Gfl\n2.0260\n3.ei&6\n”);
prirrtf("Pleaseinputyourchoice(o-3):
-);
scanfC^d"!
&c);
switch(c)
{
case0:
Chnod{HfileiBfSIRWXU);b'eak;
case1:
c