What Is The Cd Command For Mac Os X Terminal

0 views
Skip to first unread message

Cinderella Zollman

unread,
Jan 25, 2024, 11:26:35 AM1/25/24
to hoysecontsupp

Over the years, the Mac GUI has changed the way we work. Still, many people use the command line for its ability to control and automate tasks or even configure features on the Mac that are only accessible through the CLI. Some things in the Terminal app allow users to work faster for basic or repetitive tasks. Commands can be chained together to increase their usage, and more.

What Is The Cd Command For Mac Os X Terminal


DOWNLOAD » https://t.co/IzWociKpFT



Learning some of the basic CLI commands is an easy way to grow your knowledge of how you can use command line interfaces on a modern Mac to get work done efficiently. So open Terminal, and start exploring with the commands below.

The Terminal app works by entering commands on the keyboard and pressing return to execute the commands. Terminal will then respond with any relevant information available. Although, some commands may not echo back any output.

Even with macOS Sonoma, Apple has continued to ship updates to the macOS Terminal app that allows users to interact with the underlying UNIX command line. This makes the Mac extremely powerful and a great option for power users and nerds who want the most power out of their computer.

What it does: Use the ls command after navigating into a directory using the cd command to view the contents inside of the current directory. Use the argument -l (ls -l) to get even more information about each of the files, including the permissions, owner and date created.

What it does: The cp command facilitates copying a file from one location to another or making a copy of the same file with a new name. When specifying the first argument, include the originating file you wish to copy followed by a space and a full path, filename and extension of where you want the copy to be placed when the command is executed. Terminal will return when the copy has been completed.

What it does: The mkdir command will allow you to create a directory (folder) from within the CLI. When you need a place to store new files, just use this command to add a new directory in the current working directory, or specify a full path to the location where you want the new directory to be placed.

What it does: When you want to remove an entire directory that might contain other directories or files, then the rm -R command is where you will turn. This command is irreversible, unlike deleting files in the Finder and being able to restore them from the Trash. When this command is executed, all files and directories inside of the path you specify will be deleted immediately.

Your Mac has security baked in at its core, which is why when typing a password, the command line hides the characters typed for security practices. Remember to never type your password into a field that you did not request!

What it does: For commands that run in perpetuity when executed, you can end execution of the process by pressing the q key on your keyboard. Alternatively, you can press Control + C.

What it does: The ditto command will execute a copy of all of the contents of one folder into another folder you specify. This is great for when you need to start a new project and use an older project as a base or if you just need to copy files in a folder from your computer to an external drive. Add a -V, as in the example below, to get verbose output for each file copied.

What it does: Most commands in Terminal ship with a manual that allows you to get help or look up arguments and other information on what a command does. Similar to the whatis command, you can use the man command to find more information about a particular command.

A large number of tools can be used by typing commands into the command line; many come pre-installed on your system, and a huge number of others are installable from package registries. Package registries are like app stores, but (mostly) for command line based tools and software. We'll see how to install some tools later on in this chapter, and we'll learn more about package registries in the next chapter.

One of the biggest criticisms of the command line is that it lacks hugely in user experience. Viewing the command line for the first time can be a daunting experience: a blank screen and a blinking cursor, with very little obvious help available on what to do.

The terminal originates from around the 1950s-60s and its original form really doesn't resemble what we use today (for that we should be thankful). You can read a bit of the history on Wikipedia's entry for Computer Terminal.

macOS has a system called Darwin that sits underneath the graphical user interface. Darwin is a Unix-like system, which provides the terminal, and access to the low-level tools. macOS Darwin mostly has parity with Unix, certainly good enough to not cause us any worries as we work through this article.

Windows has traditionally had its own terminal-like program called cmd ("the command prompt") for a long time, but this definitely doesn't have parity with Unix commands, and is equivalent to the old-style Windows DOS prompt.

In terms of what option to choose on Windows, we'd strongly recommend trying to install the WSL. You could stick with the default command prompt (cmd), and many tools will work OK, but you'll find everything easier if you have better parity with Unix tools.

Generally, you'll find these two terms used interchangeably. Technically, a terminal is a software that starts and connects to a shell. A shell is your session and session environment (where things like the prompt and shortcuts might be customized). The command line is the literal line where you enter commands and the cursor blinks.

When you visit the command line you will inevitably need to navigate to a particular directory to "do something". All the operating systems (assuming a default setup) will launch their terminal program in your "home" directory, and from there you're likely to want to move to a different place.

To change the directory, you type cd into your terminal, followed by the directory you want to move to. Assuming the directory is inside your home directory, you can use cd Desktop (see the screenshots below).

If the directory you want to go to is nested deep, you need to know the path to get to it. This usually becomes easier as you get more familiar with the structure of your file system, but if you are not sure of the path you can usually figure it out with a combination of the ls command (see below), and by clicking around in your Explorer/Finder window to see where a directory is, relative to where you currently are.

Note: To find out exactly what options each command has available, you can look at its man page. This is done by typing the man command, followed by the name of the command you want to look up, for example man ls. This will open up the man page in the terminal's default text file viewer (for example, less in my terminal), and you should then be able to scroll through the page using the arrow keys, or some similar mechanism. The man page lists all the options in great detail, which may be a bit intimidating to begin with, but at least you know it's there if you need it. Once you are finished looking through the man page, you need to quit out of it using your text viewer's quit command ("q" in less; you may have to search on the web to find it if it isn't obvious).

Note: To run a command with multiple options at the same time, you can usually put them all in a single string after the dash character, for example ls -lah, or ls -ltrh. Try looking at the ls man page to work out what these extra options do!

There are a number of other basic utility commands that you'll probably end up using quite a lot as you work with the terminal. They are pretty simple, so we won't explain them all in quite as much detail as the previous couple.

Note: Many terminal commands allow you to use asterisks as "wild card" characters, meaning "any sequence of characters". This allows you to run an operation against a potentially large number of files at once, all of which match the specified pattern. As an example, rm mdn-* would delete all files beginning with mdn-. rm mdn-*.bak would delete all files that start with mdn- and end with .bak.

Let's say you had 1000 text files in a directory, and you wanted to go through them all and only delete the ones that have a certain substring inside the filename. If you are not careful, then you might end up deleting something important, losing you a load of your work in the process. One good habit to get into is to write your terminal command out inside a text editor, figure out how you think it should look, and then make a backup copy of your directory and try running the command on that first, to test it.

In the next section let's step it up a notch (or several notches in fact) and see how we can connect tools together on the command line to really see how the terminal can be advantageous over the regular desktop user interface.

But it can also count the number of lines of whatever output is piped into it. For example, the below command counts the number of lines outputted by the ls command (what it would normally print to the terminal if run on its own) and outputs that count to the terminal instead:

So what is going on here? A general philosophy of (unix) command line tools is that they print text to the terminal (also referred to "printing to standard output" or STDOUT). A good deal of commands can also read content from streamed input (known as "standard input" or STDIN).

We will first try to fetch the contents of MDN's "fetch" page using the curl command (which can be used to request content from URLs), from -US/docs/Web/API/WindowOrWorkerGlobalScope/fetch. Try it now:

Let's also look at the headers that developer.mozilla.org returns using curl's -I flag, and print all the location redirects it sends to the terminal, by piping the output of curl into grep (we will ask grep to return all the lines that contain the word "location").

dd2b598166
Reply all
Reply to author
Forward
0 new messages