- [Instructor] Welcome to the ninth video of section two:
Temporary File Naming and Random Numbers.
In the previous video, we've learned
about sorting unique and duplicates.
In this video, we will learn how
to generate standard filenames for temporary data.
While writing shell scripts, we often need
to store temporary data.
The most suitable location to store temporary data
is slash temp,
which will be cleaned out by the system on reboot.
Let's see how to do it.
Perform the following steps to create a temporary file
and perform different naming operations on it.
Create a temporary file as follows.
This will create a temporary file and print its filename,
which we store in dollar filename in this example.
To create a temporary directory,
use the following commands.
This will create a temporary directory
and print its filename,
which we store in dollar directory name, in this example.
To just generate a filename
without actually creating a file or directory, use this.
Here, the file will be stored in dollar temp file,
but the file won't be created.
To create the temporary filename according to a template,
use
Now we'll see how the function works.
The make temp command is very straightforward.
It generates a random file and returns its filename,
or directory name, in the case of directories.
When providing custom templates,
X will be replaced by a random alphanumeric character.
Also note that there must be at least three X characters
in the template for make temp to work.
Awesome!
We've successfully learned about temporary file naming
and random numbers.
In the next video, we'll learn how to split files and data.