Creating Files and Directories

Imran Afzal
A free video tutorial from Imran Afzal
Systems Manager / Engineer / Instructor
4.5 instructor rating • 14 courses • 144,019 students

Learn more from the full course

Linux Crash Course for Beginners - 2020

Linux System Administration and Linux Command Line

05:30:48 of on-demand video • Updated June 2020

  • Linux basic system administration
  • Efficient in basic Linux command line
  • A very well understanding of how Linux works
English [Auto] Creating files and directories and this lesson be real Khowar how we can create files and directories different ways to create files. The first one is the touch the touch command creates a file that is of course an empty file. The second way to create a file is if you are copying an existing file and creating a new file at the destination location and the third way to create a file is through VI command. Vi is our editor which we will be able Khowar in detail later in the lessons but I will cover quickly how we could create a file using vi creating directories. The easiest way to create a directory in the command is M K D R which is make directory. So now let's get into our next machine and we will use every command listed here. As a practice to create files OK the first thing we have to do is to find out what user ID we are logged in as you do. Who am I. And I would tell you you are logged in as yourself and then the second thing you have to know which directory you are in and I am in my home directory. Now I have I will be creating a few files. And as your whole work I want you to create those files and directories as well. The first way to create a file. Here's where I have a list of files that I will be creating We will use the first command to create a file will be touch or touch space. I have here. Jerry hit enter and you hit enter and you get the prompt back. That means your command worked. Now how do we know where is that file. You do. LS mine is now. And you will see here the directory you have is right here. Jerry sorry did not touch the file. Now I want you to create another file. Touch Kramer again check if it's created. Yes it is created. Gerry and Cramer. Now I use the option LS minus L which will list all the files and directories in alphabetical order. If you want to list all the files or directories that are created at. It was Last-Modified you will use LS minus L T R. Which means give you everything by the time rewarder. And in reverse meaning the oldest one on the top and the newest one at the bottom. Then you hit enter. Will see Jerry was the first one that was created followed by the Kramer next one you're are creating is George. How do you verify that file was created. You do lists all these files can be changed or renamed or moved but you'll go to the next set of files to create. I want you to use this time the copy command so I want to use copy. JERRY And then the destination file I want you to be leks to LS by itself here. So what exactly did it copied this GRB file and named it. Lex I want you to do the same thing for Clark. So copy Jerry or Cremer or whichever fall into Clark. Same thing copy Cheri and Lois. Let's verify we have all those files. They go we got all six files. So now three files we created with touch command three files we created with the copy command and the rest of the files will create using vi. Now remember VI is a very tricky so I will only create one file and we will cover the VI later. So be my space Homer. So hit enter. Once you hit enter it will bring you to file. Added to now be very careful what you type in here because you will not be able to get out if you really don't know what you are doing. So at this point I just want you to do shift Colan W as in right queue isn't quite an exclamation point which is all sort of for as. Bang. Hit enter the file. Homework is created. How do you verify it. True. It is my fault here and there you go. The homework file is created. Now the other three files I will create by the touch command. You will notice you don't have to run touch command over and over again. You could run the test command just once and do bar space Lisa Space me or March. So now with this just one command it will create three files. So hit enter. Verify that all three files Bart Marshallese all of them are in this directory. Now the next step I want you to do is create directories within your home directory. Just do PWT just to make sure you are in home directory. Then from here you do m KDE or space. Seinfeld now Derek Krieger's created because you've got to you've got your promp back. How do you wear Abiud unless mindset. TR And you see at the bottom that's where the directory is created. And if you notice some of the Linux distributions also change the color for use a this way it will be easier for you to identify which one is the file or which one is a directory. Same way I wanted to create another directory. K D or Superman. And again you could also do the same way instead of running one command after the other you could just run one command and followed by two different directories. So the second actually have Simpson. Simpson and hit enter. Once you hit and turn into splinter So to hear or see all three directories at the bottom and you have all your files right here the list listed here. So this is the way you create files and directories in your home directory. If you try to create a directory in let's say a slash or somewhere else where you do not have permission it will tell you that this directory that you do not have sufficient rights to create that directory. So let's take the example if you go to CD slash ETSI and I want to create a file here let's call it test 1 2 3 and hit enter. Going to tell you you do not have permission to create that file in there because we don't want slash who owns the slash route owns it and you are not rude. Who are you. You are yourself in this case. I saw again you learned three four commands. Touch copy vi to create files and the last command you learned to create directories is KTAR.