DEV Community

Cover image for Get started with Linux: A developer's friend
DoreenNangira
DoreenNangira

Posted on

Get started with Linux: A developer's friend

Do you want to take full control of your system operations? Want to know what happens behind the scenes? Well you need to know how to interact with the terminal. In this tutorial, we will go through some important Linux commands. This tutorial is not only for developers. System administrators, Devops engineers and cyber security professionals need this too!

What is Linux?

Linux is an open source Unix-like operating system. This means the commands that you run on any Unix machine will be similar to the ones you run on Linux.

Linux distributions

The Linux ecosystem has various distributions such as ubuntu, arch linux, fedora etc. In this tutorial we will be using ubuntu.

Installation

To get started, make sure you have a Linux distribution installed in your machine. For those using MacOs or Unix machines, you do not need to install anything. You just need to open your terminal and you are good to go.

For those using windows OS, you will need to first of all install WSL in your system. WSL is a feature that enables you to have a Unix like terminal in your windows machine.

Steps to follow:

  • Open windows powershell as an administrator
  • Write pip install wsl
  • Install ubuntu
  • Set your username and password for your ubuntu
  • Navigate to Microsoft official website and type windows terminal
  • Pick download windows terminal
  • After downloading windows terminal it will open in powershell

Image description

You can change the terminal from powershell to ubuntu by clicking the dropdown arrow and choosing ubuntu as shown below

Image description
Once your screen appears this way, then you are ready to start!

Basic Linux commands

whoami: This returns the name of the currently logged in user
Navigate to your terminal then type whoami. Press enter and see the magic

Image description

man: This command stands for manual. It gives us information about other commands and usage. You can call it the linux google!
Type man then press enter.

Image description
Now type man whoami

Image description
To get out of man page, press **q **and get back to the terminal

pwd: This command tells you the current directory in which you are.
This really helps a lot especially when you have to run commands in a specific directory.
Image description
Type **pwd **then press enter

Image description

mkdir: This command is used to make a new directory or folder
Type mkdir followed by the name of the directory you want to make
Example let's make directory named Friday

cd: To navigate to the directory you just made. type **cd **followed by name of the directory.

Image description

ls: This command is used to list the contents of your folder.
Our current directory Friday has no content. So when you type the ls command you will not see anything. Try it.

Image description
To see some content in our directory we will need to add some content. let us do this using the next command we will learn.

touch: This command is used to create files
write touch followed by the name of your new file

Image description
now use the ls command to check if the new file created is present

Image description

ls -l: This lists contents of your folder or file in long list format. It shows you the person who created the files or folder, when it was created, file permissions etc.
type ls -l then press enter

Image description

mv: This command has two main uses. it is used to rename a file and also used for moving files to a different folder.
Let's first check the first use of renaming a file.
type mv followed by the current file name then the new file name
eg mv afternoon evening. Press enter then type ls to check the new file name

Image description

To implement the second use of mv command, we need to make a new directory.
Use the command mkdir to make a new directory called day

Image description
Now to transfer the evening file into day folder, write mv evening /day. Please note that sometimes when you type this command you will get permission denied. This is a linux feature for security that ensures some actions are only performed by authorized users. To bypass this, write sudo mv evening /day. The sudo command gives you administrative privileges. You will be prompted for a password when you use sudo. Type in your linux password then press enter.

Image description
Please note the / sign before name of folder. press enter.
To check the contents of the new folder day, type ls /day

rmdir: This command is used to delete a directory. Let us delete the directory day. Type rmdir followed by name of directory you want to delete. eg rmdir day. Type ls to check that the directory no longer exists

Image description
rm: This is used to delete a file
let's make another file called tutor then we delete it.
type touch tutor to make the file then type ls to confirm that it is present. Now type rm tutor to delete it then type ls to see what happens

Image description

cd -: We looked at cd command that means changing directory. Now what does cd - do? The cd - takes you back to your previous directory. Type cd - then press enter.

Image description

Conclusion

We have come to our end of this tutorial. This should form as a basis to get you started in the world of Linux or Unix systems. Feel free to leave your feedback and suggestions on the topics I should discuss with you. Thank you and see you in my next tutorial!

Top comments (0)