Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > 老三篇之unix系统基础2
【标  题】:老三篇之unix系统基础2
【关键字】:unix
【来  源】:http://blog.chinaunix.net/article.php?articleId=15955&blogId=4298

老三篇之unix系统基础2

Your Ad Here 老三篇之unix系统基础2

mv             

Change the name of a file or directory

$mv  f1  file1 在当前目录下将文件f1重命名为file1

$mv  file1  memo 将文件file1移到memo目录下。

$mv  f2  memo/file2 将文件f2移到memo目录下,重命名为file2

当移动多个文件时,目的地必须是一个目录。

$mv  note  remind  memo

当源为目录时,该目录被命名为目标目录名。

$mv  note  letter

在默认的情况下,mv将移动或重命名现存的文件——不会作任何提示!

ln               

Create another name for a file

ln file new_file          Link to a file

ln file [file…] dest_dir      Link files to a directory

rm              Remove a file

常用选项:

-f 强制性删除被指定的文件,即使出现错误,也不会通知用户。

-r 递归性删除命令行中指定目录的内容。

-i 询问性或交互性的模式,要求用户 确认是否删除。y表示同意,n表示不同意。按return等同于不同意。

 

 

文件名的格式要求

最长为14个字符

如果支持长文件名,最长为255个字符。

通常包含字母(a-z A-Z)数字(0-9)点(.)连字符(-)和下划线(_

不能包含在文件名中的为空格,前斜杠,*<,>,\,$,|

 

 

文件类型

-普通文件

d目录

l 符号连接文件

n网络特殊文件

c字符设备文件(终端,打印机)

b块设备文件(磁盘)

p 命名管道(一个供进程间通信的管道)

 

 

文件访问权限

File Permissions and Access

Access to files is dependent on a user’s identification and the permissions associated with a file .This module will show how to

Permissions                       Understand the read,write,and execute access to a file

ls(ll,ls -l)                            

Determine what access is granted on a file

chmod                             

Change the file access

修改文件的权限例子

$ls –l f1

-rw-r--r--  1  user3  class 37  Jul  24  f1

$chmod g=rw,o=f1

$ls -l f1

-rw-rw----  1  user3  class  37  Jul  24    f1

$ls -l f2

-rw-rw-rw-  1  user3  class  37  Jul  24    f2

$chmod u+x,g=rx,o-rw  f2

$ls -l f2

-rwxr-x---  1  user3  class  37  Jul  24  11:08  f2

可以用mesg  n 命令禁止其他用户向你的终端发送消息。每个终端都有一个设备文件,负责拥护和计算机之间的通信。在这个例子中,假设这个设备文件是/dev/tty0p1

$ls  -l /dev/tty0p1

crw--w--w-  1  bin  bin  58  0x000003 Feb  15     /dev/tty0p3

$mesg  n

$ls  -l  /dev/tty0p1

crw-------  bin  bin  58  0x000003 Feb  15    /dev/tty0p3

即使禁止了别人向你发送消息,系统管理员仍然可以向你的终端发送消息。

chmod 还支持用数字(十进制)

read---4

write---2

execute---1

$chmod  640  filename

如果取消一个文件的所有权限,用chmod  000 file

umask                             

 Change default file access

$umask  [-S] [mode] User file-creation mode mask.

Example:

                                    user   grop   other

default permissions:                    rw-    rw-    rw-

set default permissions:                  rw-   r--     ---

$umask  g=r,o=

使用-S选项将以标志格式显示出目前创建文件时的默认模式的掩码值。-S选项和标志格式在Bourne shellC shell中没有得到支持。

chown                              

Change the owner of a file.

Example:

$id

uid=303(user3),gid=300(class)

$cp  f1  /tmp/user2/f1

$ls  -l  /tmp/user2/f1

-rw-r-----  1 user2  class  3967  Jan 24    f1

$chown  user2  /tmp/user2/f1

$ls  -l  /tmp/user2/f1

-rw-r-----  1 user2  class  3967  Jan  24    f1

Only the owner of a file (or root)can chane the ownership of the file.

chgrp                               

Change the group of a file

Example:

$id

uid=303(user3),gid=300(class)

$ls  -l  f3

-rw-r-----  1  user3  class 3967  Jan 24    f3

$chgrp  class2  f3

$ls  -l  f3

-rw-r-----  1  user3  class2  3967  Jan 24    f3

$chown  user2  f3

$ls  -l  f3

-rw-r-----  1  user2 class2 967  Jan 24    f3

su                                  

Switch your user identifier

Example:

$ls  -l  /usr/local/bin/class_setup

-rwxr-x---  1  class_admin  teacher  3967  Jan 24  class_setup

$id

uid=303(user3),gid=300(class)

$su  class_admin

Passwd:

$id

uid=400(class_admin),gid=300(class)

$/usr/local/bin/class_setup

$

log out of su session

$Ctrl+d

su  -username

系统有一些配置文件构造了一个对话过程。当发出命令su  username时,对话过程的特征还是跟以前一样。如果想让对话过程具有与切换后的用户标示相关联的特征,用连字符(-

选项:su  -username

newgrp                              

Changes the group ID

Example:

$ls –l /usr/loca/bin/clas_setup

-rwxr-x---  1  class_admin  teacher 3967  Jan  24   class_setup

$id

uid=303(user3)  gid=300(class)  groups=33(teacher)

$newgrp  teacher

$id

uid=303(user3)  gid=33(teacher)

$/usr/local/bin/class_setup

$newgrp

return to login group status

$newgrp  other

sorry

注释:

user3没有访问文件/usr/local/bin/class_setup的权限,因为他开始是组class的成员.由于系统管理员已经赋予user3参加teacher组的权利,user3可以用newgrp  teacher 切换到teacher.这时他可以运行这个程序,这个程序可由teacher组的任何成员执行,user3不能修改这个程序的内容,只有class_admin可以写class_setup这个程序.当他完成之后,newgrp可以恢复其原先的组身份.

/etc/group文件样本

       teacher::33:class_admin,user3

       class::300:user1,user2,user3,user4,class_admin

touch                               

Update Timestamp on File

touch命令可以用来创建一个新的空白文件。如果被指定的文件已经存在,touch命令仅仅更新文件的时间戳(chuo

touch命令有以下选项:

-a time   将文件的访问时间改为。

-m time   将文件的修改时间改为。

-t time   使用指定的time,而不是当前时间。

-c   如果该文件不存在,不要创建这个文件。

touch一个实例

$touch  test_file1

$ls  -l   test_file1

-rw-rw-rw-   1  user3  class  0  Jul 24 test_file1

$umask  a-rwx,u=rw,g=r(或者umask 137)

$umask -S (或者umask)

u=rw,g=r,o=

$touch  test_file2

$ls  -l  test_file2

-rw-r-----  user3  class  0  Jul 24 test_file2

 

 

Access Control Lists(访问控制列表)

lsacl  filename

list the ACL for a file

chacl ACL filename

change the ACL for a life

Example:

$lsacl  funfile

(user3.%,rw-) (%.class,r--) (%.%,r--) funfile

$chacl  “user2.class=rw,%.%-r”  funfile

$lsacl funfile

(use2.class,rw-) (user3.%,rw-) (%.class,r--) (%.%,---)  funfile

$chacl  -d  “user2.class”  funfile

$ll  funfile

rw-r-----  1 user3  class  3081  May  28    funfile

$lsacl  funfile

AIX学习笔记:【上一篇】
今天用vmware安装好了Freebsd!:【下一篇】
【相关评论】
没有相关评论
【发表评论】
姓名:
邮件:
随机码*
评论*
      
|  首 页  |  版权声明  |  联系我们   |  网站地图  |
CopyRight © 2004-2007 软讯网络 All Rigths Reserved.