- सिर्फ Terminal से sleep, clipboard, Finder, Spotlight और updates जैसे macOS-विशेष features को संभाला जा सकता है, जिससे GUI में दोहराए जाने वाले काम कम हो सकते हैं
caffeinate,pmset,taskpolicysleep रोकने, power status जांचने और process execution priority adjust करने जैसे system behavior पर सीधे असर डालते हैंpbcopy,pbpaste,open,screencapture,sayइस्तेमाल करने से clipboard, files खोलना, screenshots और voice output जैसे रोज़मर्रा के काम scripts में डालना आसान होता हैsips,textutil,mdfind,mdlsimage/document conversion, Spotlight-based search और metadata check को automate करने वाले file processing tools के रूप में उपयोगी हैंnetworkQuality,networksetup,softwareupdate,system_profilernetwork quality, Wi‑Fi/DNS, OS updates और hardware/software जानकारी को जल्दी जांचने में मदद करते हैं
macOS-विशेष commands का दायरा
- macOS standard Unix tools के अलावा operating system features तक पहुंच देने वाले विशेष command-line tools भी शामिल करता है
- हर command का detailed usage
man <command>से देखा जा सकता है - reference environment macOS Sonoma है
Power, sleep और process control
-
caffeinate- Mac को sleep में जाने से रोकनाcaffeinateको flags या arguments के बिना चलाने पर command चलने के दौरान Mac sleep state में नहीं जाएगाcaffeinate -u -t <seconds>specified seconds तक sleep prevention लागू करता है-dflag जोड़ने पर display sleep भी रोका जाता है-w <pid>से existing process specify करने पर उस process के खत्म होते हीcaffeinateभी खत्म हो जाता हैcaffeinate <command>दिए गए command को नए process के रूप में शुरू करता है और उस process के खत्म होने तक sleep रोकता है
-
pmset- power management status check और controlpmset -gउपलब्ध power settings information print करता हैpmset -g assertionsदूसरे processes द्वारा बनाए गए power-related assertions दिखाता है, जिससे Mac को sleep होने से रोक रहे process को ढूंढना उपयोगी होता हैpmset -g thermlogthrottled processes की जानकारी दिखाता है, जिसे benchmarks चलाते समय reference के तौर पर इस्तेमाल किया जा सकता हैpmset displaysleepnowपूरे system को sleep में डाले बिना सिर्फ display को तुरंत sleep state में बदलता हैpmset sleepnowपूरे system को तुरंत sleep state में बदलता है
-
taskpolicy- process scheduling controltaskpolicy -b <command>दिए गए command को background में चलाता है, और Apple silicon Mac पर यह केवल efficiency cores पर चलता हैtaskpolicy -b -p <pid>existing process को background execution में lower करता हैtaskpolicy -B -p <pid>specified process की background execution state हटाता है- Apple silicon Mac पर इसके बाद यह efficiency cores या performance cores पर चल सकता है
- यह behavior केवल background में lower किए गए processes पर लागू होता है; जो processes शुरुआत से ही background में शुरू किए गए हों, उन पर लागू नहीं होता
taskpolicy -s <command>दिए गए command को suspended state में शुरू करता है, ताकि execution शुरू होने के समय debugger attach किया जा सके
Clipboard, apps launch, screenshots और voice output
-
pbcopy,pbpaste- system clipboard का उपयोग<command> | pbcopycommand output को clipboard में copy करता हैpbpasteclipboard content को standard output में भेजता है
-
open- files और applications खोलनाopen -a <app> <file>specified file को किसी specific application में खोलता है-gflag जोड़ने पर current application का focus बनाए रखते हुए file को background में खोलता हैopen .current directory को नए Finder window में खोलता हैopen -R <file>specified file को नए Finder window में दिखाता है
-
screencapture- screenshot लेनाscreencapture -cscreenshot लेकर उसे clipboard में copy करता हैscreencapture <file>screenshot को specified file में save करता है-T <seconds>flag जोड़ने पर specified seconds तक इंतज़ार करने के बाद capture करता है
-
say- text-to-speech conversionsay <message>दिए गए message को voice में output करता हैsay -f input.txt -o output.aiffspecified text file से audiobook बनाता है
Images, documents, search और metadata
-
sips- image manipulationsips -z <height> <width> <image>existing aspect ratio को ignore करके image को specified size में resize करता हैsips -Z <size> <image>aspect ratio बनाए रखते हुए longest side को specified size में fit करता हैsips -c <height> <width> <image>original image के center के आधार पर specified size में crop करता हैsips -r <degrees> <image>image को specified angle तक rotate करता है- default behavior input image को destructively overwrite करता है, इसलिए अगर अलग output path चाहिए तो
-oflag इस्तेमाल करें - output file में input image जैसा ही file extension होना चाहिए
-
textutil- document files conversiontextutilMicrosoft Word, plain text, rich text और HTML formats के बीच files convert कर सकता हैtextutil -convert html journal.docjournal.docकोjournal.htmlमें convert करता है-convertके लिए usable valuestxt,html,rtf,rtfd,doc,docxहैं
-
mdfind,mdls- Spotlight search और metadatamdfind <query>दिए गए query से Spotlight keyword search करता हैmdfind kMDItemAppStoreHasReceipt=1Mac App Store से installed सभी apps खोजता हैmdfind -name <name>specified name से match करने वाली सभी files search करता है-onlyin <dir>flag से search scope को किसी specific directory तक सीमित किया जा सकता हैmdls <file-path>specified file से जुड़े सभी Spotlight metadata print करता है
Network, updates और system information
-
networkQuality- internet speed measurementnetworkQualityMac पर internet speed test चलाता है-vflag जोड़ने पर अधिक detailed information दिखती है-Iflag किसी specific network interface पर test चलाता है
-
networksetup- network settings check और configurationnetworksetup -listnetworkserviceorderउपलब्ध network services की list print करता हैnetworksetup -getinfo <networkservice>specified network service की जानकारी दिखाता हैnetworksetup -getdnsservers <networkservice>specified network service के DNS servers print करता हैnetworksetup -setairportnetwork <device> <network> [password]specified Wi‑Fi network से connect करता है- ज्यादातर मामलों में
<device>argument"en0"होता है
-
softwareupdate- OS updates managementsoftwareupdate --listउपलब्ध software updates print करता हैsudo softwareupdate -iaउपलब्ध सभी updates install करता हैsoftwareupdate --fetch-full-installer --full-installer-version <version>specified macOS version के full installer को/Applicationsमें download करने की कोशिश करता है
-
system_profiler- system information querysystem_profilerdefault रूप से उपलब्ध सभी system information print करता है, और output आम तौर पर काफी बड़ा होता हैsystem_profiler <datatype>केवल specified subsystem information print करता हैsystem_profiler -listDataTypesउन सभी subsystems की list दिखाता है जिनकी information ली जा सकती है- useful data types ये हैं
system_profiler SPHardwareDataType: current Mac का hardware overview, model name और serial number print करता हैsystem_profiler SPSoftwareDataType: current Mac का software overview और exact macOS version number print करता हैsystem_profiler SPPowerDataType: current AC power amount और battery cycle count सहित power/battery information print करता हैsystem_profiler SPDeveloperToolsDataType: current active Xcode developer tools और SDK versions print करता है
5 टिप्पणियां
ज़िंदगी में काम आने वाले MacBook के उन्नत टर्मिनल कमांड्स (आम यूज़र्स के लिए)
https://www.youtube.com/watch?v=EhiqpFtmjig
macOS के उन्नत CLI कमांड्स
मैंने इसी तरह की एक पोस्ट 7 महीने पहले संक्षेप में डाल दी थी, लेकिन यह वाला सारांश ज़्यादा देखने लायक है.. हाय
जितना आपने संक्षेप में बताया है, उतना भी समझने में कोई दिक्कत नहीं होती, इसलिए यह और भी अच्छा लगता है, हा
ऐसा नहीं है......हाहा
Hacker News टिप्पणियां
sips और iconutil को साथ इस्तेमाल करके, किसी third-party tool के बिना, एक 1024×1024 PNG से ऐप के लिए
.icnsफ़ाइल बनाई जा सकती हैmkdir MyIcon.iconsetसे iconset बनाएं,sips -zसे 16/32/128/256/512 आकार और@2xफ़ाइलें बनाएं, फिरiconutil -c icns MyIcon.iconsetचलाएंबोनस के तौर पर
ffmpeg -i MyIcon.iconset/icon_256x256.png icon.icoसे.icoभी बनाया जा सकता हैहालांकि
sipsPNG को छोटा जिस तरह करता है, उसे देखते हुए यह सवाल है कि 16px version सीधे 1024px से बनाना बेहतर है या 32px से चरणबद्ध तरीके से घटानाcpकी जगह पहले qlmanage का इस्तेमाल करके 1024×1024 PNG बना सकते हैंqlmanage -t -s 1024x1024 -o MyIcon.iconset/Icon1024.png icon.svgहालांकि macOS system icons को देखकर लगता है कि आजकल उन्हें अब हाथ से adjust नहीं किया जाता
सूची में pbcopy और pbpaste खास तौर पर पसंद हैं
compressed JSON से काम करते समय iTerm में जाकर
pbpaste | json_pp | pbcopyचलाएं, तो formatted output clipboard में आ जाता है और यह बहुत सुविधाजनक हैpbpaste | something | pbcopypattern अक्सर इस्तेमाल होता है, इसलिए इसे shell function बनाकर रखना ठीक हैइसे
pbfilter json_pp,pbfilter base64 -d,pbfilter sed 's/this/that/'जैसे इस्तेमाल किया जा सकता हैबिना arguments के सिर्फ
pbfilterचलाने पर यह clipboard की formatting हटाकर केवल plain text छोड़ने वाले filter की तरह भी काम करता हैलेकिन aliases, pipelines और जटिल expressions के साथ यह नहीं चलता; filter command कोई सामान्य command या function और उसके arguments होने चाहिए
उदाहरण के लिए, Windows-style copy/paste से आने वाली double blank lines को
alias winlines="sed '/^$/{$!{N;s/\n//;};}'"औरalias pbw="pbpaste | winlines | pbcopy"से साफ़ किया जा सकता हैLinux पर भी
alias pbcopy='xsel --clipboard --input',alias pbpaste='xsel --clipboard --output'से macOS जैसा व्यवहार imitate किया जा सकता हैX11 में
xclip[0], Wayland मेंwl-clipboard[1] है, और ये header parsing या explicit MIME type setting के जरिए binary file formats को भी support करते हैंइसलिए terminal से image copy करके browser या chat client जैसे GUI program में paste करना, या उल्टा वहां से लाना संभव है, और desktop automation shell scripts में भी उपयोगी है
macOS में
osascriptसे AppleScript call करकेset the clipboard to...इस्तेमाल करने वाला workaround चाहिए[0] https://github.com/astrand/xclip
[1] https://github.com/bugaevc/wl-clipboard
फ़ोन पर text copy करें, तो Mac command line में सीधे
pbpasteसे उसे ला सकते हैंpbpaste | vipe | pbcopyइस्तेमाल करता हूंयहां vipe एक utility है जो pipe के बीच में editor, आम तौर पर vim, लगा देती है और इसे https://joeyh.name/code/moreutils/ पर देखा जा सकता है
command-line tool तो नहीं, लेकिन Network Link Conditioner भी वाकई अच्छा है
latency, bandwidth, packet loss वगैरह डालकर बहुत खराब network simulate किया जा सकता है, इसलिए testing में उपयोगी है
उन meetings में भी जहां camera चालू रखना ज़रूरी बताया जाता है, connection को जानबूझकर खराब करके blocky video और robot जैसी आवाज़ दिखा सकते हैं, और जब सब video off करने को कहें तो “जादू की तरह” उसे normal कर सकते हैं
https://developer.apple.com/download/all/
https://tldp.org/HOWTO/Traffic-Control-HOWTO/components.html
profile के मुताबिक packet delay inject करने या packets का एक तय प्रतिशत drop करने के rules set करता है
macOS में
dnctlऔरpfctlइस्तेमाल करके similar काम, बल्कि उससे भी ज्यादा काम, किए जा सकते हैंऑडियो प्लेबैक के लिए afplay का ज़िक्र भी ज़रूर होना चाहिए
इससे एक सरल command-line MP3 player बनाया जा सकता है
voice synthesis के लिए
sayutility भी है, जो TUNE format को support करती है, जिससे बोलने की पूरी melody और timing adjust की जा सकती है और उसे भावनात्मक जैसा सुनाया जा सकता हैApple की Speech Synthesis Programming Guide https://josh8.com/blog/img/speech-synthesis.pdf पर है, और संबंधित लेख https://josh8.com/blog/commandline-audio-mac.html परまとめा गया है
इसे support करने वाली voice synthesis की आखिरी पीढ़ी 2007 में शामिल Alex voice थी, और इसे फिर देखने की संभावना बहुत कम लगती है
synthesis को बारीकी से control करने और naturalness के बीच मूल रूप से तनाव रहता है, और बाद वाला कहीं ज़्यादा मूल्यवान है
say -v '?'हैproductivity बढ़ानी हो या presentation देना हो, तो desktop के सभी icons और folders छिपा देता हूँ
defaults write com.apple.finder CreateDesktop 0के बादkillall Finderचलाने पर वे छिप जाते हैं, और value को1करने पर फिर दिखने लगते हैंइसे toggle करने के लिए एक bash alias भी बनाया है, और gist https://gist.github.com/berndverst/6f58c0d6aedddb6c06c23e57d... पर है
फिर भी
~/Desktopमैं अक्सर इस्तेमाल करता हूँ, इसलिए Dock में रखे दो folders में से एक है; दूसरा~/Downloadsहैदूसरी ओर macOS desktop में Stacks का आना शानदार था, और जिन लोगों का desktop files से अस्त-व्यस्त होता है, उन्हें मैं हमेशा यह feature दिखाता हूँ
presentation के समय काम आने वाली दूसरी settings के साथ इसे bundle करना अच्छा रहेगा
अच्छी list है, और hidutil भी है
https://developer.apple.com/library/archive/technotes/tn2450...
उदाहरण के लिए, PC keyboard पर macOS में लगभग बेकार
Inskey कोPC Executeजैसी key में बदलकर Keyboard Maestro में पकड़कर फिर remap किया जा सकता हैhidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'से European keyboard की ऊपर-बाईंparagraphkey को ज़्यादा उपयोगी backtick में बदला जा सकता हैhttps://hidutil-generator.netlify.app/
उदाहरण के लिए
hdiutil detach /Volumes/some-usb-driveसे USB drive अलग कर सकते हैं, याhdiutil makehybrid -joliet -o foo.iso ./srcfolder/से ISO बना सकते हैंकुछ साल पहले बड़े data chunk में कुछ खोजने और पूरा होने पर notify करने वाली script बनाते समय मैंने अंत में say command डाल दिया था
उसे भूलकर सो गया, और कुछ घंटों बाद home office से “घुसपैठिए” के अपने साथी से बात करने जैसी आवाज़ सुनकर झटके से जाग गया; क्या हुआ है यह समझने के बाद ही काफी राहत मिली
pushनाम की छोटी bash script बनाई थी जो title और optional body लेती थी./longRunningCommand && push "Task Done" "Here is a body"की तरह इस्तेमाल करना आसान था, और computer के सामने होने पर completion sound बजाने वालीbeepscript के साथ भी इसे इस्तेमाल करता थाsaycommand चलाने वाला Metasploit module भी हैइसे सच में इस्तेमाल होते नहीं देखा, लेकिन कभी “customer laptop पर
saycall करने वाला msf module इस्तेमाल किया” से शुरू होने वाला Twitter thread देखने की उम्मीद जगती हैइसलिए अगर task में 5 seconds से ज़्यादा लगे, तो
afplayसे beep sound बजाने वाली fish command completion script जोड़ी हैयह “बस इतना लंबा कि भूल जाओ” वाली tasks में फिर से focus करने में मदद करती है
macOS की diskutil command-line utility भी तारीफ के काबिल है
आज disk के कुछ slices में problem थी, जिसे macOS की graphical Disk Utility ठीक नहीं कर सकी; यह पहले Asahi Linux चलाकर देखने के बाद बचा हुआ residue था
मुझे लगा
diskutilCLI से कोई तरीका होगा, और इस thread में solution मिलाhttps://apple.stackexchange.com/questions/411544/cant-reclai...
अब पूरी disk फिर से macOS में इस्तेमाल की जा सकती है
diskutilशानदार है, लेकिन Disk Utility.app का यह हाल होना दुखद हैAPFS transition के बाद इसे ठीक से maintain नहीं किया गया, और कुछ काम जो
diskutilकर देता है, GUI app उनमें पूरी तरह fail हो जाता हैinterface redesign से पहले यह एक मजबूत tool था जो fail होने पर भी कारण बता देता था; अब यह बस flash drive format करने जितना ही करने वाला बच्चों के LEGO Duplo जैसा interface बन गया है
जब command या parameter याद न हो, तो um भी देखने लायक है
https://github.com/promptops/cli
उदाहरण के लिए,
um prevent my mac from sleeping for 30mडालने पर यहcaffeinate -u -t 1800जैसा परिणाम देता हैopen एक सरल और अच्छा command है जिसे मैं हमेशा इस्तेमाल करता हूँ
alias tab='open . -a iterm',alias phpstorm='open -a "PhpStorm"',alias smerge='open -a "Sublime Merge"'की तरह बना रखा है, और हर ऐप के Open/Recents dialog से भी ज़्यादा बार इसका इस्तेमाल करता हूँopen -a ...का tab autocomplete, Apple द्वारा completion definitions अपडेट न करने की वजह से, कई सालों से बेहद धीमा लगता हैइस Stack Overflow जवाब में workaround छोड़ा है: https://stackoverflow.com/a/63097652
-nभी हैयह उसी application को कई instances में चलाने देता है, और पहले निजी तौर पर सबसे ज़्यादा इस्तेमाल की जाने वाली utility थी
आजकल इतने गंभीर design issues वाले apps कम हो गए हैं, इसलिए इसका इस्तेमाल भी कम हो गया है
/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smergeऔर/Applications/Sublime Text.app/Contents/SharedSupport/bin/sublइस्तेमाल किए जा सकते हैंhttps://github.com/davatorium/rofi
यह https://i.imgur.com/Hm9TGeV.jpg जैसा दिखता है
VS Code terminal में alias
oइस्तेमाल करने पर यह current location से खुलता है, और वहाँ से file ढूँढकर editor में खोल सकते हैंalias finder='open .'इस्तेमाल कर सकते हैं