Question

In: Computer Science

Systems Programming in Linux using C Remake the version of the ls -ialR command in C.....

Systems Programming in Linux using C

  1. Remake the version of the ls -ialR command in C.. In this version of ls, you must also consider symbolic file types.
  2. Make sure you have file header comments and function header comments. Also, write inline comments whenever necessary.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

Here is the C code for ls -ialR command.

C-PROGRAM :

// Including necessary or needed header files

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

// Starting of main function

int main(int argc, char* argv[])
{

// Declaring the variable DIR
DIR *alldir;
struct dirent *allfile; // all available files
struct stat allstat; // stats of the files

// buffer

char buf[512];

// opening the current dir
alldir = opendir(argv[1]);

// Dir must not equal to Null / Existance of dir must
while((allfile = readdir(alldir)) != NULL)
{

// Printing all files names
sprintf(buf, "%s/%s", argv[1], allfile->d_name);     
stat(buf, &allstat);

// Printing Stats of the files
printf("%zu",allstat.st_size);
printf(" %s\n", allfile->d_name);
}

// Closing the Dir or stats on terminating of program
closedir(alldir);
}

The above program Output : -

Execute the program in linux by this command:- ./program.out Ashok

You will get total directories with name and stats.

Program compiled in CodeBlocks Screenshot:-

In bottom of the screen You can check all directries under that file. ( from "checking for existance")

First it will check for for existance than show all dir. .


Related Solutions

Systems Programming - File Operations Create your version of the tail command in Linux using C...
Systems Programming - File Operations Create your version of the tail command in Linux using C The lseek system call allows you to move the current position anywhere in a file. The call lseek(fd, 0, SEEK_END) moves the current position to the end of the file. The tail command displays the last ten liens of a file. Try it. tail has to move, not to the end of the file, but to a spot ten lines before the end of...
Linux Directories, File Properties, and the File System in C Understanding Unix/Linux Programming Your version of...
Linux Directories, File Properties, and the File System in C Understanding Unix/Linux Programming Your version of mv command The mv command is more than just a wrapper around the rename system call. Write a version of mv that accepts two argument. The first argument must be the name of a file, and the second argument may be the name of a file or the name of a directory. If the destination is the name of a directory, then mv moves...
a) b) c) Compare and contrast systems programming in Windows as against systems programming in Unix/Linux....
a) b) c) Compare and contrast systems programming in Windows as against systems programming in Unix/Linux. CR, 8 Explain the term structured exception handling (SEH) as used in systems programming and give a practical example of how it can be used to handle errors in a block of code. AP, 7 Write a C/C++ system program to delete an unwanted file in the Windows file system. Compile and run the program and copy the source code into your answer booklet....
Linux Directories, File Properties, and the File System in C Code your version of mv command...
Linux Directories, File Properties, and the File System in C Code your version of mv command in C The mv command is more than just a wrapper around the rename system call. Write a version of mv that accepts two argument. The first argument must be the name of a file, and the second argument may be the name of a file or the name of a directory. If the destination is the name of a directory, then mv moves...
Linux Directories, File Properties, and the File System in C Your version of find command Try...
Linux Directories, File Properties, and the File System in C Your version of find command Try running the find command in the shell and observe the output. Try it in different folders to make sure you understand what it prints out. $ find Write your version of the find command and add comments.
This program is a simple version of the linux shell using execvp by forking using C...
This program is a simple version of the linux shell using execvp by forking using C Currently this program of the shell assumes user enters no spaces before and no extra spaces between strings. Using exec, an executable binary file (eg: a.out) can be converted into a process. An example of using exec is implementing a shell program or a command interpreter. A shell program takes user commands and executes them. int execvp(const char *file, char *const argv[]); Same as...
Systems Programming - File Operations in Linux using C Preventing copying the same file What does...
Systems Programming - File Operations in Linux using C Preventing copying the same file What does the standard cp do if you try to copy a file onto itself? $ cp file1 file1 cp: 'file1' and 'file1' are the same file Modify cp1.c to handle the situation and include comments. /** * @file cp1.c * @brief Uses read and write with tunable buffer size * usage: cp1 src dest */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #define BUFFERSIZE...
a) Observe the following Linux commands and work out what each command does: 1) $ ls...
a) Observe the following Linux commands and work out what each command does: 1) $ ls –al 2) $ /etc/profile 3) $ chmod 200 final_assignment.txt b) Consider a scenario where Bob has downloaded his messages to the local machine with an access of POP3, he can create mail folders and move the downloaded messages into the folders. Bob can then delete messages, move messages across folders, and search for messages (by sender name or subject). But this paradigm—namely, folders and...
unix/Linux Create a tar command using the man command and the link referred to in To...
unix/Linux Create a tar command using the man command and the link referred to in To Practice and Explore: Text File Utilities #9. Preliminaries Use the man pages to learn more about tar Review the links referred to in To Practice and Explore: Text File Utilities #9 to see examples of using tar command Perform Use tar "to stuff" three files and then "unstuff" them into a new directory. Include the -v option. Task ll to show the original 3...
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT