Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help! Iwill grade it best ( linux ls commandcodes will be written in C++

ID: 3618932 • Letter: P

Question

Please help! Iwill grade it best ( linux ls commandcodes will be written in C++ or C) if you can please run the program that youdesigned! implement anapplication to mimic the behavior of ls command in *nixsystems. the programis exected work as follows 1.)$./ls Lists thecontent of current directory 2.) $./lsdierctory_name Lists thecontents of directory_name 3.) $./ls -rdirectory_name Lists thecontents of the directory_name. Then lists contents of allof the subdirectories that is under directory_name,recursively. Please help! Iwill grade it best ( linux ls commandcodes will be written in C++ or C) if you can please run the program that youdesigned! implement anapplication to mimic the behavior of ls command in *nixsystems. the programis exected work as follows 1.)$./ls Lists thecontent of current directory 2.) $./lsdierctory_name Lists thecontents of directory_name 3.) $./ls -rdirectory_name Lists thecontents of the directory_name. Then lists contents of allof the subdirectories that is under directory_name,recursively.

Explanation / Answer


//Hope this will helpyou. //You can use DIR structureand opendir system call in linux that will help to scandirectory. //You can extend it what youwant .

#include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h>
int main(int argc, char *argv[]) { DIR *dir; struct dirent *drent;
if(argc < 2) { fprintf(stderr, "%s <directory> ", argv[0]); return EXIT_FAILURE; }
if((dir = opendir(argv[1])) == NULL) { fprintf(stderr, "Errore opendir() "); return EXIT_FAILURE; }
while((drent = readdir(dir)) != NULL) { fprintf(stdout, "--> %s ", drent->d_name); } if(closedir(dir) < 0) { fprintf(stderr, "Errore closedir() "); return EXIT_FAILURE; } } #include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h>
int main(int argc, char *argv[]) { DIR *dir; struct dirent *drent;
if(argc < 2) { fprintf(stderr, "%s <directory> ", argv[0]); return EXIT_FAILURE; }
if((dir = opendir(argv[1])) == NULL) { fprintf(stderr, "Errore opendir() "); return EXIT_FAILURE; }
while((drent = readdir(dir)) != NULL) { fprintf(stdout, "--> %s ", drent->d_name); } if(closedir(dir) < 0) { fprintf(stderr, "Errore closedir() "); return EXIT_FAILURE; } }