DEV Community

Mohammad Shahbaz Alam
Mohammad Shahbaz Alam

Posted on • Edited on

7 Must Know Terminal Commands

If you want to get into Software Development, one thing you should know is how to use Terminal?
Yes, it could be Mac's Terminal, Linux's Terminal, or Windows terminal(not exactly, but run Git Shell or Cmder on Windows).
Don't worry I have your back here, just follow this article, and trust me, you'll thank me later for reading this post.

First of all, lets understand what is terminal?

What is Terminal?

Terminal is a program on your Operating system which lets you navigate throughout your computer’s folders and files, most importantly runs commands to help you perform your task.

Open Terminal

First and foremost, we need to open Terminal, it could be different depending on your OS, and here I trust you, you can open Terminal.

Okay, need help, please follow the below steps depending on you OS:

If you are on a Mac, hit "command + space bar" and you’ll get the computer’s "Search" bar. Once that pops up, type in "Terminal" and hit "Enter".
Mac's Terminal
Mac Terminal

If you are on Linux, hit "The Windows logo key" (also known as Windows-, win-, start-, logo-, flag-, or super- key) and type "Terminal" and open the program by clicking on it.
Linux Terminal
Linux Terminal

If you are on Windows, search "Git Shell" or "Cmder" depending on what you have installed.
Cmder Terminal on Windows
Cmder Terminal on Windows

Must know Terminal Commands

  1. pwd
  2. cd
  3. ls
  4. mkdir
  5. touch
  6. clear
  7. man

And stay away from rm, but here I'll teach you how to master that command and use only when really needed.

1 pwd

The pwd command, stands for "Print Working Directory" You type in that command on terminal, and it will print out the exact file path for the file or folder you are in.
pwd

2 cd

The cd command, stands for "Change Directory". There are multiple ways you could use cd commands. Here are those:

  • cd or cd ~: Will take us to the Home directory.
  • cd ..: Will move us back to the parent folder.
  • cd ../test: Will move us back and take us to test folder.
  • cd <folder name>: Will take us to the <folder name> folder. cd

3 ls

The ls command is the list command, it shows what's present in a folder/directory. Again, ls could be used in many ways. Here are few which you might want to use:

  • ls: it will show us everything in that folder.
  • ls -a: it will show the hidden files along with the other listed previously.
  • ls -l: it will display in a long listing format ls

4 mkdir

The mkdir command, stands for "Make Directory". It will create the new folder/directory in that place from where it is run. So always check whether you are at right place using pwd.
mkdir

5 touch

The touch command is for creating file, there are multiple ways you can create a file. But touch is an easiest. Here's how
touch

6 clear

The clear command does what the name say, it "clears" your terminal. It's always a good practice to work in a neat and clean environment.
Once run, the terminal would look like
clean terminal

Or you can use Keyboard shortcut for this, Ctrl + L it is faster on most of the terminals.

7 man

The man command, is an interface to the system reference manuals, this is something which you should use to understand how a command works and what parameters to be used to get the best out of that command. And to be a master of terminal, always refer to this command.
man ls
man ls description

Now, as said, STAY AWAY FROM rm COMMAND

So, here are a few ways you can use rm in necessary situations.

  • rm <filename>: Remove(Delete) the file.
  • rm -i <filename>: It will ask before deleting a file. Remember to use -i, so it gives you some time to double-check before deleting. rm -i will ask before deleting each file.
  • rm -r <foldername>: It will recursively delete a directory and all its contents. (normally rm will not delete directories, while rmdir will only delete empty directories)
  • rm -f: this will forcibly delete files without asking; this is mostly useful if you have rm aliased to rm -i but want to delete lots of files without confirming each one.

Deadliest combination rm -rf <foldername>. Always avoid this command, and never run as root user.

With these terminal commands, you are good to go and get ready to explore the learning paths.

Here's a diagram, which shows what are the paths one could take in Computer Science.

And at last, keep learning, keep sharing.

Top comments (3)

Collapse
 
pgronkievitz profile image
Patryk Gronkiewicz • Edited

Deadliest combination rm -rf . Always avoid this command, and never run as root user.

Unless you know what you want to do

clear

Ctrl+l is faster on most terminals

Collapse
 
shahbaz17 profile image
Mohammad Shahbaz Alam

That's correct!

Ctrl+l is faster, let me update the article.

Thanks for the input :-)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.