TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

macOS command-line tools you might not know about

2039 点作者 Gadiguibou将近 2 年前

93 条评论

strogonoff将近 2 年前
You can use sips together with iconutil to generate a complete .icns file for your app from a single 1024 by 1024 PNG without any third party software:<p><pre><code> mkdir MyIcon.iconset cp Icon1024.png MyIcon.iconset&#x2F;icon_512x512@2x.png sips -z 16 16 Icon1024.png --out MyIcon.iconset&#x2F;icon_16x16.png sips -z 32 32 Icon1024.png --out MyIcon.iconset&#x2F;icon_16x16@2x.png sips -z 32 32 Icon1024.png --out MyIcon.iconset&#x2F;icon_32x32.png sips -z 64 64 Icon1024.png --out MyIcon.iconset&#x2F;icon_32x32@2x.png sips -z 128 128 Icon1024.png --out MyIcon.iconset&#x2F;icon_128x128.png sips -z 256 256 Icon1024.png --out MyIcon.iconset&#x2F;icon_128x128@2x.png sips -z 256 256 Icon1024.png --out MyIcon.iconset&#x2F;icon_256x256.png sips -z 512 512 Icon1024.png --out MyIcon.iconset&#x2F;icon_256x256@2x.png sips -z 512 512 Icon1024.png --out MyIcon.iconset&#x2F;icon_512x512.png iconutil -c icns MyIcon.iconset </code></pre> As a bonus, generate .ico with ffmpeg:<p><pre><code> ffmpeg -i MyIcon.iconset&#x2F;icon_256x256.png icon.ico </code></pre> Incidentally, does anyone know enough about the way sips scales PNGs to confirm that it makes sense to create the 16px version straight from 1024px, as opposed to basing it off 32px (and all the way up)? I.e., is it better to downscale in fewer steps (as currently) or in smaller steps?
评论 #36495648 未加载
评论 #36502128 未加载
评论 #36505339 未加载
评论 #36500938 未加载
klausa将近 2 年前
`pbcopy` and `pbpaste` are one of my most-loved in the list.<p>Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.
评论 #36497973 未加载
评论 #36492101 未加载
评论 #36492108 未加载
评论 #36494242 未加载
评论 #36497589 未加载
评论 #36497033 未加载
评论 #36497293 未加载
评论 #36493457 未加载
评论 #36492265 未加载
评论 #36492953 未加载
评论 #36492015 未加载
评论 #36492890 未加载
评论 #36492229 未加载
评论 #36494325 未加载
评论 #36493336 未加载
评论 #36494023 未加载
评论 #36492028 未加载
评论 #36498181 未加载
评论 #36493802 未加载
评论 #36492008 未加载
评论 #36498558 未加载
评论 #36493127 未加载
评论 #36493037 未加载
评论 #36495894 未加载
评论 #36495379 未加载
评论 #36496866 未加载
评论 #36498586 未加载
评论 #36535798 未加载
wkat4242将近 2 年前
Not a command-line tool but the network link conditioner is also really great. Never seen such a tool on another OS<p>You can simulate a really bad network. Latency, bandwidth, packet loss etc. Great for testing but also if people insist on cameras being on. Just screw up the connection so bad that everyone gets annoyed with your blocky image and robot voice and suggest you turn off video and then you make it &#x27;magically&#x27; ok - lol
评论 #36494202 未加载
评论 #36493099 未加载
评论 #36492924 未加载
评论 #36493644 未加载
评论 #36516500 未加载
评论 #36509042 未加载
评论 #36493800 未加载
评论 #36492828 未加载
sovietswag将近 2 年前
Needs to mention afplay for playing audio! You can easily use this to make a command-line MP3 player.<p>Others have mentioned the “say” utility for speech synthesis. There is a lot you can do with it, it supports the TUNE format, which allows you to &quot;shape the overall melody and timing of an utterance... for example ... to make an utterance sound as if it is spoken with emotion&quot;.<p>See: Apple&#x27;s Speech Synthesis Programming Guide, <a href="https:&#x2F;&#x2F;josh8.com&#x2F;blog&#x2F;img&#x2F;speech-synthesis.pdf" rel="nofollow noreferrer">https:&#x2F;&#x2F;josh8.com&#x2F;blog&#x2F;img&#x2F;speech-synthesis.pdf</a><p>I also wrote more about this here: <a href="https:&#x2F;&#x2F;josh8.com&#x2F;blog&#x2F;commandline-audio-mac.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;josh8.com&#x2F;blog&#x2F;commandline-audio-mac.html</a>
评论 #36495517 未加载
评论 #36500311 未加载
评论 #36544614 未加载
verst将近 2 年前
I like to hide all icons or folders on my Desktop when I need to be more productive or when I&#x27;m presenting. This can be done with:<p><pre><code> # hide desktop icons and folders defaults write com.apple.finder CreateDesktop 0 killall Finder # restarting Finder is required # unhide desktop icons and folders defaults write com.apple.finder CreateDesktop 1 killall Finder # restarting Finder is required </code></pre> I made myself a convenient bash alias for this which lets me simply toggle the desktop on and off Here is a gist: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;berndverst&#x2F;6f58c0d6aedddb6c06c23e57dd50d198" rel="nofollow noreferrer">https:&#x2F;&#x2F;gist.github.com&#x2F;berndverst&#x2F;6f58c0d6aedddb6c06c23e57d...</a><p><pre><code> toggledesktop () { if [[ $(defaults read com.apple.finder CreateDesktop) -eq &quot;0&quot; ]] then export SHOWDESKTOP=1; echo &quot;Unhiding Desktop icons&quot; else export SHOWDESKTOP=0; echo &quot;Hiding Desktop icons&quot; fi defaults write com.apple.finder CreateDesktop $SHOWDESKTOP killall Finder }</code></pre>
评论 #36512317 未加载
评论 #36505146 未加载
BruceEel将近 2 年前
Nice list.<p>Also, hidutil (<a href="https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;technotes&#x2F;tn2450&#x2F;_index.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;technotes&#x2F;tn2450...</a>).<p>Example:<p><pre><code> hidutil property --set &#x27;{&quot;UserKeyMapping&quot;:[{&quot;HIDKeyboardModifierMappingSrc&quot;:0x700000049,&quot;HIDKeyboardModifierMappingDst&quot;:0x700000065}]}&#x27; </code></pre> For my PC keyboard, remaps &quot;Ins&quot; (normally useless under macOS) to something (&quot;PC Execute&quot;) I can trap and remap with Keyboard Maestro.
评论 #36492415 未加载
评论 #36493561 未加载
评论 #36492826 未加载
callumprentice将近 2 年前
Years ago, I wrote a script to find something in a big blob of data and to alert me when it was done, I added a “say &lt;some glib Rambo or Schwarzenegger&gt;” type phrase upon completion. I forgot about it and went to bed and was jolted awake hours later by what was clearly an “intruder” speaking to his accomplice, in my home office. Quite the relief when I realized what happened.
评论 #36495206 未加载
评论 #36496808 未加载
评论 #36494341 未加载
评论 #36495778 未加载
评论 #36498600 未加载
codetrotter将近 2 年前
Shoutout to the `diskutil` command line utility on macOS.<p>I had problems with some slices on a disk today, and was not able to fix it with the graphical Disk Utility that comes with macOS. These slices were remnants from experimenting with running Asahi Linux on the machine in the past.<p>I knew there had to be a way to fix it with diskutility cli program.<p>I found a thread, and the solution for what to do in such situation.<p><a href="https:&#x2F;&#x2F;apple.stackexchange.com&#x2F;questions&#x2F;411544&#x2F;cant-reclaim-empty-space-on-main-macos-partition-macos-mojave" rel="nofollow noreferrer">https:&#x2F;&#x2F;apple.stackexchange.com&#x2F;questions&#x2F;411544&#x2F;cant-reclai...</a><p>Now the disk can be fully utilised by macOS again.
评论 #36494810 未加载
silly_squidward将近 2 年前
You should check out &quot;um&quot; <a href="https:&#x2F;&#x2F;github.com&#x2F;promptops&#x2F;cli">https:&#x2F;&#x2F;github.com&#x2F;promptops&#x2F;cli</a> for when you can&#x27;t remember the command&#x2F;parameters.<p>~ um prevent my mac from sleeping for 30m<p><pre><code> caffeinate -u -t 1800 don&#x27;t see what you&#x27;re looking for? try providing more context</code></pre>
评论 #36510406 未加载
apocalyptic0n3将近 2 年前
`open` is one I use all the time. I love that simple command.<p><pre><code> alias tab=&#x27;open . -a iterm&#x27; alias phpstorm=&#x27;open -a &quot;PhpStorm&quot;&#x27; alias smerge=&#x27;open -a &quot;Sublime Merge&quot;&#x27; </code></pre> etc. I use those more than I do the Open&#x2F;Recents dialogs in the respective apps.
评论 #36504000 未加载
评论 #36498873 未加载
评论 #36499746 未加载
评论 #36499022 未加载
评论 #36498084 未加载
评论 #36499642 未加载
donatj将近 2 年前
When mentioning `open` they should have noted that `open &lt;file&gt;` will open the given file with its associated app.<p>It’s indispensable.
评论 #36493992 未加载
评论 #36492946 未加载
评论 #36494291 未加载
semanticist将近 2 年前
<p><pre><code> &#x2F;System&#x2F;Library&#x2F;PrivateFrameworks&#x2F;Apple80211.framework&#x2F;Versions&#x2F;A&#x2F;Resources&#x2F;airport </code></pre> I set an alias in my shell so this is just &#x27;airport&#x27;, lets you interact with the wifi settings - I particularly like &#x27;airport -s&#x27; for doing a scan of the local wifi networks, since it shows signal strength and channel information right there, which is helpful when troubleshooting.
评论 #36493859 未加载
rogual将近 2 年前
A fun one I use surprisingly often is<p><pre><code> open -h AppKit.h </code></pre> to open any system header file (or I guess any header in the standard include path? It finds stuff from Homebrew too.)
mechanicker将近 2 年前
Use ‘ditto’ for copying directories. It is fast!<p><a href="https:&#x2F;&#x2F;osxdaily.com&#x2F;2014&#x2F;06&#x2F;11&#x2F;use-ditto-copy-files-directories-mac-command-line&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;osxdaily.com&#x2F;2014&#x2F;06&#x2F;11&#x2F;use-ditto-copy-files-directo...</a>
评论 #36493264 未加载
nomilk将近 2 年前
Surprised pngpaste isn&#x27;t mentioned (in the article nor the comments).<p>If you take a screen shot (command + shift + 4) or partial screen shot (command + shift + control + 4) you can save it directly to an image file with:<p>pngpaste filename.png
评论 #36493527 未加载
评论 #36497429 未加载
评论 #36493211 未加载
评论 #36493174 未加载
karmakaze将近 2 年前
Another good one is &#x27;hidutil&#x27; which can remap any keys without additional software. It&#x27;s handy for things like remapping CapsLock to anything, etc. For actual full keyboard layouts though I&#x27;d use Ukelele[0].<p>[0] <a href="https:&#x2F;&#x2F;software.sil.org&#x2F;ukelele" rel="nofollow noreferrer">https:&#x2F;&#x2F;software.sil.org&#x2F;ukelele</a>
评论 #36493963 未加载
riobard将近 2 年前
For audio there&#x27;re also `afinfo` to probe metadata and `afconvert` to convert between different codec&#x2F;container formats. I use them for podcast post-processing and archiving workflow.<p>macOS 13 Ventura ships with a customized `iperf3` called `iperf3-darwin` adding features like QUIC&#x2F;L4S&#x2F;MPTCP.
评论 #36494052 未加载
massysett将近 2 年前
Is there a place Apple documents these things? Do people find these things with something like “ls &#x2F;usr&#x2F;bin” and wondering “what is this?” or does Apple have an administrator’s guide somewhere? Or has someone written a good book with this stuff?
评论 #36498205 未加载
评论 #36500063 未加载
gemstones将近 2 年前
qlmanage is super useful for converting SVG to PNG easily, too! I use it like this:<p>qlmanage -t -s 1000x1000 -o ~&#x2F;Pictures&#x2F;foo.png ~&#x2F;Pictures&#x2F;foo.svg<p>To turn an square SVG into a PNG without installing anything extra or using an online image tool
reaperducer将近 2 年前
One I use a lot: mdls.<p>It&#x27;s ls for metadata. Very helpful for getting quick and scripted access to the date&#x2F;time when and the latitude&#x2F;longitude where a photograph was taken.<p>Also, the say command is a lot more versatile than it seems.<p>Combined with the ability to save the speech to an audio file, my wife uses it as the disc jockey for her little hobby AM radio station. It introduces the song and does little station IDs and such.<p>You can customize it with dozens of dozens of voices, some in very high quality.<p>When a song from her Japanese playlists comes on, it switches to one of the Japanese voices. I don&#x27;t speak Japanese, so I don&#x27;t know if it actually translates the DJ words into Japanese, but it sounds pretty close to my untrained ears.
daneel_w将近 2 年前
afconvert(1) lets you convert between various audio formats - most noteworthy is that it gives you access to Core Audio&#x27;s superior AAC encoder without having to use iTunes&#x2F;Music:<p><pre><code> afconvert music.wav -o music_160kbps_aac.m4a -b 160000 -q 127 -s 2 -f m4af -d &#x27;aac &#x27; </code></pre> lipo(1) lets you operate (replace&#x2F;extract&#x2F;thin&#x2F;etc) on executables and libraries to tailor their supported architectures:<p><pre><code> lipo &lt;universal exe&#x2F;dylib&gt; -thin arm64e -output &lt;new apple silicon-only exe&#x2F;dylib&gt;</code></pre>
评论 #36497032 未加载
kevwil将近 2 年前
The `security` tool is handy too. I like the ability to store passwords in the `login` Keychain and automate using them in the terminal using `security find-generic-password`.<p><pre><code> security find-generic-password -gw -l &quot;${keychain_id}&quot; </code></pre> Super helpful for VPN automation scripts, easy logins to things like Vault, etc. The security tool has tons of other handy functions as well.
pseufaux将近 2 年前
Not a bad list of basic macOS specific cli tools. For a more in depth list, I usually reference <a href="https:&#x2F;&#x2F;ss64.com&#x2F;osx&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;ss64.com&#x2F;osx&#x2F;</a>.
评论 #36493703 未加载
lapcat将近 2 年前
Manage the Launch Services database:<p><pre><code> &#x2F;System&#x2F;Library&#x2F;Frameworks&#x2F;CoreServices.framework&#x2F;Versions&#x2F;A&#x2F;Frameworks&#x2F;LaunchServices.framework&#x2F;Versions&#x2F;A&#x2F;Support&#x2F;lsregister </code></pre> Manage file extended attributes (such as quarantine):<p><pre><code> xattr </code></pre> Execute a script (AppleScript or JavaScript):<p><pre><code> osascript -e &lt;statement&gt;</code></pre>
评论 #36492800 未加载
评论 #36492545 未加载
boffinAudio将近 2 年前
Wut? No fs_usage? Easily one of the most useful of them all ..<p><a href="https:&#x2F;&#x2F;www.manpagez.com&#x2F;man&#x2F;1&#x2F;fs_usage&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.manpagez.com&#x2F;man&#x2F;1&#x2F;fs_usage&#x2F;</a><p>I can&#x27;t count the number of times a bit of fs_usage foo has helped me dig out of a seriously messy pile of network, file and page fault issues ..
评论 #36492437 未加载
js2将近 2 年前
Some that were missed:<p>diskutil: modify, verify and repair local disk<p>hdiutil: manipulate disk images (attach, verify, create, etc)<p>dscl: Directory Service command line utility (manage users and groups)<p>scutil: Manage system configuration parameters (useful for checking current DNS configuration and checking reachability to a host).<p>sysadminctl: It&#x27;s a secret! No man page. Run without options to get a usage message, but even the usage is apparently incomplete. It&#x27;s a grab-bag of functionality. I use for adding&#x2F;removing a temporary build user as part of a CI&#x2F;CD setup.
bpye将近 2 年前
Caffeinate is definitely the one I miss most on Windows. Super handy to keep your machine awake whilst some task is ongoing.
评论 #36494110 未加载
评论 #36495457 未加载
评论 #36493929 未加载
评论 #36498697 未加载
评论 #36494150 未加载
atarv将近 2 年前
If you need a more featureful alternative to textutils, look for pandoc <a href="https:&#x2F;&#x2F;github.com&#x2F;jgm&#x2F;pandoc">https:&#x2F;&#x2F;github.com&#x2F;jgm&#x2F;pandoc</a>
评论 #36498203 未加载
bhal将近 2 年前
Great list, working with Mac a long time and found some good things here. This might be useful too:<p># cd to frontmost open finder folder (in Terminal cd to the current top finder window) cdf() { cd &quot;`osascript -e &#x27;tell app &quot;Finder&quot; to POSIX path of (insertion location as alias)&#x27;`&quot;; pwd; }<p># Copy the frontmost open finder folder Path from Terminal to the Clipboard in MacOS: cpf() { echo &quot;`osascript -e &#x27;tell app &quot;Finder&quot; to POSIX path of (insertion location as alias)&#x27;`&quot;|pbcopy; }<p># open manpage in preview app: pman() { mandoc -T pdf &quot;$(&#x2F;usr&#x2F;bin&#x2F;man -w $@)&quot; | open -fa Preview; }<p># Function to delete a given line in ssh known_hosts file: xho() { line=$1;tFile=&quot;$HOME&#x2F;.ssh&#x2F;known_hosts&quot;;sed -e &quot;${line}d&quot; -i &quot;.tmp&quot; &quot;$tFile&quot;;}
rockbruno将近 2 年前
Xcode uses `mdfind` to provide symbols in crash reports and for Instruments, and is the reason why it seems to have a life of its own and work only when it wants to. Spotlight indexing is extremely flaky for reasons I&#x27;m not aware of.
hgurmen将近 2 年前
It was nice to find out that macOS has a tool similar to Valgrind called `leaks` that helps you find memory leaks!
dcow将近 2 年前
I’m surprised TFA doesn’t mention `plutil` and its counterpart `PlistBuddy`. They’re like the `jq` of macOS.<p><a href="https:&#x2F;&#x2F;scriptingosx.com&#x2F;2016&#x2F;11&#x2F;editing-property-lists&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;scriptingosx.com&#x2F;2016&#x2F;11&#x2F;editing-property-lists&#x2F;</a>
RandallBrown将近 2 年前
The say command has one of my favorite pieces of that famous Apple polish.<p>If you type `say os x`, it&#x27;ll actually speak &quot;oh es ten&quot;.
评论 #36496000 未加载
gregoriol将近 2 年前
`tmutil` could be added to this list, it&#x27;s a management cli for Time Machine
评论 #36493010 未加载
Etheryte将近 2 年前
Neat, I was not aware of `networkQuality`. A good replacement for opening up Speedtest or whatnot when you just want to figure out if the network is slow or something else is up.
评论 #36497209 未加载
评论 #36499583 未加载
评论 #36492595 未加载
renewiltord将近 2 年前
I use:<p>``` #!&#x2F;usr&#x2F;bin&#x2F;env bash<p><pre><code> set -u title=${2:-Shell} msg=$1 osascript -e &quot;display notification \&quot;$1\&quot; with title \&quot;$title\&quot;&quot;</code></pre> ```<p>As `~&#x2F;bin&#x2F;,notify` and put it at the end of long-running commands:<p>``` run_this_program &amp;&amp; ,notify &quot;Long program is done!&quot; ```
评论 #36494572 未加载
评论 #36507036 未加载
kart23将近 2 年前
CUPS tools are also awesome.<p><a href="https:&#x2F;&#x2F;opensource.apple.com&#x2F;source&#x2F;cups&#x2F;cups-450&#x2F;cups&#x2F;doc&#x2F;help&#x2F;options.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;opensource.apple.com&#x2F;source&#x2F;cups&#x2F;cups-450&#x2F;cups&#x2F;doc&#x2F;h...</a>
lastangryman将近 2 年前
I find it extremely upsetting that `networkQuality` is the only command that is not entirely lowercase. How did this get through PR??
评论 #36498941 未加载
jakehilborn将近 2 年前
Self-plug of displayplacer[0] for changing screen resolutions&#x2F;rotations&#x2F;etc via the command line.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;jakehilborn&#x2F;displayplacer">https:&#x2F;&#x2F;github.com&#x2F;jakehilborn&#x2F;displayplacer</a>
评论 #36495268 未加载
评论 #36493672 未加载
评论 #36492956 未加载
joshSzep将近 2 年前
`caffeinate` is a game changer. Now I can keep my Slack status green without sitting in an empty zoom room. #WFHLife ;)
评论 #36497716 未加载
评论 #36497482 未加载
asveikau将近 2 年前
Not on the list, but I think `fs_usage` is an interesting one. Like a firehose of disk activity.
whalesalad将近 2 年前
`pbcopy | jq | pbpaste` is a very frequent command that I run to quickly format json in the clipboard.<p>I use pbcopy and pbpaste probably all day long and always miss it in Linux environments.
评论 #36493045 未加载
评论 #36492388 未加载
评论 #36496472 未加载
babbledabbler将近 2 年前
say --rate=500 &quot;Peter Piper picked a peck of pickled peppers. A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers, Where’s the peck of pickled peppers Peter Piper picked?&quot;
penjelly将近 2 年前
wait caffeinate exists natively? ive been using a third party caffeine tool for the longest time..
评论 #36493363 未加载
评论 #36494641 未加载
评论 #36493273 未加载
评论 #36494075 未加载
评论 #36497428 未加载
xenodium将近 2 年前
A couple of built-in I didn&#x27;t see:<p>macOS software versions:<p><pre><code> sw_vers </code></pre> macOS hardware overview:<p><pre><code> system_profiler SPHardwareDataType </code></pre> Convert binary plist to xml<p><pre><code> plutil -convert xml1 -o out.xml in.plist </code></pre> A couple of lesser known, but also handy ones to install:<p><pre><code> brew install dark-mode brew install duti </code></pre> &gt; screencapture - take screenshots<p>Big fan of screencapture. I wanted something similar but for capturing window videos, so I built <a href="https:&#x2F;&#x2F;github.com&#x2F;xenodium&#x2F;macosrec">https:&#x2F;&#x2F;github.com&#x2F;xenodium&#x2F;macosrec</a><p>I often wrap command line utilites with Emacs functions (don&#x27;t need to remember invocation flags&#x2F;structure but also enables batch invocations) <a href="https:&#x2F;&#x2F;xenodium.com&#x2F;recordscreenshot-windows-the-lazy-way" rel="nofollow noreferrer">https:&#x2F;&#x2F;xenodium.com&#x2F;recordscreenshot-windows-the-lazy-way</a>
fredoralive将近 2 年前
I&#x27;ll go for the somewhat obsolete `drutil eject` as Mac OS can be sometimes rather reluctant to eject cycle optical drives if it doesn&#x27;t actually think a disc in in them. Although nowadays you&#x27;ll probably be using a 3rd party tray load drive with an eject button instead of a no-button slot loading Apple one.
评论 #36500166 未加载
ExoticPearTree将近 2 年前
pbcopy&#x2F;pbpaste are a lifesaver when doing stuff on the command line that has a lot of output and piping is not something you can do.<p>networkQuality is something I really wish I knew about sooner.
评论 #36492117 未加载
simscitizen将近 2 年前
dtrace and the DTrace Toolkit scripts are also quite useful for understanding and debugging things, e.g. `opensnoop -a` to print the result of all open syscalls on the system.
elpakal将近 2 年前
`xed .` Is probably my most underrated macOS command. It will open Xcode using either your project or workspace file.
knodi123将近 2 年前
&gt; open - open files and applications<p>And urls! I use that one in a lot of my scripts. We have a ticket-based workflow, and I can parse out the ticket number from the current git branch, and open the ticket or create a merge requests without having to do anything complicated.
juujian将近 2 年前
Is ```textutil -convert``` using pandoc under the hood?
评论 #36492457 未加载
评论 #36493399 未加载
revicon将近 2 年前
I wrote this a while back to document managing WIFI connections using the command line.<p><a href="https:&#x2F;&#x2F;www.mattcrampton.com&#x2F;blog&#x2F;managing_wifi_connections_using_the_mac_osx_terminal_command_line&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.mattcrampton.com&#x2F;blog&#x2F;managing_wifi_connections_...</a><p>I use these commands a lot when I&#x27;m in a coffeeshop and I&#x27;m trying to fine-grain control which wifi connection my laptop is using and dealing with passwords.<p>IMO OSX&#x27;s UI for wifi network picking is clunky when you&#x27;re in an area with &gt;50 wifi networks in range, command line tools are much easier to deal with.
thomasahle将近 2 年前
I just tried the following: I copied all of my ~&#x2F;.bash_history into GPT and asked it for some commands that would save me time. It didn&#x27;t quite work to identify &quot;bad patterns&quot; as I had hoped, but it did suggest the following:<p>1. <i>bat</i>: A `cat` clone with syntax highlighting and Git integration.<p>2. <i>htop</i>: Interactive process viewer, a better alternative to `top`.<p>3. <i>fzf</i>: Command-line fuzzy finder to quickly search files, command history, etc.<p>4. <i>tldr</i>: Community-driven man pages with practical examples.<p>5. <i>ripgrep (rg)</i>: Extremely fast text search tool, recursively searches directories for a regex pattern.<p>6. <i>tmux</i>: Terminal multiplexer to run multiple terminal sessions within a single window.<p>7. <i>autoenv</i>: Automatically source environment variables based on the current directory.<p>8. <i>hub</i>: Extends git with extra features and commands for GitHub.<p>9. <i>ncdu</i>: Disk usage analyzer with an ncurses interface.<p>10. <i>jq</i>: Lightweight command-line JSON processor.<p>11. <i>sshfs</i>: Mount a remote filesystem using SFTP.<p>12. <i>watch</i>: Execute a program periodically, showing output fullscreen.<p>13. <i>fd</i>: Simpler and faster alternative to `find`.<p>14. <i>z</i>: Jump around directories based on frequent use.<p>15. <i>lazygit</i>: Simple terminal UI for git commands.<p>Most of them I already knew, but <i>z</i> seems like an interesting tool. The docs are here &lt;<a href="https:&#x2F;&#x2F;github.com&#x2F;rupa&#x2F;z">https:&#x2F;&#x2F;github.com&#x2F;rupa&#x2F;z</a>&gt;:<p><pre><code> z foo cd to most frecent dir matching foo z foo bar cd to most frecent dir matching foo, then bar z -r foo cd to highest ranked dir matching foo z -t foo cd to most recently accessed dir matching foo z -l foo list all dirs matching foo (by frecency) </code></pre> Might start using it, if I&#x27;m not too stuck in my habits.
评论 #36499983 未加载
评论 #36510051 未加载
pantulis将近 2 年前
powermetrics gives a lot of energy usage info per CPU core and apps.
verst将近 2 年前
A lot of macOS behavior can be toggled by modifying the system component defaults.<p>For example, turn off autohiding of the Dock from commandline:<p><pre><code> defaults write com.apple.dock &quot;autohide&quot; -bool &quot;false&quot; &amp;&amp; killall Dock </code></pre> Include the date in screenshots you take:<p><pre><code> defaults write com.apple.screencapture &quot;include-date&quot; -bool &quot;true&quot; </code></pre> Here is handy website which documents many of the defaults and their purpose: <a href="https:&#x2F;&#x2F;macos-defaults.com&#x2F;#%F0%9F%99%8B-what-s-a-defaults-command" rel="nofollow noreferrer">https:&#x2F;&#x2F;macos-defaults.com&#x2F;#%F0%9F%99%8B-what-s-a-defaults-c...</a>
评论 #36498781 未加载
bovermyer将近 2 年前
I just freaked out my cat using `say`. I&#x27;m going to enjoy this too much.
评论 #36492128 未加载
评论 #36492377 未加载
评论 #36492700 未加载
评论 #36492180 未加载
评论 #36495838 未加载
评论 #36493771 未加载
maxfurman将近 2 年前
I remember Caffeine used to be a third-party program that would prevent your Mac from sleeping, same behavior as the `caffeinate` here. Were they acquired and incorporated into the OS?
评论 #36492366 未加载
评论 #36492395 未加载
评论 #36492806 未加载
评论 #36492349 未加载
FabHK将近 2 年前
Another one that comes in handy occasionally is afconvert to convert audio files. I like to add audio files (eg audio books, or guided meditations) to iTunes&#x2F;Music or Books, and they are a little bit finicky in terms of what they accept and sync (I&#x27;ve had problems with files converted with ffmpeg).<p>I use this to convert an mp3 to a variable rate m4b for Books:<p><pre><code> afconvert -v -s 3 -f m4bf meditation1.mp3</code></pre>
brazzledazzle将近 2 年前
Probably want to check your policies if using a business-owned mac. Caffeinate probably violates your security policies if it’s a decent sized company.
评论 #36492983 未加载
评论 #36499523 未加载
评论 #36492485 未加载
alwillis将近 2 年前
My latest discovery is being able to manage Xcode simulators from the command line [1].<p>[1]: <a href="https:&#x2F;&#x2F;developer.apple.com&#x2F;documentation&#x2F;xcode&#x2F;installing-additional-simulator-runtimes#Install-and-manage-Simulator-runtimes-from-the-command-line" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.apple.com&#x2F;documentation&#x2F;xcode&#x2F;installing-a...</a>
Hamuko将近 2 年前
You can use `say` to recreate your own Serial Experiments Lain intros.<p><pre><code> say -v Whisper &quot;Weird: Layer zero one&quot;</code></pre>
评论 #36496189 未加载
apozem将近 2 年前
I love pbcopy and miss it every time I ssh into my Raspberry Pi. Should be included in every shell environment as standard.
评论 #36492666 未加载
tambourine_man将近 2 年前
In the best HN tradition, the list in the article is good, but the comments section is where the gold nuggets are.
hk1337将近 2 年前
I was aware of about half of these but textutil, networkUtility, and sips I didn’t not and look really interesting
评论 #36492413 未加载
评论 #36496208 未加载
Xen9将近 2 年前
It&#x27;s rare to see a &quot;you might not know about&quot; instead of &quot;you never thought about&quot; etc.
api将近 2 年前
Here are my favorites:<p><pre><code> alias sleepoff=&quot;sudo pmset -a disablesleep 1&quot; alias sleepon=&quot;sudo pmset -a disablesleep 0&quot; </code></pre> This fully disables sleep, period. Just make sure you don&#x27;t leave it unplugged too long, but on Apple Silicon it lasts for quite a long time.
评论 #36493491 未加载
reacharavindh将近 2 年前
Is there any easy shortcut to resizing an image by percentage or fitting to a specific size?<p>Many a times, a website says &quot;file needs to be no bigger than 2 MB&quot;, and I need to scramble with Preview app to resize teh app until it falls below that limit. A cli tool for that action would be very handy.
评论 #36492848 未加载
评论 #36493744 未加载
tngranados将近 2 年前
I didn&#x27;t know about `taskpolicy`, I&#x27;ll add it to my list. It will be handy now that it&#x27;s getting hot around here for long running commands that I don&#x27;t mind waiting for, Apple Silicon Macs run cooler than Intel&#x27;s but they can still get very hot when maxed out.
Version467将近 2 年前
Great list. Didn&#x27;t know about pbcopy&#x2F;pbpaste, very useful.<p>I use open regularly. Often to open a directory in finder and preview a file. Looks like I can just use qlmanage from now on.<p>Not sure I&#x27;d use screencapture manually, but I&#x27;m sure there are some automations that could benefit from this.
评论 #36492514 未加载
SpaghettiX将近 2 年前
There is an even longer and useful list on <a href="https:&#x2F;&#x2F;git.herrbischoff.com&#x2F;awesome-macos-command-line&#x2F;about&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;git.herrbischoff.com&#x2F;awesome-macos-command-line&#x2F;abou...</a>
balls187将近 2 年前
“say” with my laptop connected to my home bluetooth speakers is a lot of fun with my kids.
Crontab将近 2 年前
When a new MacOS release comes out, one of the first things I look for is adds and changes to the command line tools. Sadly they are not the things that most people care about on a new release.
oregano将近 2 年前
At the risk of sounding like an idiot, can someone please explain why I cannot use `networkQuality` when zsh is my shell? Is there an alternative for zsh?
评论 #36501762 未加载
d4rkp4ttern将近 2 年前
I recently discovered snippet-management tools, which I didn&#x27;t know I needed. I&#x27;m trying Maccy and Paste. Curious which ones others love.
tommica将近 2 年前
Oh, the `say` command is really damn useful to know about!
MobiusHorizons将近 2 年前
I didn’t know about textutil before, I’ll have to try that. Does that use the same backend as pages for word documents? How good is the conversion?
coding123将近 2 年前
Caffienate will save my ass going forward. I don&#x27;t know how many times I end up being the person that runs some batch job on my system...
评论 #36493314 未加载
miohtama将近 2 年前
say - text-to-speech engine:<p>I would have expected that at the era of AI this would sound a bit better than the Commodore 64 speech synthesis from 80s.
评论 #36498560 未加载
prvc将近 2 年前
What it really needs is a way to prevent sleeping when the lid is closed (only) during a system update.
varispeed将近 2 年前
Interesting so many useful commands, but they didn&#x27;t have time to fix basics like scroll wheel, so you have to install 3rd party apps to set it independently from the touch pad and then it still manages to swap it around at random times.<p>Am I the only one who finds macOS so annoying?<p>I mean the apps for scroll wheel, alt-tab and what not...
评论 #36493936 未加载
ernst_mulder将近 2 年前
Many thanks OP for the couple of commands I did not yet know. Especially `pbcopy` and `pbpaste`, those are going to be very useful.<p>Here are a couple of commands I use quite a lot.<p>lsof -p &lt;PID&gt;<p>Lists the open files of the process with process ID &lt;PID&gt;. Very very useful.<p>fs_usage -w &lt;PID&gt;<p>This one is mentioned by others here as well, but followed by a &lt;PID&gt; it shows all filesystem activity of the given process. Useful if you want to know where specific settings of an application are stored.<p>top -u<p>Obvious what this does, standard command. Sorted by CPU usage.<p>&lt;some command&gt; | open -ft<p>Opens the &lt;some command&gt;&#x27;s result in your default text editor.<p>system_profiler<p>Very useful for finding out stuff. E.g. system_profiler SPNVMeDataType SPSerialATADataType | grep &#x27;BSD Name: disk[0-9]$&#x27; | sed &#x27;s&#x2F;.\* &#x2F;&#x2F;&#x27; Gives the device name of all your system&#x27;s SATA and NVMe SSD&#x27;s.<p>sysctl -a<p>Another way to find out stuff. E.g. sysctl -a | grep hw.memsize Shows the amount of physical memory in your system.<p>tmutil<p>Very powerful for managing Time Machine as mentioned by others here. Also useful for other stuff. There is a lot of File I&#x2F;O on my system due to running at least five VM&#x27;s all the time. This produces big snapshots. Every now and then my system hung up due to running out of space because of these snapshots. Now I&#x27;m running my own &quot;snapshottaper&quot; daemon running every ten minutes keeping only the last 4 snapshots and deleting the rest, using &quot;tmutil listlocalsnapshotdates&quot; and &quot;tmutil deletelocalsnapshots&quot; which eliminates that issue (which is a bug imho).<p>And some of my often used (tcsh) aliases:<p>proc, aliased to &#x27;ps -axww -o pid,user,command | grep -v &quot;grep -i&quot; | grep -i \!\* | sed &quot;s&#x2F;^\ *&#x2F;&#x2F;&quot;&#x27;<p>Filter the list of running processes for a specific string, e.g. use &quot;proc adobe&quot; to find all running processes by Adobe. I use this a lot.<p>spf, aliased to &#x27;dig \!* txt | grep &quot;v=spf&quot;&#x27;<p>Useful for finding SPF records for a given domain, e.g. &#x27;spf apple.com&#x27;.<p>mx, aliased to &#x27;dig \!\* mx | grep -v &quot;^;..*&quot; | grep &quot;IN\WMX&quot;&#x27;<p>Same, but for MX records (I maintain e-mail servers, hence these two).<p>est, aliased to &#x27;netstat -n | grep -i proto ; netstat -n | grep ESTABLISHED | grep -v 127.0.0.1&#x27;<p>List all currently open network connections.<p>listen, aliased to &#x27;sudo echo -n; sudo lsof -i4 -n -P | grep &quot;\*:&quot; | sed &quot;s&#x2F;IPv4.*:&#x2F;&#x2F;&quot; | grep LISTEN | sort -n --key=5 | sed &quot;s&#x2F; (LISTEN)&#x2F;&#x2F;&quot; | awk BEGIN\ \{print\ \&quot;COMMAND\ \ \ \ \ \ \ \ \ \ \ PID\ \ \ \ \ \ \ USER\ \ \ \ \ \ \ PORT\&quot;\}\ \{printf\ \&quot;%-10s\ %10s\ %10s\ %10s\\n\&quot;\,\ \$1\,\ \$2\,\ \$3\,\ \$5\}&#x27;<p>List all processes currently listening on network ports.<p>router, aliased to &#x27;netstat -rn -f inet | grep default | grep -v link | awk \{print\ \$2\} | head -1&#x27;<p>List the currently used internet router.<p>(I hope all escape characters and such survive posting this, please excuse me if they don&#x27;t, also my default command shell is tcsh for historical reasons, it was my default shell in the early 1990&#x27;s. Yes my shell scripts are all #!&#x2F;bin&#x2F;sh)<p>Other than these, I really like using AppleScript and shell scripts together. Using AppleScript I now have my own GUI tools for making disk images using drag-and-drop, compacting sparse images, performing default settings for new installations, switching between virtual machines whilst hiding others, etc.
louzell将近 2 年前
opensnoop is also a good one that usually stays under the radar
efitz将近 2 年前
Someone should turn this HN discussion into a gist.
评论 #36496243 未加载
iNic将近 2 年前
`mdfind` and `networkQuality` seem very useful!
birdyrooster将近 2 年前
I never knew sips was a thing, cool!
评论 #36492593 未加载
tobiasbischoff将近 2 年前
Super cool.
koinedad将近 2 年前
pbcopy and pbpaste are soooo helpful
msie将近 2 年前
json_pp
lasermike026将近 2 年前
Wow! So cool! Thanks!
29athrowaway将近 2 年前
pandoc is the definitive document converter.
shortrounddev2将近 2 年前
While you&#x27;re at it, `brew install coreutils`. The coreutils that ship with macOS lack a lot of features available on Linux. If you use bash, I recommend upgrading it, too, since Apple ships a 16 year old build (iirc due to legal issues associated with GPLv3) `brew install bash`
评论 #36493701 未加载
评论 #36493196 未加载
评论 #36495525 未加载
thadk将近 2 年前
Having ChatGPT or equivalent create a basic Makefile for these commands (and other commands) is a quick way to preserve your process for later. You can show it your file structure first too.
nanovision将近 2 年前
Not a big fan of command lines. but my most used shortkey is ALT+M with Maccy installed.
评论 #36493820 未加载