Ticker

6/recent/ticker-posts

Top 11 - Basic Terminal Commands

1. Change Directory

Command = cd

This command will change the directory that you’re currently working within 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. You will be using this command multiple times a day so get familiar with it. What if I don't know all the names of the directories I hear you ask. Well just use cd and the tab button and it will give you the options for you to choose from. 

Example: cd “scottsProjects/” 


Example: cd + tab “scottsProjects/” 



2. Listing Directory

Command: ls

Once you have cd into the directory use ls to give you a list of the directories/ files that are in the current directory you are in. It just gives you a bit more information like more information about each of the files, including the permissions, owner and date created.

Example: ls “scottsProjects/”  


3. Create a directory

Command: mkdir

This allows you to create your very own directory. You can do this to make a directory in the current path your in.

Example: mkdir “testDirectory”


Or you can make a directory in another location by offering the full path to where you want the director located.

Example: mkdir “testDirectory/anotherTestDirectory”


4. Create a file

Command: touch

This allows you to create whatever type of file you would like. This example is a text file. This will create it in the current directory you are in so make sure you are in the location you want the file.

Example: touch myfile.txt 


5. Copy a file to another directory

Command: cp

We all love a copy and paste. This command allows you to copy a file from one location to the next. You can also go to the file and do it manually if you wanted to. The format for the cp command is as follows

cp <filename.extension> <full location path>

Example: cp myfile.txt “anotherTestDirectory” (Figure D)


6. Remove file

Command: rm

We are all human and we all make mistakes don't worry if you do. There are ways to revert these things. This command allows you to delete a file.

Example: rm “myfile.txt”


7. Remove an empty directory

Command: rmdir

Now that we removed the txt file from anotherTestDirectory we just have an empty directory we don't need. This command allows you to remove that directory. Remember you can be either in the location where that directory is stored and just add the directory name like I have done. Or you can add the full directory path to remove it.

Example: rmdir “anotherTestDirectory”


8. Execute commands with superuser privileges

Command: sudo

You know when you need to give an application admin rights to do something this is basically what you're doing with sudo. It just means your allowing the command you're trying to do to have elevated privileges. When you run this command you will see a password prompt. You will need to enter the correct password to continue. Remember that you won't be able to see anything being typed but if you are typing it will go into the command line don't worry. 

Example: sudo “command”


9. Clear the Terminal screen

Command: Clear

There are sometimes when the terminal is just too full. Clear just wipes the terminal screen for you. Don't worry though you can just scroll up to see what was there before.

Example: clear

Before - 

After - 

10. List actively running computer processes

Command: top

If you are like me, you quite like to see what's draining your resources. Or if you know you have a big task you want the computer focused on that. This command allows you to see the stats of your system. Memory, CPU, and disk utilization. It gives you the top apps that your computer is running it allows you to see if there is anything in the background you can close to focus up your resources. 

Example: top


11. Quit sub-screen and return to Terminal

Command: q or Control+C

This is basically a kill command. When your running process is continuously running. This is how you quit them. So for example. Running a server will sit there on your terminal running until you tell it otherwise. These commands come in handy. If you have run the top command above you can see it just sits there running try hitting q or Control+C

Example: After executing a command, such as top to view active processes, press “q” to exit. 



Post a Comment

0 Comments