Details of Linux basic command mktemp
- 2020-12-10 01:04:03
- OfStack
mktemp
Create temporary files or directories in a safe way. This command applies to: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1, grammar,
mktemp [Option] [TEMPLATE]
2. List of options
选项 |
说明 |
--version |
显示命令版本信息 |
--help |
显示帮助信息 |
-d | --directory |
创建目录 |
-u | --dry-run |
不要创建任何东西,只要打印1个名字(不安全) |
-q | --quiet |
发生错误的时候不显示提示信息 |
--suffix=SUFF |
附加SUFF到模板中。SUFF不能包含斜杠。如果模板不以X结尾,则使用此选项。 |
--tmpdir[=dir] |
指定临时文件的路径,如果tmpdir后面没有路径,那么使用变量$TMPDIR;如果这个变量也没指定,那么临时文件创建在/tmp目录下。使用此选项,模板不能是绝对名称。与“-t“不同,模板可能包含斜杠,但mktemp只创建最终组件 |
-p DIR |
使用DIR作为前缀 |
-t |
将模板解释为1个相对于目录$TMPDIR(如果设置)的单个文件名组件;否则通过-p指定的目录;或者使用/tmp(-t已经弃用) |
TEMPLATE |
临时文件名,名字中必须包含至少3个字母X。如果没有指定,那么默认是tmp.XXXXXXXXXX |
3, the instance,
1) Create temporary files
[root@localhost weijie]# mktemp wj123.XXXX // Name contains 4 a X
wj123.kpET
You have new mail in /var/spool/mail/root
[root@localhost weijie]# mktemp wj123.XXXXXX // Name contains 6 a X
wj123.oH2o4P
[root@localhost weijie]# ls
1.c wj123.kpET wj123.oH2o4P
2) Create a temporary directory
[root@localhost weijie]# mktemp -d wjtp // Not in the name X
mktemp: There is too little X in the template "wjtp"
[root@localhost weijie]# mktemp -d wjtpxxx // Not in the name X You can see here X It has to be uppercase
mktemp: The template "wjtpxxx" In the X Too little
[root@localhost weijie]# mktemp -d wjtpXXX // Creating a successful
wjtpflR
[root@localhost weijie]# ls -l
The total amount of 4
-rw-r--r-- 1 root root 0 9 month 7 09:11 1.c
-rw------- 1 root root 0 9 month 7 14:47 wj123.kpET
-rw------- 1 root root 0 9 month 7 14:47 wj123.oH2o4P
drwx------ 2 root root 4096 9 month 7 14:50 wjtpflR
3) Create temporary files in /tmp
[root@localhost weijie]# mktemp --tmpdir wj234.XXX //tmpdir No path is specified at tmp create
/tmp/wj234.BNy
You have new mail in /var/spool/mail/root
4) Create a temporary directory under the specified directory
[root@localhost weijie]# mktemp --tmpdir=/weijie wj234.XXX // in tmpdir Created under the specified path
/weijie/wj234.q1C
[root@localhost weijie]# ls
1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR
5) Create with option -ES48en
[root@localhost weijie]# mktemp -u wj123.XXXXXX // use -u options
wj123.dSgIKl
[root@localhost weijie]#ls // You cannot see the temporary file because it was not created
1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR
Added: linux base command
1. Basic command
ls: Lists the files or directories in the current directory
2. ls-a: List all files and directories under the current directory (including hidden files)
3. ls-l: Display file details (long format information view), 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 details of the current file itself
4. cat command: View file information (only view files)
[root @com ~]# cat /etc/passwd: View all user information
[root @com ~]# cat /etc/group: View all user group information
Note: For every user created in Linux, a corresponding user group is automatically generated.
cd command: switch directories
[root@com ~]# cd /etc : Switch to the root directory etc directory
pwd : Displays the directory of the current file
whoami: View the current user
[root@com etc]# whoami : View the current user is root The user
root
6, / : represents the user's root directory
Home directory (host directory)
1) Home directory of administrator user:
[root@com ~]# pwd
/root
2) Home directory of ordinary users:
[java17@com ~]$ pwd
/home/java17
7. Switch user command: su - user name
1) Switch to normal user
[root@localhost weijie]# mktemp -d wjtp // Not in the name X
0
2) Switch to root administrator user
[root@localhost weijie]# mktemp -d wjtp // Not in the name X
1
8. Shut down, restart and clear the screen
Turn off: halt, init 0, shutdown now
Restart: reboot, init6
Clear screen: clear, Ctrl+l
conclusion