← Back to Bash Course | Chapter 9: File Testing & Filesystem | Lesson 9 of 13

cp, mv, rm कमांड्स

cp, mv और rm एक page को photocopy करना, एक page को दूसरे folder में move करना, और एक page को shredder में डालना जैसा है। हर एक files को अलग तरीके से handle करता है।

In this page:

  1. cp, mv, rm
Syntax
bash
cp source destination
mv source destination
rm [-r] file_or_directory

cp, mv, rm

cp files copy करता है, mv उन्हें move या rename करता है, और rm उन्हें delete करता है। cp -r और rm -r directories पर recursively operate करते हैं। यह shell scripts में हर समय उपयोग होने वाले fundamental filesystem manipulation commands हैं।

Warning: rm -rf confirmation के बिना recursively delete करता है — path में एक typo intended से कहीं ज़्यादा destroy कर सकता है।

उदाहरण: cp, mv, rm

bash
#!/bin/bash
echo "original" > original.txt

cp original.txt copy.txt
mv copy.txt renamed.txt

ls original.txt renamed.txt

rm renamed.txt
echo "renamed.txt removed"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. rm -rf एक empty variable के साथ चलाना, जैसे rm -rf "$dir/", जो गलत path delete कर सकता है।
  2. cp या mv से files को बिना -i या -n के overwrite करना।
  3. एक directory copy करते समय -r भूल जाना।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.