Questions tagged [command-line]

Using programs and commands that do not have a graphical user interface (GUI) but are rather controlled by typing text commands into a terminal program, or shell.

A command-line interface () is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks. On macOS the default shell is zsh and in the past it was bash. This tag is appropriate for all shells and command line questions whether using the terminal.app or other program to access that shell. This text-only interface contrasts with the use of a mouse pointer with a graphical user interface () to click on options, or menus on a text user interface (TUI) to select options. A notable benefit of the command line is the ability to chain commands and operate with files as input and output which lead to powerful capabilities for automation and scripting.

This method of instructing a computer to perform a given task is referred to as entering a command. The system waits for the user to conclude the submitting of the text command by pressing the Enter key (a descendant of the carriage return key of a typewriter keyboard). A command-line interpreter then receives, parses, and executes the requested user command.

Upon completion, the command usually returns output to the user in the form of text lines on the CLI.

Related tag:

See also: Wikipedia Command-line_interface.

NOTE: Questions relating to programming (purely about the language, syntax, or runtime errors) belong at Stack Overflow where programming questions are best asked and answered. This tag is preferred for questions that don’t relate directly to terminal.app the program as it is more general covering ssh, any terminal type app that use the features of the idiom and shell languages.

3167 questions
84
votes
5 answers

Install shuf on OS X?

Ubuntu Linux has a great tool called shuf, which works like head except that it gives you ten random lines. I couldn't find it on Homebrew. What is the simplest way of installing it on OS X?
39
votes
3 answers

What is the equivalent of netstat -tln on OS X?

What is the equivalent of Linux's netstat -tln on OS X? Options: -l, --listening (Show only listening sockets. (These are omitted by default.) --numeric , -n (Show numerical addresses instead of trying to determine symbolic host, port or user…
lolski
  • 515
38
votes
2 answers

How to open an image file from bash in Mac?

I am fairly new with a Mac (Mac from work), and get more and more disappointed. Now I am blocked again, because I did not find an EASY way to open an image from the command line... Here is how it works in Linux (simple, no installation…
Alex
  • 2,334
10
votes
2 answers

How to make "say" command speak AND output to the file at the same time

When using the say command I can give it an option -o (file name) for it to record to a file. However, that suppresses the audio output. Is there a way to make it do both in one command?
ivanibash
  • 267
8
votes
2 answers

How do I "Get Info" from the command line?

Related to this question: https://superuser.com/q/514528/90435 Via http://osxdaily.com/2010/10/12/find-out-where-a-file-was-downloaded-from/ I find out that you can use 'get info' though Finder to find out where a file was downloaded from. For…
Joe
  • 5,039
8
votes
3 answers

Can grep highlight matching text without hiding file content?

I frequently use grep's context command line options (-A, -B, and -C), but occasionally I want to view the whole file with matching expressions highlighted. To accomplish this currently I simply specify -C 999999999, but this seems silly. Is there…
Jason Salaz
  • 24,471
8
votes
1 answer

Is there a gui fuzzy finder like rofi?

Rofi is a fuzzy searcher for linux (select one entry from a set of entries quickly by typing a substring). fzf is a similar tool for the shell. This is useful for quickly producing hacky GUI interfaces. Is there a similar way to easily select one of…
Att Righ
  • 382
7
votes
3 answers

How to start OS X applications from the command line with optional arguments?

I am looking for an easy way to start different GUI OS X applications from the command line and with different parameters. If possible I would like to add them to the system PATH in order to call them easier. Note: I tried open -a "Google Chrome"…
sorin
  • 29,875
6
votes
2 answers

How to automatically watch for file changes and perform a custom action inside shell?

For example, I'd like to automatically run YUI Compressor whenever I edit a JavaScript source file to output a compressed version. Ideally the process does not run in the background but in a dedicated shell, so I can easily terminate the process at…
Gerry
  • 14,551
6
votes
2 answers

Printing the current date/time with sub-second precision

GNU date(1) understands the %N format spec, which outputs nanoseconds, so: $ date +%H:%m:%S.%N outputs 19:10:03.725196000 BSD date doesn't understand %N. How can I print the current time with sub-second precision on OS X?
6
votes
3 answers

How can I initiate a modem connection from the command line?

I am looking for a way to initiate a PPP connection with my EVDO modem from the command line instead of having to go to System Preferences -> Network and hit "Connect".
eric
  • 209
6
votes
3 answers

Can command-line commands be made insensitive to order of filenames and options?

I'm new to Mac usage. It seems that most commands trip over options given after the file names. In linux, which I've used for years, it doesn't matter. On Apple, it does. Is there some setting somewhere or some hack to make commands like ls…
DarenW
  • 5,133
6
votes
2 answers

Using grep on Mac-style text files

When I run grep on a text file, I get nonsense results. It seems as if the whole file is printed out but on one line overwriting itself. I read that on the Mac, text files use \r instead of the normal \n as a line ending. That would explain it,…
DarenW
  • 5,133
6
votes
2 answers

Why does tcpdump not recognise piped input?

I obtained a packet capture file: $ sudo tcpdump -w file.pcap I can then analyse that file: $ tcpdump -r file.pcap I can even use file redirection to read from standard input: $ tcpdump -r - < file.pcap However, I cannot use a pipe to read from…
eggyal
  • 488
6
votes
4 answers

How to copy and paste lines in Nano on OSX

I would like to copy and paste multiple lines in the command line text editor nano on OSX Mountain Lion 10.8.5 Alt-6 and Ctrl-U do not work as on other platforms.
codecowboy
  • 3,262
1
2 3 4 5