rm, mv, wc and cp command in Unix Lab (BCA-506P) - Practical-3

 




Execute the following list of basic commands in UNIX:

(i) rm (ii) mv (iii) wc  (iv) cp

(1) rm



The rm command in Unix operating systems is used to remove or delete files and directories. It is a powerful command, and you should use it with caution because deleted files and directories are typically not recoverable.

The basic syntax of the rm command is as follows:

                rm [options] [file(s) or directory(ies)]

Options: 

-i (Interactive Deletion): 

This option is used to ask the user for confirmation before removing each file, you have to press y for confirm deletion, any other key leaves the file un-deleted.

 -f (Force Deletion): rm prompts for confirmation removal if a file is write protected. The -f option overrides this minor protection and removes the file forcefully.




(2) mv

mv command is used to move existing file or directory from one location to another. It is also used to rename a file or directory. 

The basic syntax of the rm command is as follows:

                rm [options] [file(s) or directory(ies)]

Options: 

-i (Interactive Deletion): 

This option is used to ask the user for confirmation before removing each file, you have to press y for confirm deletion, any other key leaves the file un-deleted.

 -f (Force Deletion): rm prompts for confirmation removal if a file is write protected. The -f option overrides this minor protection and removes the file forcefully.


(3) cp

The cp command is used to copy directories and files. The command contains three primary operation modes, represented by the argument types shown to the program to copy a file to other files, multiple files to any directory, or to copy the whole directories to other directories.

The basic syntax of the cp command is as follows:

                cp [options] [source file/directory destination file/directory]

Options: 

-i (Interactive Deletion): 

This option is used to ask the user for confirmation before coping each file, you have to press y for confirm deletion, any other key leaves the file un-deleted.

 -f (Force Deletion): rm prompts for confirmation removal if a file is write protected. The -f option overrides this minor protection and removes the file forcefully.

1. Copy file cmd1.txt in current directory with the name cmd2.txt.

$ cp cmd1.txt cmd2.txt




2. Copy a file cmd1.txt in ‘ankita1’ directory with the same name that is cmd1.txt

                                $ cp cmd1.txt ankita1/


3. Copy a file cmd1.txt in ‘ankita1’ directory with different name

                                  $ cp cmd1.txt ankita1/cmd2.txt


4. Use -i option of cp command for interactive mode to prompt before overwriting an existing file.

                     $ cp -i cmd1.txt cmd2.txt
                    cp: overwrite 'cmd2.txt' ? y


5. Copy multiple files to a specified directory.

                            $ cp cmd1.txt cmd2.txt khushi1/


6. Copy multiple files using wild card. It copies all files with extension .txt to 'deepika1' directory.

                                $ cp *.txt deepika1/






Post a Comment

0 Comments