In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to use the mktemp command in Linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Mktemp
It is safe to create temporary files or directories. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Mktemp [options] [TEMPLATE]
2. List of options
Option
Description
-- version
Display command version information
-- help
Display help information
-d |-- directory
Create a directory
-u |-- dry-run
Don't create anything, just print a name (not safe)
-Q |-- quiet
No prompt message is displayed when an error occurs
-- suffix=SUFF
Attach SUFF to the template. SUFF cannot contain slashes. Use this option if the template does not end with X.
-- tmpdir [= dir]
Specify the path to the temporary file, and if there is no path after tmpdir, use the variable $TMPDIR;. If this variable is not specified, the temporary file is created in the / tmp directory. With this option, the template cannot be an absolute name. Unlike "- t", templates may contain slashes, but mktemp only creates the final component
-p DIR
Use DIR as prefix
-t
Interpret the template as a single filename component relative to the directory $TMPDIR (if set); otherwise, the directory specified by-p; or use / tmp (- t has been deprecated)
TEMPLATE
Temporary file name, which must contain at least 3 Xs. If not specified, the default is tmp.XXXXXXXXXX
3. Examples
1) create a temporary file
[root@localhost weijie] # mktemp wj123.XXXX / / the name contains 4 Xwj123.kpETYou have new mail in / var/spool/mail/root [root@localhost weijie] # mktemp wj123.XXXXXX / / the name contains 6 Xwj123.oH2o4P [root@localhost weijie] # ls1.c wj123.kpET wj123.oH2o4P
2) create a temporary directory
[root@localhost weijie] # mktemp-d wjtp / / No X in the name
Mktemp: too little X in template "wjtp"
[root@localhost weijie] # mktemp-d wjtpxxx / / there is no X in the name. Here you can see that X must be an uppercase mktemp: there is too little X in the template "wjtpxxx" [root@localhost weijie] # mktemp-d wjtpXXX / / successfully created wjtpflR [root@localhost weijie] # ls-l
Total dosage 4
-rw-r--r-- 1 root root 0 September 7 09:11 1.cRaq RW-1 root root 0 September 7 14:47 wj123.kpET-rw- 1 root root 0 September 7 14:47 wj123.oH2o4Pdrwx- 2 root root 4096 September 7 14:50 wjtpflR
3) create a temporary file in / tmp
[root@localhost weijie] # mktemp-- tmpdir wj234.XXX / / tmpdir does not specify a path, create / tmp/wj234.BNyYou have new mail in / var/spool/mail/root under tmp
4) create a temporary directory under the specified directory
[root@localhost weijie] # mktemp-- tmpdir=/weijie wj234.XXX / / create / weijie/wj234.q1C [root@localhost weijie] # ls1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR under the path specified by tmpdir
5) use the option-u to create
[root@localhost weijie] # mktemp-u wj123.XXXXXX / / using the-u option wj123.dSgIKL [root @ localhost weijie] # ls / / cannot see the temporary file because 1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR was not created
Supplement: linux basic command
1. Basic command
1. Ls: list the files or directories under the current directory
2. Ls-a: lists all files and directories in the current directory (including hidden files)
3. Ls-l: displays the details of the file (view the information in long format), which is equivalent to ll
Ls-hl: displays file details and file size
Ls-al: lists the details of all files and directories in the current directory
Ls-dl: displays the details of the current file itself
4. Cat command: view file information (only files can be viewed)
[root@com ~] # cat / etc/passwd: view all user information
[root@com ~] # cat / etc/group: view all user group information
Note: each user created in the Linux system will automatically generate a corresponding user group.
5. Cd command: switch directories
[root@com ~] # cd / etc: switch to the etc directory under the root directory pwd: display the directory of the current file whoami: view the current user [root@com etc] # whoami: check that the current user is the root user root
6. /: indicates the root directory of the user
Home directory (host directory)
1) Home directory of administrator user:
[root@com ~] # pwd / root
2) the home directory of ordinary users:
[java17@com ~] $pwd / home/java17
7. Switch user command: su-user name
1) switch to ordinary users
[root@com ~] # su-java17 [java17@com ~] $pwd / home/java17
2) switch to root administrator user
[java17@com ~] $su-or [java17@com ~] $su-root Password:
8. Shut down, restart and clear the screen
Shutdown: halt, init 0, shutdown now
Restart: reboot, init6
Clear screen: clear, Ctrl+l
After reading the above, do you have any further understanding of how to use the mktemp command in Linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.