Basic Commands to Copy, Move, rename, remove files and Directories with Linux.

 How to Copy, Move, Rename Remove files and Directories

Copying files into Directories

cp <source filename> <destination directory in which to paste the file>

eg. cp Cent Downloads


Copying Directories from one location to another

cp -rvfp <filename> <destination name>

eg. cp -rvfp gyani1 gyani2


Moving files from one location to another

mv <filename> <Destination directory>

eg. mv Cent gyani2


Moving a directory from one location to another

mv <directory name> <destination dir name>

eg. mv gyani2 gyani1


Renaming a file

mv <old name> <new name>

eg. mv Cent Centos


Renaming a Directory

  •     The procedure and command for renaming the directory is the same as renaming a file
               mv <old name> <new name>

               eg. mv gyani2 gyani4


Removing a File

rm <filename> or rm -f <filename>

eg. rm cent


Removing an empty directory

rmdir <directory name>

eg. rmdir gyani2


Removing a directory with files or directories inside

A directory which is having some contents inside it cannot be removed by rmdir command. There are two ways to delete the directory with contents

  1. Remove the contents inside the directory and then run rmdir command
  2. Run rm -rf <directory name> (where r stands for recursive and f stands for forcefully)


Comments

Popular posts from this blog

Linux Filesystem Hierarchy

Basic Commands to Create files and Directories with Linux.