Bash में chown से file ownership कैसे बदलें
chown से file या directory का owner और group बदलें, परिणाम जाँचें और unsafe recursive ownership changes से बचें।
इंटरएक्टिव पाठ शुरू करेंजब कोई file या directory गलत user या group की हो, तब chown उपयोग करें। पहले target देखें, एक स्पष्ट path बदलें और तुरंत परिणाम verify करें। -R तभी जोड़ें जब directory के नीचे हर item को वही ownership चाहिए। Bash chown lesson isolated filesystem में basic form का अभ्यास कराती है।
मौजूदा owner और group जाँचें
ठीक वही path देखें जिसे बदलना है:
ls -ld project
ls -l project/readme.txt
Long listing में permissions और link count के बाद owner तथा group आते हैं। पुष्टि करें कि project सही directory है और target account व group पहले से मौजूद हैं। chown users या groups नहीं बनाता।
Owner और group दोनों बदलें
सामान्य form में path से पहले owner:group आता है:
sudo chown admin:developers project
यह directory entry project का owner admin और group developers बनाता है। भीतर की files अपने आप नहीं बदलतीं। sudo केवल तभी उपयोग करें जब current account को अनुमति न हो; elevated permission गलत नाम या path को सुरक्षित नहीं बनाती।
परिणाम जाँचें:
ls -ld project
सिर्फ owner बदलने के लिए group हटाएँ:
sudo chown admin project/readme.txt
सिर्फ group बदलने के लिए owner खाली रखें:
sudo chown :developers project/readme.txt
केवल group ownership बदलनी हो तो chgrp guide अक्सर अधिक स्पष्ट है।
Recursive ownership को अलग निर्णय मानें
-R starting directory और उसके नीचे सब कुछ बदलता है:
sudo chown -R admin:developers project
Enter दबाने से पहले pwd और ls -ld project से शुरुआत की जगह जाँचें। Unresolved variables, wildcards और untrusted message से copied paths से बचें। /, पूरे home directory या production mount पर प्रयोग न करें।
बाद में directory और representative files दोनों verify करें:
ls -ld project
ls -l project/readme.txt
एक tree में अलग service accounts की files जानबूझकर हो सकती हैं। सबको एक owner देने से command सफल होने पर भी deployments, databases या shared directories टूट सकती हैं।
Ownership और permissions अलग हैं। chown बताता है कि permission bits किस user/group पर लागू हैं; chmod bits बदलता है। Owner सही होने पर access denied मिले तो mode जाँचें।
Symlinks, network mounts, containers और managed filesystems परिणाम बदल सकते हैं। Recursive change से पहले local man chown पढ़ें। Numeric modes के लिए chmod numbers guide देखें; पूरा syntax GNU Coreutils chown reference में है।
संदर्भ
ये दस्तावेज़ लिंक इस लेख में उपयोग किए गए कमांड के लिए आधिकारिक विवरण प्रदान करते हैं।
अगला
Numeric chmod permissions समझें, files और directories के लिए सही mode चुनें, परिणाम जाँचें और unsafe recursive changes से बचें।