
You want the open command, i.e.: open filenameorURL (You can use -a to force a different application to run. The related Windows commands assoc and ftype are useful for setting the file type (for a given file extension) and the open command (for a given file type). That's why cmd line still is very useful. As usual, run help start to learn more about its options. via ssh), using finder is not possible at all.
#Mac file extensions for command line mac
Maybe it's easier in finder to rename files, but if connected remotely to a Mac (e.g. I know even people who would prefer to write a 50-lines or so perl script for this simple every-day task. Click the arrow next to Name & Extension to expand the section.
#Mac file extensions for command line install
However, if you like complexity, you can even use awk and if you like to install other programs to just do basic work, there is ren. For one file On your Mac, select a file, then choose File > Get Info, or press Command-I. To see the actual commands being executed by sh, just add an -x option after sh, which turns on debugging output in the shell, so you will see every mv command being executed with the actual arguments passed by the sed editor script (yeah, another script inside the script :-) ). Everything running in a Unix shell is always a script/program, which is just some ASCII-based stream (in this case an instruction stream opposed to a data stream). Of course it works even for filenames with spaces in it.īTW: Every time you type something in Terminal you create a script, even if it is only a single command with one word like ls or date etc.

So let's just feed the script produced by the one-liner script to sh, which is the script interpreter of OS X.

You can create/modify not only output using commands, but also commands (right, that is commands created by a command, which is what Brian Kernighan, one of the inventors of Unix, liked most on Unix), so let's take a look what the ls and the sed produces by removing the pipe to sh: $ ls | sed 's/^\(.*\)\.txt$/mv "\1.txt" "\1.md"/'Īs you can see, it is not only an one-liner, but a complete script, which furthermore works by creating another script as output. Mac users can quickly get the bit rate of any MP3, m4a or other audio file from the OS X command line. I, -mime Causes the file command to output mime type strings rather than the. Why looping with for if ls by design loops through the whole list of filenames? You've got pipes, use them. This is the default if the environment variable POSIXLYCORRECT is not defined. The preferred Unix way to do this (yes, OS X is based on Unix) is:
