Hey guys am back today am going to show you something i think is very important for beginners.
well will start with shell navigation, this is very important topic when working with a Linux environment and we are going to see some basic navigation commands.
The first directory in the file system is called the root directory.The root directory contains files and sub directories, which contain more files and sub directories and so on and so on.
pwd
We use the pwd command to see the name of the working directory
Tip: for more info pwd or use the linux command man pwd
cd
We use cd to change the working directory.To do this, we type cd followed by the pathname of the desired working directory.
Pathnames can be specified two different ways; absolute pathnames or relative pathnames.
Absolute path is defined as the specifying the location of a file or directory from the root directory(/).
Start at the root directory ( / ) and work down.
Write a slash ( / ) after every directory name (last one is optional)
Relative path is defined as the path related to the present working directly(pwd). It starts at your current directory and never starts with a /.
Example of Absolute and Relative Path
Suppose you are currently located in home/haile and you want to change your directory to home/haile/h. Let’s see both the absolute and relative path concepts to do this:
Changing directory with relative path concept :
Changing directory with absolute path concept:
Moving backward with cd
To move backward with cd command we use cd .. (cd followed by two dots).
to move backward two levels
If we type cd followed by nothing, cd will change the working directory to our home directory.
Tip: for more info on cd command cd or use the command *man cd *
ls
We use ls command when we want to list the contents of a directory.
To list the files in the /dev directory
List the files in the working directory in long format
List the files in the /bin directory and the /etc directory in long format
List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format
Tip: for more info ls or use the linux command man ls
less
we use less to view text files.less is a program that lets us view text files. This is very handy since many of the files used to control and configure Linux are human readable.
Tip: for more info less or use the command man less
touch
we use touch to create a file without content.The file created using touch command is empty
You can create multiple files with touch.
Tip: for more info touch or use the command man touch
before we get into the other commands we first need to learn about Wildcards
Wildcards
Wildcards allow you to select filenames based on patterns of characters. The table below lists the wildcards and what they select:
cp
We use cp command to copy files and directories.
Copy the file content of one file to the other
if b.txt doesn't exist it creates the b.txt file
Copy the file a.txt to the dir folder
Copy the content of dir to dir2 and if dir2 doesn't exist it creates it.
Tip: for more info cp or use the command man cp
mv
we use the mv command to moves or renames files and directories depending on how it is used.
Rename the a.txt file to load and if file load exists, its contents are silently replaced with the contents of a.txt.
The files b.txt and c.txt are moved to directory dir. If dir does not exist, mv will exit with an error.
Rename the directory dir to lp.If lp exists, the directory dir is moved within directory lp.
Tip: for more info mv or use the command man mv
rm
We use rm to remove (delete) files and directories.
To remove h.txt
To remove multiple files ha.txt and load
Tip: for more info rm or use the command man rm
mkdir
we use the command mkdir to create directories.
Tip: for more info mkdir or use the command man mkdir
rmdir
We use rmdir to remove empty directories.
Tip: more info rmdir or use the command man rmdir
Top comments (0)