Skip to Content
Perl语言入门
book

Perl语言入门

by Randal L. Schwartz, brian d foy, Tom Phoenix
August 2018
Beginner to intermediate
382 pages
7h 14m
Chinese
Southeast University Press
Content preview from Perl语言入门
248
13
修改权限
Unix
chmod
命令可用来修改文件或目录的权限。
Perl
里对应的
chmod
函数也能进
行同样的操作:
chmod 0755, 'fred', 'barney';
和许多其他操作系统的接口函数一样,
chmod
会返回成功更改的条目数量。如果只提
供了一个参数,它会在失败时将
$!
设成合理的错误信息。第一个参数代表
Unix
的权
限值(即使在非
Unix
Perl
版本里也一样)。这个值通常会写成八进制形式,理由
和前面介绍
mkdir
时相同。
Unix
chmod
命令能接受用符号表示的权限(例如
+x
go=u-w
),但是
chmod
函数
并不接受这类参数。
除非你从
CPAN
安装了
File::chmod
模块,这个模块能使
chmod
操作符升级,
从而支持符号表示的权限值。
修改文件属主
只要操作系统允许,你可以用
chown
函数修改一系列文件的属主以及其用户组。属主
和用户组会被同时更改,并且在指定时必须给出数字形式的用户标识符及组标识符。
比如:
my $user = 1004;
my $group = 100;
chown $user, $group, glob '*.o';
如果要处理的不是数字,而是像
merlyn
这样的字符串呢?答案很简单,只要
getpwnam
函数将用户名转换成用户编号,用相应的
getgrnam
函数把用户组名转换
成组编号:
defined(my $user = getpwnam 'merlyn') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

计算机科学导论:跨学科方法

计算机科学导论:跨学科方法

罗伯特 塞奇威克, 凯文 韦恩
Perl语言入门(第8版)

Perl语言入门(第8版)

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787564177911