Skip to main content

Command line Quick Bite 01

It is the black screen you see at the start and is sure looks scary with just a blank canvas. The RISE programme taught us this when we were learning about git push and pull. For many of us, it does not really work and we just seem to be copying what the instructor told us to. Needless to say, I did not go on to learn about it further. I mean GUI (graphical user interface) is good enough right? Well, coders will tell you how it is slow and you can actually do everything with the CLI.

However after I started doing CS50x, I felt more comfortable with it since you need to make directories, make code files, compile and run code files from the terminal in VScode. So here is a compilation of the commands that I find useful to know.

1) cd - change path: to navigate to another directory (aka folder)

eg1. cd Documents

This will bring you from the main directory into your "Documents" folder. Congrats you have moved into the "Documents" folder.

eg2. cd .. 

This will move you back to the previous, bigger directory.

If you are not sure about the names since it needs to be case sensitive, then we can use the trusty 'tab' to fill in the rest. 

2) ls (mac)/ dir (windows)- list out everything that is in the folder.

3) mkdir - create new folder

eg3. mkdir TestCLI

4) echo - create a file based on your specified extension in the current folder you are in. 

eg4. echo "Hello World!" >> hello.txt

This will create a text file with the words "Hello World!" inside. 

** Type dir to check!

5) cp - to copy files and it takes in two inputs, the file that you intend to copy and the new destination filename for it.

eg5. cp hello.txt hi.txt

This will copy hello.txt file in the same directory and the copied file name is called hi.txt.

However we cannot copy a whole folder if there are other files inside using just the cp command, we need to inform the terminal what we want to do with the files using "-r"

You need to move back out of the folder that you intend to copy before you can continue. 

eg6. cp -r TestCLI TestCLI1

This will copy all the content and create another folder name TestCLI1. Move into the folder >> cd TestCLI1 >> dir 

This should list all the items you had in the folder. 

6) rm - remove a file. Note that rm will remove completely since it is not going into the recycling bin. 

eg7. rm hi.txt

Viola hi.txt file is gone....forever.

eg8. rm -r TestCLI1 

Now the whole folder TestCLI1 is gone too.

7)mv - move file, essentially renaming the file 

eg. mv Hello.txt Hello1.txt

This allowed us to rename the file from Hello.txt to Hello1.txt. This saves us two steps from having to copy to Hello1.txt then deleting the file. 

8) whoami - check out the user and name of the computer being used.

This will return the user currently logged in. Though not really important but probably quite cute to ask this at the terminal. 

9) ctrl+c will kill the command that you had been running. 

10) ctrl+l - clear the terminal screen if it is getting too much clutter.

11) exit - close the terminal window

These days I just use the search function and type terminal to get it open again. 

12) Other fun command lines that CS50x suggest to try:

chmod 

ln

touch

man

diff

sudo

clear

telnet

I have not tried them yet. If you had and they are useful, do let me know in the comments. ^^

To a more proficient coder!

Comments