VI Editor Commands and Networking Commands in Linux

VI Editor Commands and Networking Commands in Linux
2. Vi Editor & its Modes, Introduction of Basic administrative commands.

  • i – Insert text entry mode (insert mode)
  • ESC – Terminate insert mode
  • a – Append text after current character (append mode)
  • A – Write text at the end of line
  • u – Undo last changes
  • U – Restore current changes
  • o – New line below current line
  • O – New line above current line
  • dd – Delete a line
  • 3dd – Delete 3 lines.
  • dw – Delete word
  • cw – Change word
  • 4dw – Delete 4 words
  • x – Delete a character at the cursor
  • r – Replace a character

Moving Cursor in a file

  • k – Move cursor up
  • j – Move cursor down
  • h – Move cursor left
  • l – Move cursor right

Saving and Closing the file

  • Shift+zz – Save the file and quit
  • :w – Save the file but keep it open
  • :q  – Quit without saving
  • :wq – Save the file and quit
  • :q! – Quit without saving
  • :set showmode -Insert mode is one bye default is off

Linux File Permissions
Read (r)
Write (w)
Execute (x)
In Linux, each file is associated with an owner and a group and assigned with permission access rights for three different classes of users
u – owner.
g – group.
o – All other users.
a – All users, identical to ugo.

– Removes the specified permissions.
+ Adds specified permissions.
= Changes the current permissions to the specified permissions.
First you have crate a file using following commands.
$ touch file1 file2 file3
$ chmod o+x file1
$ chmod u-w, g+x file1
$ chmod u=rwx, g=rx, o=r file1
$ chmod a=rwx file1

Each read, write, and execute permissions have the following number value:
r             (read) = 4
w           (write) = 2
x        (execute) = 1
no permissions = 0

To find out the file’s permissions in numeric mode simply calculate the totals for all users classes
Owner: rwx=4+2+1=7
Group:   r-x=4+0+1=5
Others:  r   =4+0+0=4

Give the file’s owner read and write permissions and only read permissions to group members and all other users:
$ chmod 644 file2
Give the file’s owner read, write and execute permissions, read and execute permissions to group members and no permissions to all other users:
$ chmod 750 file3
To change the permissions of all files and subdirectories under the  team/cricket directory to 744 you would use: first you have create a directory using below command.
$ mkdir team
$ mkdir team/cricket
$ chmod -R 744  team/cricket

3. Usage of basic Network related commands in Linux.
Ping(Packet Internet Groper)
ping command is used to ensure that a computer can communicate to a specified device over the network.
$ ping
$ ping

nslookup command queries the DNS in order to fetch the IP address or the domain name from DNS records.
$ nslookup

This command is used to get the route of a packet.
$ traceroute

host command is used to find domain name associated with the IP.
$ host
$ host

netstat(Network Statistics) is the command that is used to display routing table, connection information.
$ netstat
$ netstat -r

ARP(Address Resolution Protocol) command is used to display of IP address to MAC address.
$ arp

Show ip address
$ ifconfig

To enable an interface
ifup eth0
To disable an interface
ifdown eth0

Linux iwconfig is used to configure the wireless network interface. It is used to set and view the basic WI-FI details like SSID and

4. How to Check if a File or Directory Exists.
To test for the file /tmp/test.log, enter the following from the command line:
[email protected]:~$ test –f /tmp/test.txt
The first line executes the test to see if the file exists. The second command, echo, displays the results 0 meaning that the file exists, 1 means no file was found.
echo $?
In our example, the result was 1.
[email protected]:~$ echo $?

Now try creating a file, then testing for it:
[email protected]:~$ touch /tmp/test.txt
As we have created the file beforehand, the result now is 0:
[email protected]:~$ test –f /tmp/test.txt
[email protected]:~$ echo $?

You can also use square brackets instead of the test command:
[email protected]:~$ [ –f /tmp/test.txt ]
[email protected]:~$ echo $?
How to Check if a Directory Exists
To check if a directory exists, switch out the –f option on the test command for –d (for directory):
[email protected]:~$ test –d /tmp/test
[email protected]:~$ echo $?
Create that directory, and rerun the test command:
[email protected]:~$ mkdir /tmp/test
[email protected]:~$ test –d /tmp/test
[email protected]:~$ echo $?

Open Source Software Lab Manual

About me