1 00:00:00,000 --> 00:00:01,800 [No audio] 2 00:00:01,800 --> 00:00:05,490 Creating files and directories. In this lesson we 3 00:00:05,490 --> 00:00:08,580 will cover how we can create files and 4 00:00:08,580 --> 00:00:12,480 directories, different ways to create files. The 5 00:00:12,480 --> 00:00:16,230 first one is the touch. The touch command creates 6 00:00:16,230 --> 00:00:21,150 a file that is, of course an empty file. The 7 00:00:21,150 --> 00:00:24,930 second way to create a file is if you are copying 8 00:00:24,930 --> 00:00:30,210 an existing file and creating a new file at the 9 00:00:30,210 --> 00:00:33,630 destination location. And the third way to create 10 00:00:33,630 --> 00:00:38,220 a file is through vi command. vi is our editor, 11 00:00:38,520 --> 00:00:41,550 which we will cover in detail later in the 12 00:00:41,550 --> 00:00:44,490 lessons, but I will cover quickly how we could 13 00:00:44,490 --> 00:00:49,950 create a file using vi. Creating directories, the 14 00:00:49,980 --> 00:00:53,670 easiest way to create directory in the command is 15 00:00:53,730 --> 00:00:58,800 mkdir which is make directory. So now let's get 16 00:00:58,800 --> 00:01:02,550 into our Linux machine, and we will use every 17 00:01:02,700 --> 00:01:07,410 command listed here as a practice to create 18 00:01:07,410 --> 00:01:10,710 files. Okay the first thing we have to do is to 19 00:01:10,710 --> 00:01:14,100 find out what user id we are logged in as. So you 20 00:01:14,100 --> 00:01:17,970 do whoami, and it will tell you you are logged in as 21 00:01:17,970 --> 00:01:21,030 yourself. And then the second thing you have to 22 00:01:21,030 --> 00:01:26,400 know which directory you are in and I am in my 23 00:01:26,400 --> 00:01:31,860 home directory. Now I have, I will be creating a few 24 00:01:31,860 --> 00:01:35,850 files and as your homework I want you to create 25 00:01:35,850 --> 00:01:40,020 those files and directories as well. The first way 26 00:01:40,440 --> 00:01:43,230 to create a file, here I have a list of 27 00:01:43,230 --> 00:01:44,760 files that I will be creating. 28 00:01:44,760 --> 00:01:50,760 [No audio] 29 00:01:50,760 --> 00:01:53,490 We will use the first command to create a file 30 00:01:53,490 --> 00:01:59,760 will be touch, okay. touch space, I have here jerry, 31 00:02:00,810 --> 00:02:04,320 hit enter. When you hit enter and you get the prompt 32 00:02:04,320 --> 00:02:08,460 back that means your command worked. Now how do we 33 00:02:08,460 --> 00:02:15,660 know where is that file? You do ls -l, and you 34 00:02:15,660 --> 00:02:20,340 will see here the directory you have is right here, 35 00:02:21,570 --> 00:02:25,800 jerry. Sorry not directory, the file. Now I want 36 00:02:25,800 --> 00:02:34,230 you to create another file, touch kramer. Again 37 00:02:34,230 --> 00:02:38,550 check if it's created. Yes it is created, jerry and 38 00:02:38,550 --> 00:02:42,150 kramer. Now I use the option ls -l which will 39 00:02:42,150 --> 00:02:45,690 list all the files and directories in alphabetical 40 00:02:45,720 --> 00:02:48,990 order. If you want to list all the files or 41 00:02:48,990 --> 00:02:52,830 directories that are created, and when it was last 42 00:02:52,830 --> 00:02:58,140 modified, you will use ls -ltr which means 43 00:02:58,290 --> 00:03:01,920 give you everything by the timely order, and in 44 00:03:01,920 --> 00:03:05,250 reverse meaning the oldest one at the top and the 45 00:03:05,250 --> 00:03:08,730 newest one at the bottom. Then you hit enter, you 46 00:03:08,730 --> 00:03:11,910 will see jerry was the first one that was created, 47 00:03:11,940 --> 00:03:13,525 followed by the kramer. 48 00:03:13,525 --> 00:03:15,525 [No audio] 49 00:03:15,525 --> 00:03:19,711 Next one we are creating is george. 50 00:03:19,711 --> 00:03:22,201 [No audio] 51 00:03:22,201 --> 00:03:25,380 How do you verify the file was created? You 52 00:03:25,380 --> 00:03:27,924 do ls -l. 53 00:03:27,924 --> 00:03:33,600 Now these files can be changed or renamed or 54 00:03:33,600 --> 00:03:37,500 moved. But we'll go to the next set of files to 55 00:03:37,500 --> 00:03:41,430 create I want you to use this time to copy command. 56 00:03:41,430 --> 00:03:47,820 So I want you to use cp jerry, and then the 57 00:03:47,820 --> 00:03:53,100 destination file I want you to be lex. Do ls minus 58 00:03:53,100 --> 00:03:57,450 ltr. So what exactly did it copy? This jerry file and 59 00:03:57,450 --> 00:04:02,340 named it lex. I want you to do the same thing for 60 00:04:03,390 --> 00:04:09,450 clark. So cp jerry or kramer or whichever file 61 00:04:09,810 --> 00:04:12,650 and do clark. 62 00:04:13,650 --> 00:04:19,957 Same thing cp jerry and lois. 63 00:04:21,015 --> 00:04:23,880 Now let's verify we have all those files. There you go. 64 00:04:23,880 --> 00:04:26,550 We got all six files. So now three files we 65 00:04:26,550 --> 00:04:30,120 created with touch command, three files we created 66 00:04:30,540 --> 00:04:34,770 with the copy command, and the rest of the files 67 00:04:34,770 --> 00:04:38,820 we'll create using vi. Now remember, vi is a very 68 00:04:38,820 --> 00:04:43,410 tricky, so I will only create one file and we will 69 00:04:43,410 --> 00:04:50,130 cover the vi later. So vi space homer. So hit 70 00:04:50,160 --> 00:04:54,450 enter. Once you hit enter, it will bring you to 71 00:04:54,630 --> 00:04:59,760 file editor. Now be very careful what you type in 72 00:04:59,760 --> 00:05:02,520 here, because you will not be able to get out if 73 00:05:02,520 --> 00:05:05,100 you really don't know what you are doing. So at 74 00:05:05,100 --> 00:05:12,240 this point, I just want you to do Shift colon, w 75 00:05:12,240 --> 00:05:16,800 as in write, q as in quit, and exclamation point, 76 00:05:17,160 --> 00:05:23,580 which is also referred as bang, hit Enter. The 77 00:05:23,580 --> 00:05:27,150 file homer is created. How do we verify it? 78 00:05:27,180 --> 00:05:30,030 Let's do ls -ltr, and there you go, the 79 00:05:30,030 --> 00:05:33,270 homer file is created. Now the other three 80 00:05:33,270 --> 00:05:37,110 files, I will create by the touch command. Now you 81 00:05:37,110 --> 00:05:39,420 will notice, you don't have to run touch command 82 00:05:39,420 --> 00:05:41,700 over and over again, you could run the touch 83 00:05:41,700 --> 00:05:46,680 command just once and do bart space lisa space 84 00:05:46,710 --> 00:05:50,490 marge, marge. So now with this just one command, 85 00:05:50,520 --> 00:05:55,800 it will create three files. So hit enter. Verify 86 00:05:55,920 --> 00:05:59,820 all three files bart, marge, lisa, all of them are 87 00:06:00,270 --> 00:06:05,820 in this directory. Now, the next step I want you 88 00:06:05,820 --> 00:06:09,930 to do is create directories within your home 89 00:06:09,930 --> 00:06:14,280 directory. So just do pwd just to make sure you 90 00:06:14,280 --> 00:06:21,614 are in home directory. Then from here, you do mkdir 91 00:06:21,614 --> 00:06:25,785 space seinfeld. 92 00:06:25,785 --> 00:06:28,521 [No audio] 93 00:06:28,521 --> 00:06:30,630 Now the directory is created 94 00:06:30,630 --> 00:06:32,760 because you got, you got your prompt back, how do 95 00:06:32,760 --> 00:06:35,880 you verify it, ls -ltr. And you'll see at 96 00:06:35,880 --> 00:06:36,857 the bottom, 97 00:06:38,339 --> 00:06:41,759 that's where the directory is created. And if you 98 00:06:41,759 --> 00:06:44,939 notice, some of the Linux distributions also 99 00:06:44,939 --> 00:06:47,849 change the color for you. So this way, it will be 100 00:06:47,849 --> 00:06:51,599 easier for you to identify which one is the file 101 00:06:51,629 --> 00:06:55,799 or which one is a directory. Same way I wants you to 102 00:06:55,799 --> 00:07:01,649 create another directory mkdir superman, and 103 00:07:01,649 --> 00:07:05,339 again, you could also do the same way. Instead of 104 00:07:05,339 --> 00:07:08,969 running command one command after the other, you 105 00:07:08,969 --> 00:07:12,839 could just run one command and followed by two 106 00:07:12,839 --> 00:07:15,599 different directories. So the second directory we 107 00:07:15,599 --> 00:07:19,052 have is simpsons, simpsons. 108 00:07:19,052 --> 00:07:22,907 [No audio] 109 00:07:22,907 --> 00:07:24,719 And hit enter. Once you 110 00:07:24,719 --> 00:07:28,739 hit enter, so ls -ltr, see all three 111 00:07:28,739 --> 00:07:32,369 directories at the bottom. And you have all your 112 00:07:32,369 --> 00:07:38,609 files right here, listed here. So this is the way 113 00:07:38,609 --> 00:07:41,399 you create files and directories in your home 114 00:07:41,399 --> 00:07:46,319 directory. If you try to create a directory in 115 00:07:46,319 --> 00:07:50,999 let's say, slash or somewhere else where you do 116 00:07:50,999 --> 00:07:54,329 not have permission, it will tell you that this 117 00:07:54,329 --> 00:07:59,819 directory, you don't have sufficient rights to 118 00:07:59,819 --> 00:08:01,619 create that directory. So let's take the example 119 00:08:01,619 --> 00:08:04,829 if you go to cd slash etc, and I want to create 120 00:08:04,829 --> 00:08:09,839 a file here, let's call it test123 and hit enter. 121 00:08:09,869 --> 00:08:12,809 It's going to tell you, you do not have permission 122 00:08:13,109 --> 00:08:16,739 to create that file in there because we don't own 123 00:08:16,829 --> 00:08:20,909 slash. Who owns the slash? root owns it, and you are 124 00:08:20,909 --> 00:08:26,249 not root. Who are you? You are yourself in this case 125 00:08:26,249 --> 00:08:30,989 iafzal. Again, we learned three, four commands 126 00:08:31,019 --> 00:08:34,948 touch, cp, vi to create files, and the last 127 00:08:34,948 --> 00:08:38,308 command we learned to create directories is mkdir. 128 00:08:38,308 --> 00:08:41,301 [No audio]