Professional Documents
Culture Documents
Linux Practical2
Linux Practical2
Linux Practical2
Familiarize with Unix/Linux Log In/Log Out and various other commands &vi editor
1. Local Login:
login:
• The login command initiates a new login session on the local system.
• It prompts for a username and password.
• Once logged in, it provides access to the system's resources.
2. Remote Login:
3. Logout:
exit:
$ logout
3. Editing Text:
• Inserting Text:
• Press i to enter insert mode before the cursor.
• Press a to enter insert mode after the cursor.
• Press o to open a new line below the current line and enter insert mode.
• Deleting Text:
• Press x to delete the character under the cursor.
• Press dd to delete the entire line.
• Press d$ to delete from the cursor to the end of the line.
• Press dw to delete a word.
5. Searching:
• Undoing Changes:
• Press u to undo the last change.
• Redoing Changes:
• Press Ctrl + r to redo changes that were undone.
• Copying and Pasting:
• Position the cursor where you want to start copying.
• Press v to enter visual mode.
• Move the cursor to select the text.
• Press y to copy (yank) the selected text.
• Move the cursor to where you want to paste.
• Press p to paste the copied text after the cursor.
Output of Some basic commands on terminal:
Vi Editor -
Practical -2
Develop simple shell programs using Bash or any other shell in Linux.
chmod +x abc.sh
~$ ls -l
total 4
-rw-r--r-- 1 user user 0 Apr 21 15:39 2024-04-21-terminal-1.term
-rw-r--r-- 1 user user 0 Apr 21 15:39 2024-04-21-terminal-2.term
-rw-r--r-- 1 user user 20 Apr 21 14:31 abc
-rwxr-xr-x 1 user user 57 Apr 21 15:44 abc.sh
-rw-r--r ~$
~$ ./abc.sh
Linux Shell Testing
Welcome in linux Shell
#!/bin/bash
# Prompt the user to enter the first number
echo "Enter the first number:"
read num1
# Prompt the user to enter the second number
echo "Enter the second number:"
read num2
# Perform the addition
sum=$((num1 + num2))
# Display the result
echo "The sum of $num1 and $num2 is: $sum"
Output:
~$ vi sum.sh
~$ ls -l
total 5
~$ chmod +x sum.sh
~$ ./sum.sh
20
30
Program-3
#!/bin/bash
read pattern
echo "Enter the filename:"
read filename
Output :
vi grep1.sh
~$ chmod +x grep1.sh
~$ ./grep1.sh
first
sum.sh
#!/bin/bash
Output:
$ cat>file
Ctrl+d
Program:
#!/usr/bin/awk -f
print $1, $3
$3 == "Male"
NR > 1 {
total += $2
NR == 1 {
print "Welcome " $1 ", you are a " $4 ". How can I assist you?"
# End of script
END {
if (NR > 1) {
Output: