In this lecture, I'm going to show you how to create a new files and directories. To create a new file 1
in Linux, you have to use the touch command. 2
We've already discussed it in a previous lecture. 3
So now we'll just recap it quickly. 4
The touch command takes as argument one or more files. If those files already exist 5
touch will update the files timestamps to the current system time. 6
But if the files do not exist, then touch will create them. 7
touch report.txt 8
touch logs 9
Since the files didn't exist, touch has created them. 10
If I ran it again with the same files as arguments, then touch will set the files timestamps to the current 11
time. 12
Let's see the timestamps. 13
These are the files timestamps, and I'm running the touch command again. 14
touch, the first file and the second one. 15
And stat report.txt and loogs. 16
See how it updated the atime, mtime and ctime. 17
Note that you can change atime and mtime individually as well. 18
See the previous lecture where I've gone deeper into this, if you feel the need. And if you want to 19
create a new file that contains a white space in its name, then put the whole name between double quotes. 20
So touch, in user's home directory, 21
it's the current directory anyway, and between double quotes 22
learning Linux 23
This is the name of the file, it contains more white spaces! However, Linux is not recommended to 24
have file names that contain white spaces. 25
Use an underscore instead, if you wish a more readable name. 26
So a more appropriate name would be something like this: 27
Much better! 28
Also remember that in Linux case matters, so a file called Report.text, which starts with 29
a capital R, is a complete new file; or touch report.txt There are three files called report.txt 30
in the current directory, only the capitalization differs. 31
It's important to note that the user executing this command must have enough permissions to create the 32
file in the parent directory or he will get a permission denied error. 33
For example, I'm logged in as student, a non privileged user, and if I try touch/etc/abc 34
I've got a permission denied error. 35
This non-privileged user is not allowed to create the file called abc in /etc 36
Let's move on and see how to create a new directories using the mkdir command. 37
Mkdir comes from “make directory”. 38
This is the command, and it's syntax is mkdir, some options and some directories. Let's see an example. 39
In the current working directory, I'm going to create a directory called dir1. 40
mkdir dir1 41
This is the new director. 42
In case you want mkdir to display some details about the operation is performing, then add the 43
- v option; -v comes from verbose: mkdir -v dir2 44
It has displayed this message and created the directory. 45
And if you want to create more directories in one command, then give all directories, you want to 46
create as arguments. 47
So mkdir dir3 dir1/dir10 it means it will create a new directory called dir10 48
inside dir1 and /tmp/tmp_jr the 3rd directory. 49
In this example, I've created three directories at once. 50
dir3 51
dir10 inside dir1 and another directory inside /tmp 52
Now, let's suppose I want to create a complete directory structure, and to do that I run mkdir, let's 53
say first, second, third. 54
So I want to create a new directory called first in the current directory, inside first, another directory 55
called second, and inside it, a directory called the Third. 56
Note that none of these directories exists. 57
If I'm hitting enter, I'm getting an error. 58
Cannot create a directory, no such file or directory. 59
Maybe it's weird, but mkdir wanted to create the directories from right to left. 60
So when it wanted to create a directory called Third, this one, it noticed that its parent directory called 61
Second didn't exist. To solve this issue just at the -poption, which comes from parents. 62
And it will make the parent directories as needed. 63
I am adding the -p option 64
between the command name and its arguments. 65
And it has created all three directories. 66
See how they look like: -p option is also good when the directory already exists and you don't want 67
an error. In this example 68
there is already a directory called dir1 in the current working directory 69
I've just created it. 70
If I try to make it again, I'll get an error. 71
mkdir dir1n 72
Cannot create directory dir1: file exists. 73
Remember that a directory is a special type of file. 74
But if I add the- p option, there will be no error. 75
OK, this all about creating files and directories. 76
Thank you.