Terminal Flashcards
cd
Change Directory, 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.
ls
Listing Directory, 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.
open “filename”
Open files, 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.
cp “filename” “newfilename”
Copy a file to another directory , 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.
mv “filename” “path/to/new/file/location”
Move a file , 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.
touch myfile.txt
The touch command allows you to create any type of file, but it’s blank. After you create the blank file, you can open it in a text editor by typing open [filename].
mkdir
This command will allow you to create a directory (folder) right from 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.
rmdir “path/to/directory”
When you’ve created a folder that has the wrong name, you can easily use the mv command to rename it, or if you want to remove a directory altogether, use the rmdir command followed by the path to the directory.
sudo “command”
sudo (or super user do) is a command that allows you to elevate your user privileges while executing the command to administrator privileges. This is required for some commands to run —for instance removing a file that is owned by another user. When you run this command, you will see a password field appear in the Terminal where you will need to type your user account password to finish the command execution.
top
List actively running computer processes , You’ll see the stats of your system updated in the Terminal window, including the memory, CPU and disk utilization. You’ll also see a running list of the top apps using the CPU and their state, ports used, memory per app and more, without needing to open the Activity Monitor app on your Mac. This command will execute until you close the Terminal window or press Control + C to return execution back to the CLI.
ditto -V MyFolder MyNewFolder
Copy contents of a folder to a new folder, The ditto command will execute a copy of all of the contents of one folder into another folder that you specify. This is great for when you need to start a new project and use an older project as a base, or just 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.
whatis “command”
Get one-line description for a command, When you want to get a short description of a command and what it does on your Mac, use this command to find out.
man “command”
Show manual page for a command, Most commands in the Terminal ship with a manual that allows you to get help or look up arguments and other information on what a command does. Use this man command when you want to find more information about a particular command.
nano “Document.txt”
nano command lets you open the specified file with nano editor which is an enhanced version of the Pico editor.