A few terminal commands I learned when I first started coding

Terry L
3 min readJun 24, 2021

--

Just a few commands and shortcuts that have helped me navigate the terminal in MacOS. All commands are case sensitive and will be in lowercase.

1.List files and directories
command: ls
This command lists all the contents inside of the current directory.

2. Change directory
command:
cd <directory>
Shortcut: cd .. (The two dots will move you up a directory)
This command will change or move you into another directory of your choosing. Using ls to see what’s available, let’s move into Desktop. An autocomplete shortcut is built into Terminal. Just type the first few letters in the directory (case sensitive) and hit tab. You can also hit tab earlier to see options available.

3. Open files
command:
open <filename>
Now that we’re in the Desktop, let’s open a file.

4. Create a directory
command:
mkdir <name>
That screenshot above could use some organization. I can make a folder or directory for us to move it into. When creating new directories or files, Terminal will not give you a response that it has been done, but we can use ls to verify that it’s there.

5. Copy files to a different directory
command:
cp <filename> <destination>
We can copy files to the newly created directory now. Then cd into screenshots and it’s there!

6. Move files
command:
mv<filename> <destination>
Don’t need a copy and just want to move it instead? Use mv -i to make it interactive. Terminal will prompt you to confirm if you’ll be overwriting a file. -i can be used for copying in step 5 as well.

7. Rename files
command:
cp <filename> <newfilename> <newdirectory>
command: mv <filename> <newfilename> <newdirectory>
Renaming is simple by using the commands from steps 5 and 6. To copy, rename and move the file, add the new filename between filename and destination. If you don’t indicate a new directory, it’ll just make a copy with the new name in the same directory. Using the mv command and keeping it in the same place will just rename the file.

8. Delete files or directories
command:
rm <filename>
For best practice, always use -i. Removing or deleting is very straightforward, using the interactive option helps create a second layer before deleting by accident (I learned this the hard way)!

There you have it, very short, very simple. I hope to write more beginner friendly blogs like this and some that will dive into more advanced features using Terminal or Github. Happy coding!

--

--

Terry L

Current Flatiron School student trying to learn more about software engineering.