Copy A File From RemoteHost to LocalHost

DESCRIPTION:
  • Consider we want to copy test.txt file from remote machine(192.168.2.5) to local machine(192.168.1.10)
  • We need to use scp(secure copy) command to establish above need
  • For this you want the root password of the remote host.

COMMAND:

    scp  <remote username>@<remote ipaddress>:<source with path> <dest path with file name>

    example:
    scp root@192.168.2.5:/home/remote/test.txt /home/user/Desktop/test.txt
  • It will ask the remote machine password to enter
  • Now file will successfully copy to remote machine 

Copy A File From Localhost to Remotehost


DESCRIPTION:
  • Consider we want to copy test.txt file from local machine(192.168.1.10) to remote  machine(192.168.2.5)
  • We need to use scp(secure copy) command to establish above need
  • For this you want the root password of the remote host.

COMMAND:

    scp <source file> <remote username>@<remote ipaddress>:<dest path with file name>

    example:
    scp test.txt root@192.168.2.5:/home/user/Desktop/test.txt
  • It will ask the remote machine password to enter
  • Now file will successfully copy to remote machine 



Shell Script To Find The Area Of A Triangle

SCRIPT:

#!/bin/bash

#This script used to find the area
#of the triangle. user need to give
#the base and height of the triangle

echo -n "Please enter the base and height of the triangle : "
read base
read height
area=`expr "scale=2; 1/2*$base*$height"|bc`
echo "area of the triangle = $area"

RUN:

sh triangle.sh

OUTPUT:

Please enter the base and height of the triangle : 10
25
area of the triangle = 125.00


Display All The Files From A Directory Using C

DESCRIPTION:
  • This program get the directory path from the user and display all the filed from the directory.
  • We should add dirent.h header file to accomplish this program.


PROGRAM:

#include <stdio.h>

#include <string.h>

#include <dirent.h>
int main (int argc, char *argv[])
{
    DIR *directory;
    struct dirent *file;    
    directory = opendir (argv[1]);
    int directory_length = strlen(argv[1]);
    if (directory != NULL){
        while (file = readdir (directory))
                  printf("FILE : %s \n",file->d_name);

        (void) closedir (directory);
      }
      else
        perror ("Not able to open the directory\n");
    return 0;
}



COMPILE

gcc -o out scan.c

RUN:
  • Pass the directory name with the path as argument to the program
./out /home/sujin/directory

OUTPUT:

FILE : favicon.ico
FILE : README.txt
FILE : monkey.jpg 
FILE : index.html