Please find my implemetation:
Here is the code for you:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char *argv[])
{
char fileName[50];
if(argc != 3)
{
printf("Error. Usage: mycp source_file target_file\n");
return 0;
}
strcpy(fileName, argv[1]);
//Attempts to open the file with the name specified by the user
(using the open system call) in read only mode.
int fdIn = open((const char *)fileName, O_RDONLY);
//Displays an error message and quits the program if file open is
unsuccessful.
if(fdIn == -1)
{
printf("Error: Source file doesn't exist.\n");
return 0;
}
strcpy(fileName, argv[2]);
int fdOut = open((const char *)fileName, O_RDONLY);
if(fdOut != -1)
{
printf("Error: Destination file readily exist.\n");
return 0;
}
close(fdOut);
fdOut = open((const char *)fileName, O_CREAT);
fdOut = open((const char *)fileName, O_WRONLY);
char buffer;
int byteCount = 0;
while(read(fdIn, &buffer, 1))
{
write(fdOut, &buffer, 1);
byteCount++;
}
close(fdIn);
close(fdOut);
printf("Copied %d bytes\n", byteCount);
}
Write a C program to Simulate Implementation of Linux *cp* command. Copying Files and directories
Write a C program countFiles.c to be executed on the command line as follows: countFiles <directory> The program should count the (regular) files in the specified directory as well as all subdirectories and output the total number on the console. Files and subdirectories whose names .start with should be ignored! To do this, define a function int countFilesRec(char* dirName)that dirName returns the number of (regular) files in the directory and all the subdirectories. Call the function recursively to count the...
1. the commands you used to create the directories and files in Linux and Windows; 2. the commands you used to determine default permissions in Linux and Windows; 3. the commands you used to change permissions on your files in Linux and Windows; 4. a paragraph about how directories and file permissions work and what was the same or different between Windows and Linux.
Linux Question: I just need the command for the below: How many files are below “/etc/”? In other words, I want the number of files that are in this directory andany directories below it. You will need to use the “find” command to get this number and it is between 500 and 2500.
a) How would you use the ls command to display all of the files/directories in the directory ‘/sbin’ that start with ‘bl’? b) How would you use the ls command to display all of the files/directories in your current directory that contain the word ‘grade’ somewhere in the name and end with ‘.pdf’? c) How would you use the ls command to display all of the files/directories in your current directory that are any two characters followed by the file...
I need some help with the cp command in Unix/Linux. I need to copy all the files in my current directory A03 into the backup directory. How do I do this? I am taking an introductory unix/linux course so I need a basic answer. Thanks.
Run Linux Lite. Determine Linux Lite network settings from the command line. Be able to use the Linux ls command to view files and directories. Be able to use the Linux dot dot notation to view parts of the Linux file system. Run two Linux Lite sessions on the one computer. Analyse Wireshark traffic. Capture DNS or ARP traffic with Wireshark. please show your every steps of screen short and explanation.
Write a C program implementing Linux tr command. You have to specify both symbols and two file names as command line arguments.
Displays the names of the non-hidden files and directories in the current directory, or another directory, along with creation time, and size of file. In case of subdirectories, it displays the word <DIR> instead of file size. At the end, the command should display the total number of files in the directory, the total file size, and the number of sub-directories. Examples: LodgherDir (displays info of all files and directories in current directory) LodgherDir c:\LFromDir (displays info of all files...
Linux System Administration What files are used by the “finger” command? What command did you use? The “uname” command will display certain information about the Linux machine you are using. What option on this command will print the “machine hardware name”? What is the machine hardware name on “loki”? Pay attention to the keyword “machine hardware name”.
Unix/Linux 1 (a)What should my umask be so new directories default to "drwx—x—x"? (b)What will files default to with the umask from the previous question?