Linux Essentials For Hackers - #3 - File Management & Manipulation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this series is sponsored by lenode linux provides virtual servers that make it easy and affordable to host your own app site or project in the cloud you can get twenty dollars free on your linux account with the code hackersploit20 or by clicking the link in the description that is linux.com forward slash hack exploit welcome back to the linux essentials for hacker series in this video we're going to be taking a look at file management and file manipulation uh in linux so let's get started so i'm just going to open up my terminal here and let's just expand this and let's increase the font size so we can see what's going on all right so let's start off with a bit of directory navigation and understanding uh what files exist within a directory right so the first question any beginner to linux has is uh when the in the terminal is how do i know where i am or how do i know what directory i'm in right so they want to know where where they actually exist in the linux file system so by default if you are logged in as a user you know that a user is not the root user so you know a normal user account for example i'm logged in as alexis so i'm going to be in my current home directory now you can confirm this by typing in pwd all right pwd means print current working directory or print working directory and that is self-explanatory it prints the current directory that you are in and that you uh will be working in or any commands that you actually run will be executed within this directory right so i'm going to hit enter and as you can see it tells you i'm in the home alexis directory now user accounts are usually sorted out this way so the root account usually has its own folder in the root directory of the file system of the linux file system whereas other users like alexis here uh will be found within the home directory and then furthermore their own individual directories based on their usernames and this is where all their files will be stored all right which brings us to the next question which is how do i list the files within a particular directory and this is very simple we use the ls command which means list all right so i'm going to hit enter and this will list the files and the directories within the current directory right so i'm going to hit enter and as you can see it tells us within this current directory we we have the desktop directory uh the documents directory downloads etc etc right so this is the simple way of listing files now the ls command has the ability to be run with other arguments or commands or options that allow you to increase or to modify the way the output is or the way the files are displayed to you right so a quick example of this is by using the ls hyphen or dash l command all right so this will list all the files and directories in this directory in the format of a list or a table which makes it easier to read for users right so i'm going to hit enter and immediately you can see it gives you a vital information like the total uh right over here the permissions the owner the ownership of these files and directories uh you have the date modified and the name of the file of the files and directories all right so that is how to use ls in combination with another command now you can also get more output uh by combining the ls command with other options so again if we wanted to list all the files that are all the files and directories that are currently in this working directory i can use the a command which essentially is an abbreviation for all now when i say all in the context of linux it means all hidden files all files within this directory will be displayed all right so if i list the files again here you can see that it only displays the the files and directories that are visible to users if we want to display all the files and directories including hidden files and directories we can say ls and we can say a all right and this again will give us all files and directories including hidden files and directories so you can see the hidden files in linux have the dot or the full stop uh before the file name here so again the bash aliases file is a file that is used in configuration of your bash profile so again it allows you to configure aliases when working with bash again so the hidden files in nx typically are used for configuration of various system system environment variables or various system uh tools uh you know so on and so forth we'll be working with this later on and it will all make sense shortly now the great thing about the list command is that i can use it in combination with the previous command so if i wanted to list this in a way that was much easier to read i can say ls a l and this will list all the files and directories including the hidden files and directories in the format of a list or a table and i hit enter and there you are you can see it displays all the files and directories in the form of a list here and again it gives you information in regards to the ownership and the permissions more of which we'll touch upon later on in the course all right so i'm just going to clear the terminal here and let's take a look at the ls command a little bit more all right so let's say i wanted to um to actually list the files in a more readable format for users so again i can just type in ls l and i can use the h command right so if i hit enter again this displays it in a much easier way for for users to understand what's going on and the context i'm referring to is more to do with the size all right so if i say ls l you can see that the data here or the size of the files is in bytes right now when we use the ls h or the h where the h stands for human readable format you can see it displays the actual size in kilobytes a much easier way for you to understand the sizes of files etc etc alright so let me just clear the terminal here and let's take a look at one more uh command uh that we can use with ls and that is if we wanted to uh show uh subdirectories right so remember when we show when we use the ls command it shows us the directories within this current working directory but let's say we had other directories within um let's see within pictures right so we could have other directories within pictures or documents or the downloads folder etc so again we can say uh if i wanted to list uh the the sub directories within the desktop folder i can say ls l and we'll use the capital r command and this again means recursively so we can then specify the folder we want which is going to be desktop or the directory we want again it's going to be desktop and we hit enter and again it will list for us the files that exist on the desktop first of all and again it shows us that we have a directory called c and a txt file called todo.txt all right within the c folder or the c directory we have three files we have a temp dot c uh we have a test binary and a test dot c file so again it's displayed to us what is on the desktop and then what is uh what what is in the directory c on the desktop so again it's used for recursive a listing of the of files and directories and subdirectories that way all right so i hope that makes sense now let's talk about uh some directory navigation all right which is quite important here before we actually talk about file manipulation and copying files etc so as i said we are currently in the home alexis directory now if i wanted to move a step back or to move to a parent directory i can say cp all right so cd will change directory to the actual home directory uh so again if i type in pwd you can see it will not do anything now if i wanted to go a step back i can type in cd and i can follow that uh or yes i can follow that up with two full stops and that will take me a step back and immediately on your bash shell you'll be given the current directory that you're in now so again it's telling us we are in the home directory and we can confirm this by typing in pwd right so if we list the files within the home directory you can see that the only directory that exists is the alexis folder and that's because that's the only use on the system so let's take a step back right so i can take a step back and i hit enter and now we are currently in the root directory the root file system directory for the off for linux right so again i can list all the files in here and i can hit enter and as you can see we are now in the root this is the actual root directory of the linux file system not the root folder or the root user directory just the root of the file system so you can now see all the various folders that the linux file system is comprised of all right so that is how to actually navigate a step back now if i wanted to navigate into any one of these directories i could say cd and then i specify cd is an abbreviation for change directory and i can specify the directory i want to move into so i can say cd home right and again that will take me into my home directory and then i can list the files in here and this tells me oh we have a directory called alexis d and then i can say change directory into the directory alexis and that will take me into the uh the directory alexis all right now i can also use um i can also use the forward slash to refer to a directory that is currently not in this particular directory so let's say i wanted to move into the um let's see i wanted to move into the let's try the etsy folder i can say cd uh forward slash etsy and this refers to a directory that is currently not in this directory but at the root at the root of the linux file system so i hit enter and that takes us into the etsy folder so again i can confirm this by typing in pwd and again it tells me i'm currently in the etsy folder right now if i want to navigate back to my user home directory so i'm currently logged in as the user alexis if i want to go back to alexis home directory i can simply do this by typing home alexis right that's very very simple but if i want to even make this shorter i can use uh the command right over here and again i can hit enter and i can easily just navigate back to my home directory so if i hit enter you see and i type in pwd it's going to take me into my home directory right over here all right now that we have taken a look at you know directory navigation and moving around directories let's take a look at creating files copying etc all right so i'm currently on my in my home directory so let's talk about actually copying a file uh now before we actually do that we need to actually understand how to create files really really quickly all right so uh the first thing i want to do is i'll go into my desktop here and i'll say cd desktop and i'm going to hit enter and i'm in my desktop now all right so if i wanted to create a file really easily i can use touch all right so touch is a is a tool or a utility that allows you to you know easily create files again uh let me show you a command that will help you understand what various commands and tools are so if i want to know uh i want information about a particular command i can use the what is the what is command so i can type in what is and then i can say what is touch and i can hit enter and again it tells me change the file timestamps all right or so i can also say what is let's see what is nano right nano is a text editor so i can hit enter and it's going to tell nano is another editor etc so it gives you information about a particular command or tool all right so i can use touch to create a file remember without any content right so i can say touch and i can say the file name is going to be test dot txt all right i can hit enter and if i list all the files in the desktop you can see i have the test.txt file right over here all right so uh i can now direct data into this file so again i can use the ech command and if we want to learn more about the echo command i can type in what is and i can say echo and i can hit enter and it's going to say display a line of text right so we can say echo alexis is alexis is you can say alexis is not cool i know something like that and i can just hit enter and again it will display on our terminal alexis is not cool all right so it simply just displays a line of text however we can redirect this data into a particular file and in this case we want to dis we want to redirect this data into the test.txt file right so i can say echo we can say hello and we'll just use this simple string of text here and i can say redirect to this and we use the greater than sign to redirect data to a particular file or to a particular command so i can say test dot txt all right and i hit enter and now this file should have the words or the string hello now if you want to easily just uh display the context uh or the content of a file i can use the cat command all right now again we can use the what is command to find uh to find out more about what the the cat command does so i can hit enter and it's going to tell us it concatenates files and prints on the standard output so again it gives us the output of all the content it prints out the content of a particular file uh so again i can say cat test dot txt and hit enter and again it prints out what we had redirected into it all right so that is how to use the cat command now again i can redirect a lot of text into this uh so let's say i wanted to edit this uh this file or i wanted to remove this file which is a much better way of actually taking a look at you know file manipulation technique so again i've shown you how to create a file a very simple file redirecting output we can also use cat to redirect output so for example if i wanted to redirect the contents of the password file i can say cat hc password and i'm using the relative directory you can see here so the the the contents of the password file i want to redirect into the test dot txt file however if i wanted to create another file i could easily do it directly from here i could say password dot txt and i hit enter and now we can display the contents of the password.txt file and again i can use the tab autocompletion here and i hit enter and again it gives us all the content was redirected into this new txt file excellent so now let's talk about actually you know create removing files copying them etc so if i wanted to remove this file here the test.txt file i use the rm command which stands for remove right again you can use the what is command and again use it again it tells you this is used to remove files and directories so let's talk about removing files first all right so we can say remove uh test.txt all right and again we use tab autocompletion and i hit enter and this will have removed the file over here right so um that is essentially how to remove a file now if i want to remove a directory i can now i need to specify that it is a recursive action but before we do that let's talk about creating a directory first because that's quite important as well so if i want to create a directory i use the make directory command which is abbreviated into mkdir so make a directory and i give it a name so i can say test all right so this is going to create a folder or id or a directory called test right once i hit enter and i list all the files here you can see we have the test directory over here so what i can do is uh i can you know i can navigate into it i can copy files into it so let's say i wanted to copy a file into this uh directory so again i can say let's say i wanted to say touch or we can do the same thing so i can say cat etsy password and i want to redirect this into a file called password.txt and once that is done i want to copy the file so i want to say cp that means copy and i want to specify the file that i want to copy which is going to be password dot txt and i want to copy that into the test directory so i specify the directory i want to copy in i want to copy it into in this case the test directory is within the current working directory so i don't have to specify a relative path if i was specifying a relative path i would use the forward slash here so i can just say test and i hit enter and now if i remember if i wanted to list the contents of the sub directories recursively i could say ls lr and i hit enter and you can see the contents of the test directory password.txt excellent so again if i want to remove the the password file i can say removepassword.txt if i want to remove a directory and the directory what we want to remove is the test directory i can say remove and i use the capital r which means recursively remove and i say test and i use the tab auto completion and i hit enter and now if we list the files in the on the desktop you can see we've gotten rid of all of these folders and files all right so now that we know how to actually create a directory we can actually um let me talk about removing a directory i actually covered it with the remove command however we can also use um another command called remove directory which is abbreviated into rmdir this will only allow you to remove a directory if you do not have any files within that directory right so let's say i uh by the way you can cycle through your previously used commands using your arrow keys in this case you can use the uh the up arrow key so let's say i wanted to cat i wanted to you know redirect output of the password file into a file called password.txt and i wanted to copy this file or let's actually talk about moving files so if i wanted to move a file i would say mv and again you can use the what is command so what is mv so i can say mv i want to move the password.txt file into the test directory here i'm going to hit enter and now you can see that the the password file has been moved into the test directory so again i can i can list all the files within the test directory here and that again it tells me that we only have the password.txt file in here so if i use the rm dir command which means remove directory and i say test remove directory test you can see it's going to tell me that this directory is not empty so as a result we need to specify remove recursively test and i'm going to hit enter and now it gets rid of the test directory for us all right so those are very very simple ways of you know creating copying and of of course deleting commands now uh before we actually end this video which i know has been going on for quite a while i'm going to be covering file directory permissions later but i want to talk i want to talk about file manipulation a little bit more so we've talked about you know using the cat command redirecting output using touch as well moving files let's talk about you know renaming files uh and also taking a look at the content of particular files here so uh what i want to do now is let's actually take a look at um at actually renaming files all right so i'm going to again use the similar command that we had used i'm just going to you know i'm going to redirect the output of the password file into a file called password.txt and now if i wanted to rename the filepassword.txt into something else i would use the mv command right so there isn't a command to rename files in linux you use the mv command which means move in this case it's very simple the syntax is you specify the file that you want to change the name of which is going to be password.txt and i change the file name to let's say test dot txt and hit enter and now if we list all the files in the directory you can see that it changes it to test.txt and indeed if we actually uh if we actually display the contents of the file you can see that uh the content is preserved well we've changed the name and we can also change the extension of the file so i could say move test.txt into test um let's say test dot c we can we can change the contents into a c file right and now if i say cat test dot c i can hit enter and there you are now let's talk about uh editors and then i'll talk about the content of the files uh before we actually end this video so um there are two standard editors that are pretty much the standard when it comes to linux and working within the terminal i'm not talking about graphical gui based editors like g edit and stuff so if i wanted to edit this file within the terminal i have two options i have nano so again i can use the what is command and say what is nano and again that's an editor and i have we have vim which is pretty much the most popular option and i'll be making independent videos on this editors and how to configure them so again if i want to edit the test.txt file i can say nano test dot tx test dot c uh let's actually rename it back to test.txt dot txt and we say nano test dot txt and when it enter and that takes us into nano now exiting nano is very simple again you can navigate around make changes uh exiting it we use control and x and that's it now with v vim or vi we simply type in vi or vim and we say test dot txt hit enter and again with them the syntax is very different if i want to make changes or i want to add content i type in i to insert text and again i can play around with it and once i'm done i hit escape and then i can write changes to this file or i can quit and discard any changes by typing in q and the exclamation mark and hit enter and that's how to use the various editors i'm not covering them uh you know to their full to their fullest extent and that's because we have various videos that will be actually focused on editors themselves so um that's pretty much all that i wanted to cover in this video there's quite a bit hopefully you guys can actually learn a lot from this video if you have any questions or suggestions let me know in the comment section and i'll be seeing you in the next video [Music]
Info
Channel: HackerSploit
Views: 42,064
Rating: 4.9644589 out of 5
Keywords: hackersploit, linux, kali linux, kali linux tutorial for beginners, linux tutorial, linux tutorials point, linux tutorial for beginners bangla, linux tutorial for beginners, linux tutorial bangla, linux tutorial for beginners 2019, linux essentials, linux essentials exam, linux essentials commands, linux for hacker, linux for hacking, kali linux for beginners, linux commands, linux command line tutorial, hacker exploit, hacking
Id: oGj5JBBQLHs
Channel Id: undefined
Length: 24min 0sec (1440 seconds)
Published: Thu Oct 31 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.