Terminal, or the command line interface (CLI), is considered by many to be the Holy Grail of computer management. At one time the CLI was the only way to accomplish anything on a computer; then, the CLI gave way to the graphical user interface (GUI) as the popularity of PCs increased. The purists among us often prefer to use the CLI as a means of manipulating the computer and getting it to perform tasks instead of using a mouse to get things done.
Over the years the Mac GUI has changed the way we work, but 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 allow users to work faster for basic or repetitive tasks. Commands can be chained together to increase their usage, and more.
Anyone on a Mac built after Mac OS X’s initial debut in 2001 can experience the command line interface through the Terminal app on their Mac through the UNIX-based shell. This app can be found inside of the Applications | Utilities folder (open a Finder window and press Command+Shift+U). The Terminal works by entering commands on the keyboard and pressing return to execute the commands. The Terminal will then respond after the command has been executed with any relevant information available (some commands may not echo back any output).
Open up the Terminal and follow some of the basic CLI commands below to grow your knowledge of how you can use command line interfaces on a modern Mac to get work done.
1. Change Directory or in the case of DOS/CMD Command Directory
Command: cd
What it does: This command will change the directory that you’re currently working with in the Terminal in order to execute other commands on a different directory, view the contents of a different directory or open a file in a different directory. This is a very common command that will be used when working with the CLI. If you ever lose your place and which directory you’re in, type pwd (print working directory) and press Return to echo the current path.
Example: cd “path/to/directory/” (as you see below)
jayp@ethio-tech$ cd /var/www/html/
2. Listing Directory
Command: ls
What it does: Use this command after navigating into a directory using the cd command to view the contents (files and directories) 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.
Example: ls “path/to/directory/”
jayp@ethio-tech$ ls /media/jayp/
3. Open files
Command: open
What it does: When browsing a directory, you may encounter a file that you wish to open on your Mac. That’s where the open command comes in. Typing this command followed by a space and the filename will open the file with the app that can open that file type on the Mac. When typing the filename, you don’t need to type the full name, partially type what you can, then press tab to autocomplete the remaining text.
Example: open “filename”
jayp@ethio-tech$ open “word.app”
4. Copy a file to another directory
Command: cp
What it does: This command facilitates copying a file from one location to another, or just simply making a copy of the same file with a new name. When specifying the first argument, include the originating file that 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. The Terminal will return when the copy has been completed.
Example: cp “filename” “newfilename”
jayp@ethio-tech$ sudo cp smb.conf newsmb.conf
5. Move a file
Command: mv
What it does: When you don’t want to copy a file, but instead move it, use the same format of the cp command, but instead replace ‘cp’ with ‘mv’. This will perform a file move from one location to another, removing the file from the original location and putting it into the new location.
Example: mv “filename” “path/to/new/file/location”
jayp@ethio-tech$ mv smb.conf /srv/samba/
would you like a part 2 to this tutorial let me know in the comments below