Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views28 pages

102 - File System in Linux

102 - File System in Linux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

102 - File System in Linux

102 - File System in Linux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

File System in

Linux
AGENDA
1. Part 1: Overview of File System

2. Part2: Some basic commands

3. Part3: Additional basic


commands

4. Part4: More commands


01
Overview of
The file
system
Linux Hierarchy
Overview of File System in Linux
● File system in linux contains directories, files, scripts and executable
files.

● Some of these directories contain consistent pre-defined files.

● Linux is different than Windows in its hierarchy, in Windows your hard


disk is divided into more than on partition (as you will see in the next
slide). However, in Linux there is one, and only one, hierarchy.

● So Linux has only one tree (unified hierarchy)


File System in Windows

● As we can see, Windows has more than one drive.

● Even if you connect a storage device (such as flash memory), a new


drive (partition) will appear.
File System in Linux
Overview of File System in Linux
File System in Linux
● So we learned that Linux has only one tree, this tree is known as “the
root tree”.

● So there is a question, what if I need to plug another hard disk to my


Linux, will it work?

● Yes it will work just as plugging an external flash memory. A new


mounted device will appear and you can mount and access it so easily
Files and Directories
● Now you got the idea how Linux file hierarchy consists. So let us move
forward and see how we can deal with Linux directories and files.

● Folder in Windows are named “Directories” in Linux.

● Directory names separated by forward slash “/”


/home/kali/Desktop/MyNewDirectory
/home/kali/Document/abc.txt

● Also you can reach your above directory by typing:


~/Desktop/MyNewDirectory
~ means /home/kali and in called your home directory
Files and Directories
● Suppose that your are working in directory
“/home/kali/Desktop/business” you can express all of that by typing “.”
IF you are CURRENTLY working (stands) on this directory.

● Your current directory will always appear in your terminal prompt next
to your username as shown below:
02

Some Basic
Commands
Let us practice
Basic Commands

● In this topic we will learn how, when and why to use some very basic
commands in linux to handle file system stuff.

● You can do most of these basic commands using the Graphical User
Interface (GUI). For example, you can copy, delete, move and do more
and more using your mouse.

● We will focus more on doing these stuff using the basic commands.

● So we will perform these commands in the TERMINAL not GUI.


Basic Commands
Command Description

$ pwd Printing Current Directory

$ ls List the sub files and directories in the current directory

$ cd Change Directory to another one

$ mkdir Make Directory to create a new one

$ cp Copy file or directory to another place

$ mv Move or Rename file or directory

$ rm Remove file or directory

$ clear Clear the current terminal


Basic Commands: pwd

● We use “pwd” command to let the system print on the terminal the
current working directory
$ pwd
Basic Commands: ls

● We use “ls” command to list the subdirectories and files under the
current directory.
Basic Commands: ls

● You can also use “ls” with its options !

● $ ls -l >> list in long format


$ ls -a >> show hidden files and directories
$ ls -t >> list and sort based on the timestamp
$ ls -S >> list and sort based on the size
$ ls -r >> list and sort in reverse order
$ ls -d >> show only the subdirectories
$ ls <dir> >> list the mentioned directory

● Also you can use more than one option in the same command:
$ ls -lad
Basic Commands: cd

● We use the command “cd” to change the directory or navigate to


another directory in the system.

● The next screenshot shows how to navigate from one


directory to another one.

● Also we can use “cd” to navigate to the parent dir.


$ cd ..
Basic Commands: mkdir

● We use the command “mkdir” to create a new directory


$ mkdir MyNewDirectory

● Also you can use the same command to create a new directory in
another directory (not your current directory)
$ mkdir /etc/security/NewDir
03
Additional
Basic
Commands
Basic Commands: cp

● We use the command “cp” to copy file or whole directory from one
place to another

● To use this command please try it as following


$ cp <file/directory> <the new place>

● For example, if we need to copy file located in Desktop on another


place we have to type:
$ cp /home/kali/Desktop/Dir1/MyFile /etc/Dir2
Basic Commands: cp

● To copy a file we use the previous command. What if we need to copy a directory
$ cp -R ./Desktop/Mydir1 /home/kali/DistinationDir

● What if we need to copy the files inside the directory


$ cp -r ./Desktop/Mydir1 /home/kali/DistinationDir

● You can also create a new copy file in the sme directory with another name:
$ cp /home/kali/Desktop/MyFile1.txt /home/kali/Desktop/MyNewFile
Basic Commands: mv

● We use the command “mv” to move or rename a file or directory.

● To move the file type the following:


$ mv /home/kali/Desktop/Dir1/Myfile.txt /home/kali/Documents/Myfile.txt

● You can also move the same file above to the new directory with new name:
$ mv /home/kali/Desktop/Dir1/Myfile.txt /home/kali/Documents/MyNewfile.txt

● In same directory, you can rename the file using the same command:
$ mv /home/kali/Desktop/Dir1/Myfile.txt /home/kali/Desktop/Dir1/Myfile2.txt
Basic Commands: rm

● We use the command “rm” remove or delete a file or directory

● To remove file all we need is typing:


$ rm /home/kali/Desktop/MyFile.txt

● To remove a directory:
$ rm -r /home/kali/Desktop/Dir1

● To force removing a file or directory we type:


$ rm -rf /home/kali/Desktop/Dir2
Basic Commands: clear
● We use the command “clear” to clear the terminal only.
04

More
Commands
More Commands
● In the previous slides we discussed some basic commands that are
necessary to interact with any Linux OS.

● Now we are going to take more commands that you will need in our
journey either while dealing with Kali or any other Linux distributions.

● These commands are:


○ $ cat >> to read only the file content on the terminal
○ $ touch >> to create new text file
○ $ nano >> to read/edit on text file
○ $ sudo >> to perform some root commands

You might also like