Question

In: Computer Science

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

  1. 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 the file into that directory. Otherwise mv rename the file if possible.
  2. Add comments to code.

Solutions

Expert Solution

mv stands for move. mv is used to move one or more files or directories from one place to another in file system like UNIX. It has two distinct function

Uses of mv command:

It rename a file or folder.
It moves group of files to different directory.

Syntax of mv command

mv [Option] source destination

1)Here is a version of mv command where the first argument is the name of a file, and the second argument is the name which will rename this file.

Syntax

mv argument1 argument2

Command:

Here we use the mv commnad to rename the file named "newfile" to file "orkut"

This command will rename the file and remove the previous name. The contents of teh file remains the same.

As given in the question, this will work only to rename a file.

2)Here is a version of mv command where the first argument is the name of a file, and the second argument is the direcotry which will move this file to the given directory.

Syntax:

mv argument1 /argument2

This will move the file with the name orkut to the folder or directory /home.

The file will no longer exist in the original place and will be move permanently to /home directory.

I have showed you the new location of the file by going to the honme dirctory using cd and using ls to display the list of files in it.

Note that this requires root priviledges so I have used sudo for it.

If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.

Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.


Related Solutions

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.
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...
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...
Systems Programming in Linux using C Remake the version of the ls -ialR command in C.....
Systems Programming in Linux using C Remake the version of the ls -ialR command in C.. In this version of ls, you must also consider symbolic file types. Make sure you have file header comments and function header comments. Also, write inline comments whenever necessary.
In the Linux file system, the majority of the file system code exists in the kernel....
In the Linux file system, the majority of the file system code exists in the kernel. research the anatomy of the Linux file system, then discuss the effectiveness or ineffectiveness of this type of architecture. In addition, explain why you feel the way you do and provide support
Using Linux in VirtualBox To display your system date: Type date in the command line, and...
Using Linux in VirtualBox To display your system date: Type date in the command line, and press Enter. What do you see?                                            You might see the abbreviation EDT (Eastern Daylight Time) instead of EST (Eastern Standard Time), or another time zone abbreviation, such as MDT (Mountain Daylight Time) or CST (Central Standard Time). Notice also that UNIX/Linux uses a 24-hour clock. Type Date in the command line, and press Enter. What error do you see?                                    The system error...
Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file...
Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file to have a tab for each delimiter ':'. Hint: use tr 2. Write a Linux command to extract the user names and sort them. Hint: use cut 3. Write a for loop to to display a time table, e.g., 17 x 1 = 17; 17 x 2 = 34; etc., as follows: 17 x 1 = 17 17 x 2 = 34 17 x...
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....
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT