cp (copy) aur mv (move) commands CentOS/Linux me files aur directories ko copy aur move karne ke liye use hoti hain. Inka syntax aur options kaafi simple aur straightforward hain.
- Purpose: Files ya directories ko copy karna.
cp [options] source destination
-
Single File Copy:
cp file1.txt /path/to/destination/
file1.txtko specified destination folder me copy karega.
-
Multiple Files Copy:
cp file1.txt file2.txt /path/to/destination/
file1.txtaurfile2.txtko ek saath destination folder me copy karega.
-
Directory Copy (Recursively):
cp -r directory_name /path/to/destination/
r: Directory aur uske andar ki saari files/subdirectories ko recursively copy karega.
-
Preserve File Attributes:
cp -p file1.txt /path/to/destination/
p: Original file ke permissions, ownership, aur timestamps ko preserve karega.
-
Interactive Mode:
cp -i file1.txt /path/to/destination/
i: Agar destination par file pehle se exist hai, to confirmation maangega.
- Purpose: Files ya directories ko move karna ya rename karna.
mv [options] source destination
-
Move a File:
mv file1.txt /path/to/destination/
file1.txtko destination par move karega (original location se delete ho jayega).
-
Rename a File:
mv oldname.txt newname.txt
- File ka naam
oldname.txtsenewname.txtme change karega.
- File ka naam
-
Move a Directory:
mv directory_name /path/to/destination/
- Poore directory ko specified destination par move karega.
-
Interactive Mode:
mv -i file1.txt /path/to/destination/
i: Agar destination par file pehle se exist hai, to confirmation maangega.
-
Force Move:
mv -f file1.txt /path/to/destination/
f: Forcefully move karega, bina confirmation ke overwrite karega.
| Feature | cp Command |
mv Command |
|---|---|---|
| Action | Copy file/directory. | Move or rename file/directory. |
| Source File | Original file remains. | Original file is removed. |
| Usage | For creating duplicates. | For relocation or renaming. |
-
Backup File Before Editing:
cp config.conf config.conf.bak
config.confka backupconfig.conf.bakke naam se banayega.
-
Move All Files to Another Directory:
mv *.txt /path/to/destination/- Current directory ke saare
.txtfiles ko destination par move karega.
- Current directory ke saare
-
Rename and Move Together:
mv file1.txt /path/to/destination/renamed_file.txt
file1.txtko rename karke destination parrenamed_file.txtke naam se move karega.
-
Preserve Attributes While Copying a Directory:
cp -rp directory_name /path/to/destination/
r: Recursively copy karega.p: Permissions aur ownership preserve karega.
- Backup Before Moving: Important files ko move karte waqt backup banana zaroori hai.
- Interactive Option:
ioption use karna overwrite ke risk ko reduce karta hai. - Combine with Wildcards: Commands ke saath `` aur
?jaise wildcards ka use karna process ko efficient banata hai.
By mastering cp aur mv, aap CentOS/Linux me file management tasks ko efficiently handle kar sakte hain!