Unix & Linux Training Crash Course | How to create file & Directory in Unix & Linux Unix Beginners

Unix  & Linux Training  Crash Course | How to create file & Directory in Unix & Linux Unix Beginners

Show Video

this conference will now be recorded okay so next we'll start with some file handling command some very very basic level of commands already we did in last two classes the first two classes to understand about unix linux operating system all those things we did so whatever will do our work in lineups environment linux operating system everything will be highly reactive command ej file script dj file program is a file then any command we are writing that is everything is file only so first we can now start how to create a file and how to create the directory so before that what should be the file file name what kind of name we can give which is the better approach already we discussed in last class now practically we'll use all those okay so first we can create about directly then we can go for the file okay so that i'm going here only increasing the size okay so for creating file first we can go for creating file create directory as we can see create directory so directory means what directory is a container this directory each container which can keep the subdirectory or files so under one directory we can keep another directory also under that another directory like that hierarchy will be there or we can keep the files also file can contain data directory will not contain data directory will contain another directory or files it will keep so for creating the directory what is the command mkdir mkdir is the command name for creating the directory so the commands are mkdir for creating directory mkdir remove directory rmdia okay so create directory remove directory first we will do this what is the syntax mkdir we can create some directory name now where we are currently present so where we are currently present here pwd if you will it is displaying some path so in this path we are currently present now mkdiff is the c like that we can give so first we can give one directory then again we can create multiple directory so it is not mandatory that capital letter we can give a small letter we can give anything we can give so just i am giving capital letter yes that doesn't mean that capital letter also only you can give you can give test one a directory one anything you can give so these are two directories how to create so under our current working directory we can create mkdir exists so which is already present that it will not create again with same name in the same path so we can try with another name b b is also exist another name we can try c okay c also actually okay we can do one thing which are exist we can see first a b c d these are exist so we can remove them first r m d i r e b c d removed now i can check those are not available now we can create mkdir similarly now again multiple directory we can create mkdir so what it is saying a is already exist so if a is already exist then it will not create again so which are not exist that it will create b c d e f it is not exist so it will create now already we have given it is created except a it will cls bcdef created so in this way individual directory we can create so multiple directories at a time also we are able to create single directory at a time also we are able to create and how to delete all those rmdir rmdir is the command name a means a will be deleted rmdir is the command name b c d f like that we can so those will be delete now we can remove so these are empty directory create directory so mkdir of command will create empty directory empty directory rmdir command will remove empty directory if nothing is present under that no content node files nothing is present then it will remove then it will create so we create empty directory now we can remove empty directory rm dier single empty directories a can remove now is gone similarly we can give b c single directory multiple directory with empty we created we deleted it will not go into any recycle bin or anything in unix line of separating system recycle bin panda is not there so if we are deleting means permanently it will delete so before delete you can think for five times or two times double check you cannot revert back if it is deleted okay now recursive structure also we can create m kdir k under that b under that c under that d under that e like that we can create so b directory will be project under a directory so here all are in same path but here all learning not same path in our current directory a will create under that b c will be present under b d will be present under c e will be present under d so this one and this one both are not same so this is called as a recursive structure so for recursive structure if you are creating minus p parameter we have to then it will create recursive structure or tree structure tree or recursive or hierarchy now we can create this mkdir a slash b slash c slash d slash e like that it is throwing error no such filer directory so what to do minus p parameter we have to give then only recursive structure it will create now no error message so it is created um if we say i want yeah sorry i'm getting charged so you know the first um before make directory bc um sorry before you said mcdonald's three bbc e we already quitted and make the h3a and then why is it that i said file doesn't exist when he said creator of that query abcdef no any name you can give just i have given some sort name you can give directory one you can give your name also you can give test you can give one you can give any country name us uk any name yeah but maurice what i'm saying is that we already have a directory before that a before so why when you now say make directory abc again so why did he say file doesn't exist because we already have a file with um a if you go if you go home okay uh yeah so at that time a was there already it was not allowing to create we have checked realities are exist or not yes really these are referenced a b c so same path we cannot create after that we removed first error dif abcd although i removed now these are not available now we created facebook mkdir a a created mkdi or abcdef again a is created here again a will not create so file exists it is swing but rest of the things are not present i get it now thank you okay all right yeah that's fine so here abcde in recursive structure it is created and if you will give ls then only a you can able to see so in this current directory under this only it is present a directory other things are not present directly under a that is present so how we can see ls under a which is present that we can ask for lsa we can give so we can see b similarly ls a under b is there again us so we can see c under that c we can see under that d we can see e under that e nothing is there so up to this level we are able to see if we want to see all the recursive structure ls minus star on that day we do already did on the demo session first session minus r so recursively it will display so which are directly present under our current working directory these are the list after that a under b a b under c abc under t a b c d under e and after that nothing that is last so recursively everything is displayed or one by one also we can see so one by one is not the good approach this then this then this then this this is not the good approach lengthy process that is how many times you can do so better ls minus r if you will do everything at a time it will display go through and understand all these are present under a depth wise directly indirectly recursively revise hierarchy while everything is displayed so in this way we can create recursive structure of the directories also and how to remove the recursive structure of directory input tool just copy this how to copy select means copy now right click means paste this is very easy one so here rmdir we can give now this is removed so we created with the three structure recursive structure hierarchy structures using this and same thing we can remove also by using this okay so all these are empty directory we are not keeping any file with any data or content or anything if file will be mixed here the command will be changed only directory then only mkdir or mdir files should not combine here purely directory direct no file nothing so one kind is single directory multiple directory in same path now recursively now some sequence name of directory also we can get how to create mkdir then suppose we want to create dir1 dir2 dir3 dir4 this kind of names so if three four names are there then that is fine we can type but if thousand of names are there like this then what to do if you will type all those thousand of names it will take a lot of time here's some sequence is there dir is common d-i-r d-i-r d-i-r only last number is changing 1 2 3 4 like that so instead of writing this we can write in another way or it can be anything so it is not like that 1 2 3 4 here we can give 10 here we can give 22 here we can give 35 here we can give 48 this kind of lamps so everywhere dir part is covered after that these are the changes so in short form also we can write mkdeir the common part first you can write after that curly braces you can give and within that curly braces what are the names 10 comma 35 comma before that 22 is there comma after that 48 is there so we can make it shortcut now if we execute this then it will create all these multiple directories so instead of writing this we can use this which is shortcut and good approach now we can write this an export here no error message it is created ls dir 10 dir 22 dir 35 dir 48 everything is created removed all right so this way we are writing fine or in shortcut way we are writing that is also fine it will remove so this is one way another is so here random values are there 10 20 2 35 48 no sync in that suppose these are in c like this d i r 11 d i r 12 dir 13 dia 14 so 11 12 13 14 these are in sequential values in increasing order so in that case we can write like this it is going on up to suppose dir 30 11 to 30 it is created so any number no restriction rows lux thousands hundreds of directory can be created fraction of second so one initial value we can give 11 then dot dot last value we can give 30. no need to mention in between any other values are there so one one increment will happen here 11 12 13 14 15 16 17 up to 30 it will create now no error message c ls dir 11 the ir12 dir 30 up to dir30 it is created we can remove that also same thing again we can keep here remove color those are called so these are the different approach how to create the directory for this deletion rndir we can write in questions on all these these are the way how to create directory multiple approaches there single directory multiple directory recursive directory then with some sequential names of directed list a lot here um are you talking to me yeah so all are clear how do we know this is clear yeah clear we're good now we can go for 5 create file so for creating five touch is one command cat is one command then vi is one command so these are mostly used frequently commerce some others are there also we'll see later those are not appropriate okay so these are the major commands for create so vi is editor also so we will see in some other classes this is very likely one so initially we will not see after few classes we use this api so using touch command only create file will be create that's all using cat command create and we can write the content also one additional part and for vi command we can create we can write the contents we can modify the content also or that is also called as edit the content so here in cat command we cannot delete that only in vi we can edit that in touch edit part leave it we cannot write also only create so only write touch component only at create and write the contents the i command create write and modify also so this bi later on we'll see this create using pub chat cat will see now so you just touch how to create torch a single file it will create touch a b c d e f g like that then multiple files it will create and again similarly touch touch some means sequential wise it is there test one here we can write like this within curly braces 12 comma 25 comma 68 comma 99 so test 1 2 test 2 5 test 68 test 99 like that it will create approach is initial number we can give like 11 11 to 30 suppose we need product 30 to test 11 test 12 test 13 test 14 test 15 like that up to 30 will create so similarly for removing the files also we can use all these files instead of this we can give rm command rm command rn so for removing the file rm command for creating the file touch command okay now we can create touch a clearing the screen touch a ls a created okay so previously abcdefg as it is there we can remove all rf a b [Music] you can remove all these okay so firstly we can create now just before create just c this is available now i am creating this b a l a created now multiple files we can create torch a b c d e like that so these multiple files it will create now created no error see a b c d e it is created if we want to remove rma removed ls rna h not there if we want to remove all these pcdfgh you can see those are not available removed now again we can give 5 13 15 99 78 like that we want to create these are different names unless so file 13 file 15 file 99 file 78 in ascending order it is created now we can remove that also how we have given in the same way we can now ls all are gone now sequence wise also we can create we can start from 11 dot 30. no need to mention in between any value any number so sequentially eleven two and thirteen fourteen fifteen sixteen up to thirty it will create uh create patch we have to give torch unless all these are created i'll 1 file 11 file 12 file 13 file 14 i'll 15 file 16 up to 5 30. if we want to remove all these rm now unless nothing is there everything is gone okay so this is the way how to create file and how to remove file using touch command any doubt from this touch how to create how to remove no everything is clear okay next another command cat command we can use command is case sensitive already we discussed in first class so don't write capital letter anywhere most of more to all greater than a we can give then we can create so using cat we cannot create multiple files at a time we cannot create this type of naming convention by giving at a time we cannot create sequence names related to some files no these are not possible not at a time only one file we can create using cat command so these are the day merits of cad command at a time only single file can be created no other way is available to create more than one file that is the merits but merit seeds we can create as well as we can write the contents also that is one minute now we can create a file using cut command capped greater than a now cursor coming below we can type something here enter type anything you can type these are the contents so you can write some appropriate contents also i'm learning unix my name is this my role is this now this time is this one anything you can write just for short part way i am typing now we have created we have written some contents if we want to modify something then that is not possible so if you will try just see here i'm using backspace backspace backspace so in the same line where cursor is there we can remove but before that line we cannot go back now i'm trying so not at all possible we cannot edit or modify anything in cad command only we can delete our modifier in the last line where person is present apart from that nothing now how to save this file control d it will save now get paste file name it will display the content of that file whatever we have written and saved that is visible now so how to save control d we have to press after that enter write something something something so whenever you don't want stop here control plus b you can press from the keyboard enter after that it will save after that again if you want to see the content of file whatever we have written so space a if you are giving then it will display the content greater than a if you are giving it will create a file and it will allow to write some content then we can save this and see this this is the way how we can create a file now suppose again we are creating a file name with the same name what will happen we don't know a we are creating but a is somebody created using cat we are doing writing something tiger lion anymore something something we can write suppose now i skip this now cat what happened previous one is gone new one is coming so previous will be override with these new commands new contents the first one we cannot get back again now that is gone already so previous what contents was there it is overrated with the new content so whenever you are doing this cat command and creating a file very very careful in office if you are working somebody already created some project related files a lot of important informations are present in that and you created something and abcd xyz or anything then that is one case it cannot refer back also whole project is done so whenever you are doing some explore related to unix lineups command scriptings or anything always you can create one directory with your name abcd something go to that directory and then you can explore anything it will not disturb to anybody anywhere go and just create delete all those things don't prefer an effort to very danger because in unix overwrite means permanently overwrite delete means permanently delete you cannot revert back like windows control facility is not available undo facility is not available this cycle bin is not available that's why whatever we are doing permanent so before doing it carefully we need to do that's why these are not user friendly also if good in this technical knowledge of this can only work otherwise anybody you are in that is not good okay so this is the way how to create file using cat as well as create command so create command what are the merits for interview one demand is multiple files or sequential files we cannot create wherever torch we can create the benefit is we can create and write but we are not able to edit also the content that is another demerits so multiple files at a time we cannot create contents of the file we cannot edit these are the demands of cad command the touch command what is the benefit we can create single file as well as multiple files as well as sequential names of the files very good feature for the touch command but what is the d merits we cannot write any content we can not modify any content that is the demands and another advantage of this cad command commandant if we are giving the file name existing file name again then what it will do the last creation date and time will be changed to current date and time suppose here ls minus lrt so one file i'm picking okay a wk.txt are asking right nice okay okay so this last part i am doing now so we can use touch commands suppose a wk.txt is one file which is already created when i created april 8 749 i created now again i am creating touch the same file name awk.txt

enter now again we can check ls minus select now see a w k minor dot txt what happen storage date and current time it is displayed so data creation of that file will be changed date and time of the creation with that file will be changed here and display here content will remain same content will not change but i kept that only it is not changed so that is another benefit of touch command so if any existing file is there and again we are using the same name with project command it will not create a new one or it will not replace with any new content so what it will do it will change the creation date and time of that exact i everything will remain same file name content everything will remind them only creation date and time will be changed but in cash if you are using and creating again then that will replace with the older to newer content so these are the merits and the merits of touch as well as cat command which are used for creating the files now all those files we can remove also remove rm only the command so using rm command we can remove these files okay now if directory and file both contain then how to remove this is individually directly created individually directly deleted individually file created individually file deleted now combined okay so for individually rmdir we are using for delete directory for individual file delete rf command we are using or combine one rm command so here we can keep one thing i am creating a file and directory also mkdir a enter go to the directory using cd command now where we are present under a anything is there under a ls no nothing now we can give some command and create file a b c again we can create another command here another directory here b again we can go to b now again i am creating some file x y z now i am coming back so if we want to see recursive structure of a if this minus r with this so under a directory a b c files are there b is one directory under a and b x y z is there so these are recursive structure so in this recursive structure directory is also there high also there means combine directories as well as file so in that case what how to delete in that case if we are deleting rf command only we can use rma rm a it is not deleting why because these are recursive so rn minus are enter now everything is done now again you can see l s minus r a something is present so in this way you can delete if combinedly it is there r s minus r e minus capital r also you can anything is fine so wherever combinedly it is present directories as well as file then this is the way how you will delete it wherever only file is there this is the way wherever only directories are there now how to create directory how to display the direct file contacts and how to remove the directory how to remove the files how to remove the directory as well as how to remove combinedly directories and files everything with requests everything is completed any questions from all these no okay next is display file content one is cat command another is more command another is less covered okay so get more less these are the three command so cad command is used to display the content of small files more command is used to display for big files in forward direction left command is used to display the file content of big files in forward as well as backward direction these are the three commas so here we have created one file a for any file we can take it from here a is there suppose we can take a cut a so three lines are there then that is fine now we can create a big file history i am creating a big file later on will tell what is this another class so history h k and i created now this hkl contains how many lines 458 lines okay so 450 line means we are able to see if suppose 5000 likes then we cannot see this that cat command will display up to 500 or 800 or 1000 likes only beyond that it will not display so here 450 then that is fine if 5000 lines then what to do so for that we can use more command more hkl now it started displaying from first line first line second line third line fourth line fifth line sixth line from starting it is displayed six percent displayed in first page then we can click we can press on space bar in keyboard press space bar this press press it is going next next page next page next page next next next next it will continue we cannot come back backward backward backward backward we cannot go only forward forward forward no other option arrow key no another arrow no backspace no nothing only one option spacebar with next page movement completed now next what to do if we want to see backside and front side backward forward backward forward then what to do less command less command then hkl so from starting it is displayed after that just use down arrow key from keyboard i am pressing down arrow down down down down down it is going down down down i want to come up go forward come backwards both are possible now how to quit press q it will quit so these are the three commands used for display the file content if it is very small files go for cat command if it is very big five thousands of lines are there go for more command again while seeing the contents of that file we want to roam forward backward forward backwards and best approach is less common if not moving backward only forward-wise we will go then go for more command if less contents are there small file is there go for cad command many are telling cat command is used to display the content in interviews so you can tell three answer every time you can tell multiple answers anybody is asking in the interview how to create a file people are telling cat command very last people are telling touch command now after telling touch command these things they don't know this is not mentioned in any books also so don't miss this you will be unique person in the interview and definitely you will still have no rejection nobody is telling you so which nobody is telling that look at that which everybody is telling and you are also telling that is your love or not so refer in that way and loving that way okay so these are the contents today we covered

2022-06-18 17:42

Show Video

Other news