SlideShare a Scribd company logo
BASICS OF UNIX
COMMANDS
Prepared By:- Subra Kumar Das
Designation: Operations Support
Analyst
Version 1.0
1. Introduction to Unix
2. What is File & Directory ?
3. Pathnames
4. Listing files and directories
5. Making Directories
6. Changing to a different directory
7. Copying Files and directories
8. Moving Files and directories
9. Removing files and directories
10.Creating a file using vi editor
11.Displaying the contents of a file on the screen
12.Searching the contents of a file
13.Redirecting the Output
14.Redirecting the Input
15.Pipes
16.Wildcards
Agenda
Introduction to UNIX
Go back to Agenda
• UNIX Operating system originally developed in 1969 by a group of AT&T
employees at Bell Labs.
• Various flavours of Unix & Unix-like OSes are Solaris, Linux etc.
• Designed to be portable, multi-tasking & multi-user in a time-sharing
configuration.
• Unix systems are characterized by various concepts:
– Use of plain text for storing data.
– A hierarchical file system.
– Treating almost everything as files.
– Use of a large number of small programs that can be strung together, as
opposed to using a single program that has the same functionality.
• Unix Philosophy :-
“Write programs that do one thing and do it well.
Write programs to work together. Write programs to handle text
streams, because that is a universal interface.”
History of UNIX
What is File & Directory ?
Go back to Agenda
Files: Everything in Unix is a file!!
Directories:
A directory is a file that contains directory entries.
• Each directory entry contains a file name along with a structure of
information describing the attributes of the file.
– Type of the file (normal file/directory/device file/soft link/hard link etc.)
– Size of the file
– Owner of the file
– Permissions for the file (whether other users may access this file)
– Time stamps (when the file was last modified/accessed)
• Can be considered as a container for files.
• When we first login, our current working directory is our home directory.
• Our home directory has the same name as our user-name.
File & Directory in UNIX
Go back to Agenda
There are two special directories called (.) and (..)
The current directory (.)
In UNIX, (.) means the current directory, so typing
$ cd .
means stay where we are.
The parent directory (..)
(..) means the parent of the current directory, so typing
$ cd ..
will take us one directory up the hierarchy.
Note: typing cd with no argument always returns us to our home directory.
This is very useful if we are lost in the file system.
More about Directories
Go back to Agenda
~ (our home directory)
Home directories can also be referred to by the tilde ~ character.
It can be used to specify paths starting at our home directory. So typing
$ ls ~/unix_session
will list the contents of our unix_session directory, no matter where we currently are in the file system.
More about Directories
Pathnames
Go back to Agenda
Pathname enables us to know where we are in relation to the whole file system.
Command:
pwd
Meaning:
Present Working Directory
Description:
The pwd command prints the absolute pathname of our current working directory.
For example, to find out the absolute pathname of our home-directory,
We need to type cd to get back to our home-directory and then type
$ pwd
which means that subra (our home directory) is in the home sub-directory,
which is in the top-level root directory called " / " .
Pathnames in UNIX
Listing files and directories
Go back to Agenda
Command:
ls
Meaning:
List
Description:
The ls command ( lowercase L and lowercase S ) lists the contents of our current working directory.
$ ls
Listing files and directories
Go back to Agenda
• There may be no files visible in our directory, in which case, the UNIX prompt will be returned.
• Files beginning with a dot (.) are known as hidden files and are not listed by ls command
• To list all files in a directory including those whose names begin with a dot, we need to type
$ ls –a
Where –a is an option and means all
• To list contents in a directory other than the present working directory, we need to type
$ ls < path to directory >
Listing files and directories
Making directories
Go back to Agenda
Command:
mkdir <directory or path>
Meaning:
Make Directory
Description:
The mkdir command creates new sub-directory within the current working directory.
$ mkdir unix_session
To cross-verify if the directory has been created or not, we can type ls command,
which will show the new sub-directory named unix_session within the current working directory
Making directories
Changing to a different directory
Go back to Agenda
Command:
cd <directory or path>
Meaning:
Change Directory
Description:
The cd command changes working directory to a different directory specified with the command.
$ cd unix_session
To cross-verify if the directory has been created or not, we can type ls command,
which will show the new sub-directory named unix_session within the current working directory
Changing to a different directory
Copying File & Directory
Go back to Agenda
Command:
cp < source_path > < destination_path >
Meaning:
Copy
Description:
The cp command copies files/directories from source path to destination path.
To copy files:
$ cp /home/subra/abc.txt /home/subra/unix_session/
To cross-verify if the file abc.txt has been copied or not, we can type ls /home/subra/unix_session/,
which will show the new file named abc.txt within the destination directory.
Copying File in UNIX
Go back to Agenda
To copy directory:
$ cp -r /home/subra/unix_session/ver1/ /home/subra/ver1
Where –r means recursive
To cross-verify if the directory has been copied to /home/subra or not,
we can type ls /home/subra/
which will show the directory named ver1 within the destination path.
Copying Directory in UNIX
Moving File & Directory
Go back to Agenda
Command:
mv < source_path > < destination_path >
Meaning:
Move
Description:
The mv command moves files/directories from source path to destination path.
To move files:
$ mv /home/subra/unix_session/abc.txt /home/subra/abc.txt
To cross-verify if the file abc.txt has been moved or not, we can type ls /home/subra/unix_session/,
which will not contain abc.txt.
Moving File in UNIX
Go back to Agenda
To move directory:
$ mv /home/subra/unix_session/ver1/ /home/subra/ver1
To cross-verify if the directory has been moved to /home/subra or not,
we can type ls /home/subra/
which will show the directory named ver1 within the destination path.
Moving Directory in UNIX
Removing File & Directory
Go back to Agenda
Command to remove a file:
rm < file_path >
Meaning:
Remove
Description:
The rm command removes (deletes) file from the file path.
Command to remove a directory:
rmdir < directory_path >
Meaning:
Remove Directory
Description:
The rmdir command removes (deletes) directory from the directory path.
We need to make sure directory which we need to remove is empty, as UNIX will not let us remove
a non-empty directory with rmdir.
Removing File & Directory in UNIX
Go back to Agenda
Command to remove a non-empty directory:
rm –r < file_path >
Meaning:
Remove everything recursively
Description:
The rm command removes (deletes) all files and directories in the directory named in the command.
However, it would also present a prompt for approval to delete each of the files.
Command to remove a non-empty directory without receiving a prompt for each file :
rm -rf < directory_path >
Meaning:
Remove everything recursively and forcefully
Description:
The rmdir command removes (deletes) directory from the directory path.
Removing non-empty Directory in UNIX
Creating a file using vi editor
Go back to Agenda
To create a file called unix_file containing a list of statements, we need to type
$ vi unix_file.txt
Then type in the names of some OS. Press [Return] after each one.
Zero is a number.
A is a Capital Letter Alphabet
b is a small letter Alphabet.
zero is also a number
Apple is fruit
UNIX is OS
WIN is OS
^D {this means press [Ctrl] and [d] to stop}
Type:
:wq
Where w means write (save) and q means quit.
Creating a file using vi editor
Displaying contents of a file on screen
Go back to Agenda
clear (clear screen)
Before we start the next section, we may like to clear the terminal window of the previous commands
so the output of the following commands can be clearly understood.
At the prompt, we need to type
$ clear
This will clear all text and leave us with the $ prompt at the top of the window.
cat (concatenate)
The command cat can be used to display the contents of a file on the screen.
Type:
$ cat unix_file.txt
If the file is longer than the size of the window, so it scrolls past making it unreadable.
Displaying contents of a file on screen
Go back to Agenda
less
The command less writes the contents of a file onto the screen a page at a time.
Type
$ less unix_file.txt
We can press the [space-bar] if we want to see another page, and type [q] if we want to quit reading.
As we can see, less is used in preference to cat for long files.
Displaying contents of a file on screen
Go back to Agenda
head
The head command writes the first n no. of lines of a file to the screen.
Then we need to type
$ head -5 unix_file.txt
Which will print first 5 lines of a file named unix_file.txt
tail
The tail command writes the last n no. of lines of a file to the screen.
we need to type
$ tail -5 unix_file.txt
Which will print last 5 lines of a file named unix_file.txt
Displaying contents of a file on screen
Searching the contents of a file
Go back to Agenda
grep
It searches files for specified words or patterns.
We can type
$ grep zero unix_file.txt
grep will print out each line containing the word zero in a file named unix_file.txt
We can try typing
$ grep Zero unix_file.txt
In this case, grep will print out each line containing the word Zero in a file named
unix_file.txt
The grep command is case sensitive; it distinguishes between Zero and zero.
To ignore upper/lower case distinctions, we can use the -i option, i.e.
$ grep -i zero unix_file.txt
Searching the contents of a file
Go back to Agenda
To search for a phrase or pattern, we must enclose it in single quotes (the apostrophe
symbol).
For example to search for spinning top, type
$ grep -i ‘numeric zero' unix_file.txt
Some of the other options of grep are:
-v display those lines that do NOT match
-n precede each matching line with the line number
Don't forget, we can use more than one option at a time.
For example, the number of lines without the words zero or Zero is
$ grep -iv science science.txt
Searching the contents of a file
Redirecting the Output
Go back to Agenda
We use the > symbol to redirect the output of a command.
$ echo startoffile > unix_file_new.txt
Above command will create a new file with a name unix_file_new.txt and startoffile as a
content in the first line.
The symbol >> appends standard output to a file. So to add more items to the file
unix_file.txt, we need to type
$ echo Mango is a fruit >> unix_file.txt
Which will add Mango is a fruit to a file named unix_file.txt
After execution of above command, we can type cat command followed by the filename /
filepath to verify the same.
Redirecting the Output
Redirecting the Input
Go back to Agenda
We use the < symbol to redirect the input of a command.
The command sort alphabetically or numerically sorts a list.
To sort the list and output to the screen
$ sort < unix_file.txt
Which will sort the list alphabetically for the start letter.
Note: Capital Letter will be higher in the order always then the small letter.
To output the sorted list to a file
$ sort < unix_file.txt > sorted_unix_file.txt
Redirecting the Input
Pipes
Go back to Agenda
What we really want to do is connect the output of the cat command directly to the input
of the grep command.
This is exactly what pipes do.
The symbol for a pipe is the vertical bar |
For example, by typing
$ cat unix_file.txt
$ grep zero unix_file.txt >> unix_file_zero.txt
We get a new file named unix_file_zero.txt with all the lines having zero in it.
Now
$ cat unix_file.txt | grep zero >> unix_file_zero.txt
will give the same result as above, but it is quicker and cleaner as it takes less number of
lines.
Pipes
Wildcards
Go back to Agenda
The * wildcard
The character * is called a wildcard, and will match against none or more character(s) in
a file (or directory) name.
For example, in our unixstuff directory,
$ ls list*
This will list all files in the current directory starting with list....
By typing
$ ls *list
This will list all files in the current directory ending with ....list
Wildcards
Go back to Agenda
The ? wildcard
The character ? will match exactly one character.
By typing
$ ls ?list.txt
Will list out all the files ending with list like flist, slist, mlist but not fglist as single ? is
used
Wildcards
Go back to Agenda
The [ ] wildcard
Defines class of characters.
For range of characters – can be used.
To exclude certain character or range of characters ! Can be used.
By typing
$ ls [a-z]*.txt
Will list out all the txt files starting with a to z in lower case
$ ls [A-Z]*.txt
Will list out all the txt files starting with A to Z in upper case
Wildcards
Go back to Agenda
By typing
$ ls [0-9]*.txt
Will list out all the txt files starting with numeric 0 to 9
$ ls [!0-9]*.txt
Will list out all the txt files not starting with numeric 0 to 9
Similarly to exclude all the files starting with [a-z] and [A-Z], we can use
$ ls [!a-zA-Z]*.txt
Wildcards
THANKS
HAPPY
COMMANDING !!
Ad

Recommended

03 browsing the filesystem
03 browsing the filesystem
Shay Cohen
 
Basic unix commands
Basic unix commands
swtjerin4u
 
Linux commands
Linux commands
Manish Bothra
 
Directories description
Directories description
Dr.M.Karthika parthasarathy
 
Linux commands and file structure
Linux commands and file structure
Sreenatha Reddy K R
 
Linux basic commands
Linux basic commands
Sagar Kumar
 
Important Linux Commands
Important Linux Commands
Arun Sharma
 
Linux - Directory commands
Linux - Directory commands
joesofi
 
Know the UNIX Commands
Know the UNIX Commands
Brahma Killampalli
 
Unix commands in etl testing
Unix commands in etl testing
Garuda Trainings
 
A z index of the windows cmd command line
A z index of the windows cmd command line
proser tech
 
CMD Command
CMD Command
Chandra Pr. Singh
 
Basics of unix
Basics of unix
Deepak Singhal
 
Linux commands
Linux commands
Ajaigururaj R
 
Linux commands
Linux commands
penetration Tester
 
Unix practical file
Unix practical file
Soumya Behera
 
intro unix/linux 07
intro unix/linux 07
duquoi
 
Learning Bash For linux Command Line
Learning Bash For linux Command Line
Mohamed Alaa El-Din
 
Linux basic commands
Linux basic commands
MohanKumar Palanichamy
 
Linux commands
Linux commands
Radheshyam Kori
 
intro unix/linux 02
intro unix/linux 02
duquoi
 
intro unix/linux 09
intro unix/linux 09
duquoi
 
intro unix/linux 11
intro unix/linux 11
duquoi
 
Basic Linux day 2
Basic Linux day 2
Saikumar Daram
 
Linux basic commands with examples
Linux basic commands with examples
abclearnn
 
Basic unix commands
Basic unix commands
Nomura Japanese Investment Bank
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examples
Noé Fernández-Pozo
 
Os lab manual
Os lab manual
Neelamani Samal
 
Karkha unix shell scritping
Karkha unix shell scritping
chockit88
 
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
YajnadattaPattanayak
 

More Related Content

What's hot (20)

Know the UNIX Commands
Know the UNIX Commands
Brahma Killampalli
 
Unix commands in etl testing
Unix commands in etl testing
Garuda Trainings
 
A z index of the windows cmd command line
A z index of the windows cmd command line
proser tech
 
CMD Command
CMD Command
Chandra Pr. Singh
 
Basics of unix
Basics of unix
Deepak Singhal
 
Linux commands
Linux commands
Ajaigururaj R
 
Linux commands
Linux commands
penetration Tester
 
Unix practical file
Unix practical file
Soumya Behera
 
intro unix/linux 07
intro unix/linux 07
duquoi
 
Learning Bash For linux Command Line
Learning Bash For linux Command Line
Mohamed Alaa El-Din
 
Linux basic commands
Linux basic commands
MohanKumar Palanichamy
 
Linux commands
Linux commands
Radheshyam Kori
 
intro unix/linux 02
intro unix/linux 02
duquoi
 
intro unix/linux 09
intro unix/linux 09
duquoi
 
intro unix/linux 11
intro unix/linux 11
duquoi
 
Basic Linux day 2
Basic Linux day 2
Saikumar Daram
 
Linux basic commands with examples
Linux basic commands with examples
abclearnn
 
Basic unix commands
Basic unix commands
Nomura Japanese Investment Bank
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examples
Noé Fernández-Pozo
 
Os lab manual
Os lab manual
Neelamani Samal
 

Similar to Basics of UNIX Commands (20)

Karkha unix shell scritping
Karkha unix shell scritping
chockit88
 
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
YajnadattaPattanayak
 
linux-lecture4.ppt
linux-lecture4.ppt
LuigysToro
 
linux commands.pdf
linux commands.pdf
amitkamble79
 
UNIX Command Cheat Sheets
UNIX Command Cheat Sheets
Prashanth Kumar
 
UNIX.pptx
UNIX.pptx
P S Rani
 
Linux
Linux
One97 Communications Limited
 
Unix Basics For Testers
Unix Basics For Testers
nitin lakhanpal
 
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
pssafvan97
 
Linux directory commands:more options on cd and ls command
Linux directory commands:more options on cd and ls command
bhatvijetha
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
Tushar B Kute
 
Red hat linux essentials
Red hat linux essentials
Haitham Raik
 
linux-file-system01.ppt
linux-file-system01.ppt
MeesanRaza
 
Unix training session 1
Unix training session 1
Anil Kumar Kapil,PMP®
 
Chapter 2 Linux File System and net.pptx
Chapter 2 Linux File System and net.pptx
alehegn9
 
Introduction to linux2
Introduction to linux2
Gourav Varma
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdf
CesleySCruz
 
Linux file system nevigation
Linux file system nevigation
hetaldobariya
 
linux chapter 5.pptx lesson About introduction to linux
linux chapter 5.pptx lesson About introduction to linux
zakiaxmed534
 
Linux Notes-1.pdf
Linux Notes-1.pdf
asif64436
 
Karkha unix shell scritping
Karkha unix shell scritping
chockit88
 
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
linux-lecture4.pptuyhbjhbiibihbiuhbbihbi
YajnadattaPattanayak
 
linux-lecture4.ppt
linux-lecture4.ppt
LuigysToro
 
linux commands.pdf
linux commands.pdf
amitkamble79
 
UNIX Command Cheat Sheets
UNIX Command Cheat Sheets
Prashanth Kumar
 
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
TERMINAL COMMANDS IN LINUX TERMINAL USED TO INTERACT WITH SYSTEM
pssafvan97
 
Linux directory commands:more options on cd and ls command
Linux directory commands:more options on cd and ls command
bhatvijetha
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
Tushar B Kute
 
Red hat linux essentials
Red hat linux essentials
Haitham Raik
 
linux-file-system01.ppt
linux-file-system01.ppt
MeesanRaza
 
Chapter 2 Linux File System and net.pptx
Chapter 2 Linux File System and net.pptx
alehegn9
 
Introduction to linux2
Introduction to linux2
Gourav Varma
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdf
CesleySCruz
 
Linux file system nevigation
Linux file system nevigation
hetaldobariya
 
linux chapter 5.pptx lesson About introduction to linux
linux chapter 5.pptx lesson About introduction to linux
zakiaxmed534
 
Linux Notes-1.pdf
Linux Notes-1.pdf
asif64436
 
Ad

Recently uploaded (20)

How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Ad

Basics of UNIX Commands

  • 1. BASICS OF UNIX COMMANDS Prepared By:- Subra Kumar Das Designation: Operations Support Analyst Version 1.0
  • 2. 1. Introduction to Unix 2. What is File & Directory ? 3. Pathnames 4. Listing files and directories 5. Making Directories 6. Changing to a different directory 7. Copying Files and directories 8. Moving Files and directories 9. Removing files and directories 10.Creating a file using vi editor 11.Displaying the contents of a file on the screen 12.Searching the contents of a file 13.Redirecting the Output 14.Redirecting the Input 15.Pipes 16.Wildcards Agenda
  • 4. Go back to Agenda • UNIX Operating system originally developed in 1969 by a group of AT&T employees at Bell Labs. • Various flavours of Unix & Unix-like OSes are Solaris, Linux etc. • Designed to be portable, multi-tasking & multi-user in a time-sharing configuration. • Unix systems are characterized by various concepts: – Use of plain text for storing data. – A hierarchical file system. – Treating almost everything as files. – Use of a large number of small programs that can be strung together, as opposed to using a single program that has the same functionality. • Unix Philosophy :- “Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.” History of UNIX
  • 5. What is File & Directory ?
  • 6. Go back to Agenda Files: Everything in Unix is a file!! Directories: A directory is a file that contains directory entries. • Each directory entry contains a file name along with a structure of information describing the attributes of the file. – Type of the file (normal file/directory/device file/soft link/hard link etc.) – Size of the file – Owner of the file – Permissions for the file (whether other users may access this file) – Time stamps (when the file was last modified/accessed) • Can be considered as a container for files. • When we first login, our current working directory is our home directory. • Our home directory has the same name as our user-name. File & Directory in UNIX
  • 7. Go back to Agenda There are two special directories called (.) and (..) The current directory (.) In UNIX, (.) means the current directory, so typing $ cd . means stay where we are. The parent directory (..) (..) means the parent of the current directory, so typing $ cd .. will take us one directory up the hierarchy. Note: typing cd with no argument always returns us to our home directory. This is very useful if we are lost in the file system. More about Directories
  • 8. Go back to Agenda ~ (our home directory) Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at our home directory. So typing $ ls ~/unix_session will list the contents of our unix_session directory, no matter where we currently are in the file system. More about Directories
  • 10. Go back to Agenda Pathname enables us to know where we are in relation to the whole file system. Command: pwd Meaning: Present Working Directory Description: The pwd command prints the absolute pathname of our current working directory. For example, to find out the absolute pathname of our home-directory, We need to type cd to get back to our home-directory and then type $ pwd which means that subra (our home directory) is in the home sub-directory, which is in the top-level root directory called " / " . Pathnames in UNIX
  • 11. Listing files and directories
  • 12. Go back to Agenda Command: ls Meaning: List Description: The ls command ( lowercase L and lowercase S ) lists the contents of our current working directory. $ ls Listing files and directories
  • 13. Go back to Agenda • There may be no files visible in our directory, in which case, the UNIX prompt will be returned. • Files beginning with a dot (.) are known as hidden files and are not listed by ls command • To list all files in a directory including those whose names begin with a dot, we need to type $ ls –a Where –a is an option and means all • To list contents in a directory other than the present working directory, we need to type $ ls < path to directory > Listing files and directories
  • 15. Go back to Agenda Command: mkdir <directory or path> Meaning: Make Directory Description: The mkdir command creates new sub-directory within the current working directory. $ mkdir unix_session To cross-verify if the directory has been created or not, we can type ls command, which will show the new sub-directory named unix_session within the current working directory Making directories
  • 16. Changing to a different directory
  • 17. Go back to Agenda Command: cd <directory or path> Meaning: Change Directory Description: The cd command changes working directory to a different directory specified with the command. $ cd unix_session To cross-verify if the directory has been created or not, we can type ls command, which will show the new sub-directory named unix_session within the current working directory Changing to a different directory
  • 18. Copying File & Directory
  • 19. Go back to Agenda Command: cp < source_path > < destination_path > Meaning: Copy Description: The cp command copies files/directories from source path to destination path. To copy files: $ cp /home/subra/abc.txt /home/subra/unix_session/ To cross-verify if the file abc.txt has been copied or not, we can type ls /home/subra/unix_session/, which will show the new file named abc.txt within the destination directory. Copying File in UNIX
  • 20. Go back to Agenda To copy directory: $ cp -r /home/subra/unix_session/ver1/ /home/subra/ver1 Where –r means recursive To cross-verify if the directory has been copied to /home/subra or not, we can type ls /home/subra/ which will show the directory named ver1 within the destination path. Copying Directory in UNIX
  • 21. Moving File & Directory
  • 22. Go back to Agenda Command: mv < source_path > < destination_path > Meaning: Move Description: The mv command moves files/directories from source path to destination path. To move files: $ mv /home/subra/unix_session/abc.txt /home/subra/abc.txt To cross-verify if the file abc.txt has been moved or not, we can type ls /home/subra/unix_session/, which will not contain abc.txt. Moving File in UNIX
  • 23. Go back to Agenda To move directory: $ mv /home/subra/unix_session/ver1/ /home/subra/ver1 To cross-verify if the directory has been moved to /home/subra or not, we can type ls /home/subra/ which will show the directory named ver1 within the destination path. Moving Directory in UNIX
  • 24. Removing File & Directory
  • 25. Go back to Agenda Command to remove a file: rm < file_path > Meaning: Remove Description: The rm command removes (deletes) file from the file path. Command to remove a directory: rmdir < directory_path > Meaning: Remove Directory Description: The rmdir command removes (deletes) directory from the directory path. We need to make sure directory which we need to remove is empty, as UNIX will not let us remove a non-empty directory with rmdir. Removing File & Directory in UNIX
  • 26. Go back to Agenda Command to remove a non-empty directory: rm –r < file_path > Meaning: Remove everything recursively Description: The rm command removes (deletes) all files and directories in the directory named in the command. However, it would also present a prompt for approval to delete each of the files. Command to remove a non-empty directory without receiving a prompt for each file : rm -rf < directory_path > Meaning: Remove everything recursively and forcefully Description: The rmdir command removes (deletes) directory from the directory path. Removing non-empty Directory in UNIX
  • 27. Creating a file using vi editor
  • 28. Go back to Agenda To create a file called unix_file containing a list of statements, we need to type $ vi unix_file.txt Then type in the names of some OS. Press [Return] after each one. Zero is a number. A is a Capital Letter Alphabet b is a small letter Alphabet. zero is also a number Apple is fruit UNIX is OS WIN is OS ^D {this means press [Ctrl] and [d] to stop} Type: :wq Where w means write (save) and q means quit. Creating a file using vi editor
  • 29. Displaying contents of a file on screen
  • 30. Go back to Agenda clear (clear screen) Before we start the next section, we may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood. At the prompt, we need to type $ clear This will clear all text and leave us with the $ prompt at the top of the window. cat (concatenate) The command cat can be used to display the contents of a file on the screen. Type: $ cat unix_file.txt If the file is longer than the size of the window, so it scrolls past making it unreadable. Displaying contents of a file on screen
  • 31. Go back to Agenda less The command less writes the contents of a file onto the screen a page at a time. Type $ less unix_file.txt We can press the [space-bar] if we want to see another page, and type [q] if we want to quit reading. As we can see, less is used in preference to cat for long files. Displaying contents of a file on screen
  • 32. Go back to Agenda head The head command writes the first n no. of lines of a file to the screen. Then we need to type $ head -5 unix_file.txt Which will print first 5 lines of a file named unix_file.txt tail The tail command writes the last n no. of lines of a file to the screen. we need to type $ tail -5 unix_file.txt Which will print last 5 lines of a file named unix_file.txt Displaying contents of a file on screen
  • 34. Go back to Agenda grep It searches files for specified words or patterns. We can type $ grep zero unix_file.txt grep will print out each line containing the word zero in a file named unix_file.txt We can try typing $ grep Zero unix_file.txt In this case, grep will print out each line containing the word Zero in a file named unix_file.txt The grep command is case sensitive; it distinguishes between Zero and zero. To ignore upper/lower case distinctions, we can use the -i option, i.e. $ grep -i zero unix_file.txt Searching the contents of a file
  • 35. Go back to Agenda To search for a phrase or pattern, we must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type $ grep -i ‘numeric zero' unix_file.txt Some of the other options of grep are: -v display those lines that do NOT match -n precede each matching line with the line number Don't forget, we can use more than one option at a time. For example, the number of lines without the words zero or Zero is $ grep -iv science science.txt Searching the contents of a file
  • 37. Go back to Agenda We use the > symbol to redirect the output of a command. $ echo startoffile > unix_file_new.txt Above command will create a new file with a name unix_file_new.txt and startoffile as a content in the first line. The symbol >> appends standard output to a file. So to add more items to the file unix_file.txt, we need to type $ echo Mango is a fruit >> unix_file.txt Which will add Mango is a fruit to a file named unix_file.txt After execution of above command, we can type cat command followed by the filename / filepath to verify the same. Redirecting the Output
  • 39. Go back to Agenda We use the < symbol to redirect the input of a command. The command sort alphabetically or numerically sorts a list. To sort the list and output to the screen $ sort < unix_file.txt Which will sort the list alphabetically for the start letter. Note: Capital Letter will be higher in the order always then the small letter. To output the sorted list to a file $ sort < unix_file.txt > sorted_unix_file.txt Redirecting the Input
  • 40. Pipes
  • 41. Go back to Agenda What we really want to do is connect the output of the cat command directly to the input of the grep command. This is exactly what pipes do. The symbol for a pipe is the vertical bar | For example, by typing $ cat unix_file.txt $ grep zero unix_file.txt >> unix_file_zero.txt We get a new file named unix_file_zero.txt with all the lines having zero in it. Now $ cat unix_file.txt | grep zero >> unix_file_zero.txt will give the same result as above, but it is quicker and cleaner as it takes less number of lines. Pipes
  • 43. Go back to Agenda The * wildcard The character * is called a wildcard, and will match against none or more character(s) in a file (or directory) name. For example, in our unixstuff directory, $ ls list* This will list all files in the current directory starting with list.... By typing $ ls *list This will list all files in the current directory ending with ....list Wildcards
  • 44. Go back to Agenda The ? wildcard The character ? will match exactly one character. By typing $ ls ?list.txt Will list out all the files ending with list like flist, slist, mlist but not fglist as single ? is used Wildcards
  • 45. Go back to Agenda The [ ] wildcard Defines class of characters. For range of characters – can be used. To exclude certain character or range of characters ! Can be used. By typing $ ls [a-z]*.txt Will list out all the txt files starting with a to z in lower case $ ls [A-Z]*.txt Will list out all the txt files starting with A to Z in upper case Wildcards
  • 46. Go back to Agenda By typing $ ls [0-9]*.txt Will list out all the txt files starting with numeric 0 to 9 $ ls [!0-9]*.txt Will list out all the txt files not starting with numeric 0 to 9 Similarly to exclude all the files starting with [a-z] and [A-Z], we can use $ ls [!a-zA-Z]*.txt Wildcards