जवाबों:
मैं फेडोरा पर हूं, और ये वॉयसपैक थोड़े अलग स्थान पर हैं:
$ ls /usr/share/festival/lib/voices/*/ -1 | grep -vE "/usr|^$"
kal_diphone
ked_diphone
nitech_us_awb_arctic_hts
nitech_us_bdl_arctic_hts
nitech_us_clb_arctic_hts
nitech_us_jmk_arctic_hts
nitech_us_rms_arctic_hts
nitech_us_slt_arctic_hts
आप इसे इस तरह से संशोधित कर सकते हैं:
$ ls /usr/share/festival/voices/*/ -1 | grep -vE "/usr|^$"
lsइस जागीर का उपयोग आम तौर पर पर आधारित है क्योंकि lsपार्स करने के लिए मुश्किल है। findकमांड का उपयोग करने के लिए बेहतर है , जैसे:
$ find /usr/share/festival/lib/voices -maxdepth 2 -mindepth 2 \
-type d -exec basename {} \;
nitech_us_awb_arctic_hts
nitech_us_bdl_arctic_hts
nitech_us_slt_arctic_hts
nitech_us_jmk_arctic_hts
nitech_us_clb_arctic_hts
nitech_us_rms_arctic_hts
ked_diphone
kal_diphone
यह कमांड उन फ़ाइलों के लिए पूर्ण पथों की सूची तैयार करके काम करता है जो इस निर्देशिका के संबंध में 2 स्तरों के गहरे हैं:
/usr/share/festival/lib/voices
यह सूची इस प्रकार है:
$ find /usr/share/festival/lib/voices -maxdepth 2 -mindepth 2
/usr/share/festival/lib/voices/us/nitech_us_awb_arctic_hts
/usr/share/festival/lib/voices/us/nitech_us_bdl_arctic_hts
/usr/share/festival/lib/voices/us/nitech_us_slt_arctic_hts
/usr/share/festival/lib/voices/us/nitech_us_jmk_arctic_hts
/usr/share/festival/lib/voices/us/nitech_us_clb_arctic_hts
/usr/share/festival/lib/voices/us/nitech_us_rms_arctic_hts
/usr/share/festival/lib/voices/english/ked_diphone
/usr/share/festival/lib/voices/english/kal_diphon
लेकिन हम इन निर्देशिकाओं का अंतिम भाग चाहते हैं, पत्ती नोड। तो हम basenameइसे बाहर पार्स करने के लिए उपयोग कर सकते हैं :
$ basename /usr/share/festival/lib/voices/us/nitech_us_awb_arctic_hts
nitech_us_awb_arctic_hts
यह सब एक साथ रखते हुए, हम findकमांड को कमांड में प्रत्येक 2 स्तर की गहरी निर्देशिका पास कर सकते हैं basename। यह नोटेशन basename {}इन बेसन रूपांतरणों को क्या कर रहा है। इसे -execस्विच के माध्यम से कॉल करें।
-exec basename {}होता है, क्या आप यहाँ बता सकते हैं?
find ~/ -maxdepth 1 -mindepth 1 -type d | xargs du -csh | sort -h सबसे बड़ी निर्देशिकाओं को आकार में हल करता है
सबसे आसान है
ls -d /usr/share/festival/voices/*/*
यह शेल द्वारा सभी उप निर्देशिकाओं में /usr/share/festival/voices/और फिर उन उप निर्देशिकाओं में से प्रत्येक की सामग्री तक विस्तारित है ।
यदि आप केवल एक विशिष्ट स्तर तक उतरना चाहते हैं जैसा कि आपके शीर्षक से पता चलता है, कुछ कार्यान्वयन findजैसे कि GNU और कुछ BSD का:
find /usr/share/festival/voices/ -mindepth 2 -maxdepth 3 -type d
यह सभी निर्देशिकाओं ( -type d) को ढूंढेगा, जो उपनिर्देशिका में हैं /usr/share/festival/voices/, mindepth 2लेकिन 3 स्तर नीचे ( maxdepth 3) से अधिक गहरे नहीं हैं । से man find:
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc‐
tories below the command line arguments. -maxdepth 0
means only apply the tests and actions to the command line
arguments.
-mindepth levels
Do not apply any tests or actions at levels less than levels (a
non-negative integer). -mindepth 1 means process all files
except the command line arguments.
-type fलिए -type dइसे बदलना चाहिए, है ना? इसके उद्देश्य के बारे में -exec basename {}
-type dडायरेक्टरी मिलेगी। यह basenameएक बहुत अच्छा विचार है, यह केवल नाम छपेगा और रास्ता निकालेगा। आप केवल नाम चाहते हैं, यह मानते हुए कि आपको क्या करना चाहिए। एक नजर man basenameऔर भी है man dirname।
स्वीकार किए जाते हैं जवाब सही ढंग से काम करता है लेकिन कुछ हद तक अक्षम है, क्योंकि यह एक नई spawns basenameप्रत्येक उपनिर्देशिका के लिए प्रक्रिया:
find /usr/share/festival/lib/voices -maxdepth 2 -mindepth 2 \
-type d -exec basename {} \;
जब संभव हो, findस्पॉनिंग प्रक्रियाओं के खर्च से बचने के लिए इसमें निर्मित सुविधाओं का उपयोग करना बेहतर होता है। कार्रवाई findका उपयोग करके अपने मुद्रित आउटपुट को संशोधित करने की काफी व्यापक क्षमता है -printf। डिफ़ॉल्ट -print
क्रिया संपूर्ण पथ को प्रिंट करती है, लेकिन -printfमुद्रण के लिए पथ के कुछ भागों का चयन करना और प्रारूप स्ट्रिंग का उपयोग करना संभव है। अग्रणी निर्देशिकाओं (जैसा कि basename
करता है) के बिना पथ का फ़ाइल नाम भाग निकालने के लिए , प्रारूप स्ट्रिंग है %f। प्रत्येक फ़ाइल नाम के बाद एक नई पंक्ति रखने के लिए, \nनिम्नानुसार शामिल करें :
$ find /usr/share/festival/lib/voices -maxdepth 2 -mindepth 2 \
-type d -printf '%f\n'
nitech_us_awb_arctic_hts
nitech_us_bdl_arctic_hts
nitech_us_slt_arctic_hts
nitech_us_jmk_arctic_hts
nitech_us_clb_arctic_hts
nitech_us_rms_arctic_hts
ked_diphone
kal_diphone
findमनमाने बाहरी आदेशों के साथ उपयोग करने के अधिक सामान्य पैटर्न को शामिल किया गया है ; यह केवल उन ऑपरेशनों के लिए कम कुशल है जो इसमें निर्मित हैं find। मैंने उनके उत्तर में एक टिप्पणी जोड़ने पर विचार किया था, लेकिन मुझे इससे अधिक प्रतिष्ठा की आवश्यकता है। अपने स्वीकृत उत्तर को बदलने की कोई आवश्यकता नहीं है, क्योंकि वर्तमान में स्वीकृत उत्तर सही है, अच्छी तरह से समझाया गया है, और अधिक सामान्य मामले के लिए एक पैटर्न के रूप में प्रयोग करने योग्य है; मैं सिर्फ यह बताना चाहता था कि इस विशिष्ट मामले के लिए एक अधिक कुशल तरीका है।
TLDR; इस सवाल के शीर्षक के आधार पर यहां आने वालों के लिए ; "सूची उपनिर्देशिका केवल n स्तर गहरी": का उपयोग करें
find -maxdepth N
जहां Nकिसी भी संख्या है।