Self-study Linux shell14.3-create temporary files

Source: Internet
Author: User
Tags tmp folder

Click Back to learn the path of the Linux command line and shell script

14.3-Create temporary file mktemp
    • The Linux system retains a special directory location for temporary file use. Linux uses the/tmp directory to process files that do not need to be persisted.
    • Most Linux distributions have system configurations that automatically remove any files from the/tmp directory at startup.
    • Any user account on the system has permission to read and write to files in the/tmp directory.
    • Create temporary file: Themktemp command makes it easy to create a unique temporary file in the/tmp folder . The shell creates the file but does not use the default Umask value. Instead, it only assigns read and write permissions to the file owner and uses the user as the owner of the file. After you create a file, you can script full permission reads and writes to the file, but no one else has access to it.

Mktemp command:

    • [FileName parameter] The filename parameter must be a file name. XXXXXX format
    • -T forces temporary files to be created in the system's TEMP directory/tmp
    • -D Create a temp directory instead of a temporary file

Example 1:
By default, Mktemp creates files in the local directory. To create a temporary file in a local directory using the Mktemp command, you only need to specify a file name.
The module includes a text file and 6 xxxxxx appended to the file name.
The MKTEMP command replaces 6 xxxxxx with a 6-character code to ensure uniqueness of the file name in the directory.

Example 2:

The-t option forces mktemp to create temporary files in the system's/temp folder.
However, when you use this option, the Mktemp command returns the full path name used to create the temporary file, not the file name.
Because the mktemp command returns the full pathname, temporary files can be referenced from any directory on the Linux system, regardless of where the system places the temporary directory.

Example 3:

The-D option lets the mktemp command create a temporary directory instead of a file.

Self-study Linux shell14.3-create temporary files

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.