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 at cursor (insert mode)
  • ESC – Terminate insert mode
  • a – Write after cursor (append mode)
  • A – Write at the end of line
  • U – Undo all changes to the entire line
  • u – Undo last change
  • o -new line
  • dd – Delete line
  • 3dd – Delete 3 lines.
  • dw – Delete word
  • cw – Change word
  • 4dw – Delete 4 words
  • x – Delete character at the cursor
  • r – Replace 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! – Force Quit, no save

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.

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-x=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 File1
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 File2
To change the permissions of all files and subdirectories under the /var/www directory to 755 you would use:
$ chmod -R 755 /var/www

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 192.168.8.1
$ ping google.com

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

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

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

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

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

ifconfig
Show ip address
$ ifconfig

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

iwconfig
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
Syntax:
iwconfig

4. How to Check if a File Exists.
To test for the file /tmp/test.log, enter the following from the command line:
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 $?
1

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

You can also use square brackets instead of the test command:
[ –f /tmp/test.txt ]
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):
test –d /tmp/test
echo $?
Create that directory, and rerun the test:
touch /tmp/test
test –d /tmp/test
echo $?



Create and Execute First BASH Program:

Open Source Software Lab Manual 

About me