Perl learning notes 13 objective operations

Source: Internet
Author: User
Tags glob

1. Change the Directory

Chdir "/etc" or die "can't chdir to '/etc '! \ N ";

If the parameter is omitted, the system returns to the user's home directory, which is the same as that of CD;

2. wildcard file name

My @ all_files = glob "*"; # files starting with a dot are not included.

My @ pm_files = glob "*. PM ";

Multiple matching modes are separated by spaces: My @ files = ". **"; # All files can be matched, including

3. Fill in another syntax for file names

My @ files = <* >;## is equivalent to: My @ files = glob "*";

Supports variable interpolation: My $ dir = "/etc"; my @ dir_files = <$ DIR/* $ DIR/. *>;

Angle brackets support configuration of file handles and file names. Perl will determine which operation to choose. If it is an identifier, it will be read as a file; otherwise, it will be processed according to the file name Configuration:

4. Directory handle

Directory handle can be opened (opendir), read (readdir, read as file name), close (close );

A directory handle is a low-level operator that only Returns basic information and requires additional processing.

5. delete an object

Unlink "file1", "file2", "file3"; # The number of successfully deleted files returned.

Cannot be used to delete directories;

Delete multiple files at a time: unlink glob "*. O ";

The permission to delete a file is independent of the permission of the file itself, and depends on the permission of the directory where the file is located. Therefore, a file that cannot be read, written, or executed may also be deleted;

6. Rename an object

Rename "old", "new ";

Achieve effects similar to MV: Rename "/home/place/file1" "file2"

7. Links and files

Hard link:

This will increase the number of links to a file. As long as one link exists, the file exists.

You cannot increase the number of links to a directory or link to a volume.

Soft link (symbolic link ):

It does not increase the number of links to files and can point to non-existing files.

Position to which the symbolic link points:

8. Create and remove Directories

Create a directory:

 

0755 is the permission, and strings cannot be directly interpreted as Octal numbers. The OTC function is required:

Remove directory:

Only one directory can be deleted at a time, and it must be an empty directory. If it is not an empty directory, you can use unlink to delete it:

$: Current process number.

If there are subdirectories in the directory, unlink will fail, resulting in rmdir failure. File: rmtree in the path module provides a complete solution.

9. Modify permissions

Chmod 0755, "file1", "file2 ";

10. Change the Affiliation

User identifiers and group identifiers must be specified in the form of digits. If you do not know, you can use the following method:

11. Modify the timestamp

The third timestamp ctime must be set to now. No function can modify it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.