Task #1 Write a shell script (script l sh) to create a few directories as shown
ID: 3886036 • Letter: T
Question
Task #1 Write a shell script (script l sh) to create a few directories as shown below in your current directory (dir1, dir2) a few files (file1 in current directory, file10 in dirl, file20 in dir2, and a symbolic-link link1 (to link to file20). You are going to create the files and directories in depth-first order (and left to right). That is, dirl will be created first, then file10, and so on. You should create linkl (a softlink to file20) after file20 is created From your current dirl dir2 file1 ink file10 file20 Copy and paste your shell script (scriptl.sh) here Copy and paste the run-output of your shell script (scriptl.sh) hereExplanation / Answer
#include <dirent.h> // directory header
#include <iostream> // input/output stream
// use a few things from the std namespace for console I/O
using std::cout;
using std::cin;
using std::endl;
int main () // entry point of the program
{
// first off, we need to create a pointer to a directory
DIR *pdir = NULL; // remember, it's good practice to initialise a pointer to NULL!
pdir = opendir ("."); // "." will refer to the current directory
struct dirent *pent = NULL;
cout << " ERROR! pdir could not be initialised correctly";
exit (3);
} // end if
while (pent = readdir (pdir)) // while there is still something in the directory to list
{
if (pent == NULL) // if pent has not been initialised correctly
{ // print an error message, and exit the program
cout << " ERROR! pent could not be initialised correctly";
exit (3);
}
// otherwise, it was initialised correctly. Let's print it on the console:
cout << pent->d_name << endl;
}
// finally, let's close the directory
closedir (pdir);
cin.get (); // pause for input
return EXIT_SUCCESS; // everything went OK
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.