How to Use Mktemp Command on Linux
We generally tend to create many information and folders in the house folder of our Linux techniques. These information and folders can save the information eternally with out the elimination of such information and folders on reboot. Linux got here up with the brand new function to create brief information within the “tmp” folder. These information or folders can be robotically deleted after the reboot and all of the knowledge inside those information or folders might be misplaced. Let’s check out the “mktemp” command within the Linux shell to create the brief information in Ubuntu 20.04 machine.
You wish to make certain that your machine is already up to the moment and upgraded to Ubuntu 20.04 machine. If now not, check out the usage of the “apt” bundle command within the Ubuntu terminal shell in conjunction with the key phrase “update”. Before the whole thing, you want to open up the command-line utility to do all this. The command-line utility will also be introduced with using the task menu at the most sensible left nook of your Ubuntu 20.04 display. Tap on that icon and a seek bar might be opened. Write the identify of a command-line utility as “terminal” and hit the Enter button. It will open your terminal in a couple of seconds.
Let’s check out how the “mktemp” unmarried phrase command works within the shell. So, throughout the question space, now we have written the “mktemp” command and pressed “Enter” for the execution objective. The output might be like “/tmp/tmp.LB1DOVqUPF”. It is a random and brief report created within the “tmp” folder of your machine. The identify of a report may be generated robotically.
Let’s test the “tmp” folder of our machine now. Open it in the course of the report explorer. You can see from the picture beneath that the report tmp.LB1DOVqUPF is generated.
You have noticed that the report has no extension. If you wish to have so as to add some extension on the finish of a brief report, you should upload the “—suffix” key phrase within the mktemp command in conjunction with the extension. The extension should be added throughout the inverted commas. You can see, now we have been the usage of the “.txt” extension to create a textual content kind report throughout the “tmp” folder. After executing this command, the random report “tmp.q0GlvSUC75.txt” with the “.txt” extension is created as consistent with the output.
After opening the “tmp” folder the usage of the report explorer, now we have noticed that the brief textual content report “tmp.q0GlvSUC75.txt” is created within the folder having the “.txt” extension.
This used to be all in regards to the advent of a brief report within the “tmp” folder. Along with the textual content information or random easy information, we will be able to additionally create the brief listing within the “tmp” folder. This listing identify may also be generated randomly i.e. assigned on its own. This “mktemp” command can be utilized with the flag “-d” to create a random listing throughout the “tmp” folder. After the execution of this question, the listing identify “tmp.55ULnaranu” is created within the “tmp” folder as the image demonstrated.
Let’s open the report explorer and navigate against the “tmp” folder of your Ubuntu 20.04 machine as proven beneath. The listing named “tmp.55ULnaranu” will also be noticed within the opened “tmp” folder of our machine proven within the symbol. This is the brief folder and would possibly robotically take away from the machine when you reboot your Ubuntu 20.04 machine.
Same as the straightforward random information, the brief information and directories even have some privileges and restrictions assigned robotically by way of the machine as soon as those are created. Let say, now we have created a brand new brief report “tmp.uhPHOWaabz” with the “mktemp” question within the shell. Now, we will be able to take a look at the assigned privileges to this newly created brief report with the checklist command. So, we need to use the key phrase “ls” in conjunction with the “-al” flag in conjunction with the site of the report within the “tmp” folder.
The end result displays that the random report has handiest “read” and “write” privileges for the present consumer i.e., “saeedraza” and has no assigned privileges for the gang and different customers. The output may be appearing the consumer and staff it belongs to in conjunction with its advent date and time. This used to be in regards to the easy brief information.
Now, we can take a look at the similar factor for the brief directories. Therefore, you want to create a brief listing within the “tmp” folder the usage of the “mktemp” command with the “-d” flag. The listing is now generated within the “tmp” listing. The checklist command is applied to test the privileges assigned to the brief listing simply created throughout the “tmp” folder. The “-ld” flag is used throughout the checklist command along the listing trail as beneath.
The listing has learn, write, and execution rights to the present consumer i.e., saeedraza. While the opposite customers and teams haven’t any rights to learn, write and execute this listing. The output introduced within the photographs displays the listing’s identify, date, time on which it’s created. Also, it displays the gang and consumer identify it belongs to.
The mktemp is not just used to create the brief information and directories within the accounts “tmp” folder however the “home” folder as neatly. For this, you want so as to add the report identify in conjunction with greater than 3 “XXX” on the finish. It will in the end create your report “newcHs” in the house folder. The “XXX” characters will robotically get replaced by way of robotically generated characters of the machine. The checklist command is used to checklist all of the information and directories of the present house of our Ubuntu 20.04 machine. The “newcHs” report is proven within the “home” listing.
To create a listing in the house root folder, we wish to upload the “-d” flag throughout the “mktemp” folder with the listing identify having “XXX” at its finish. The listing “newoC9” is generated. The checklist “ls” question is appearing that the listing “newoC9” is in the house folder.
Conclusion
We have applied the running of the “mktemp” command in Ubuntu 20.04. We have used it to create brief information and folders within the “tmp” folder in conjunction with some extensions. We have additionally taken a have a look at learn how to create the brief report and listing in the house folder of our machine.