Sign in
Log inSign up

Basic commands in Unix

Santosh Balchandran's photo
Santosh Balchandran
·Aug 22, 2020·

4 min read

In this blog I am going to discuss some basic commands in Unix. Before going to the commands let us understand the structure of UNIX system.

Structure of the UNIX system

Unix_scaled.png

The core of Unix is called kernel. It controls and manages everything in the system.This is the section that performs all hardware access. In the above figure we can see that on top of the hardware, kernel is present.

Above kernel lies the shell. The shell acts as an interface between the user and the kernel. This is where we write our commands. The shell accepts and interprets commands through a command line interface known as terminal.

The layer of Application lies above the shell where we have GUI applications like file explorer, dbms, etc.

As a software developer, one must be well versed with the commands that is required to perform various operations in the system.

Let us look at some basic commands :

  • man - prints the working manual of the command passed as the argument
  • clear - clears the terminal screen
  • exit - exits the terminal window
  • echo - displays the string passed to the command.

Now let us look at some commands used for file manipulation :

  • touch - creates a file
  • head - displays the first 10 lines of a file
  • tail - displays the last 10 lines of a file
  • cat - displays the output from more than one file simultaneously
  • echo - (we have seen this in the set of basic commands) here the command helps to append content to the end of the file.
  • nano - opens the nano text editor
  • grep - searches for a string in the given file
  • rm - deletes a file

Finally let us look at some commands for working with folders :

  • mkdir - creates a folder
  • pwd - gives us the path of the current folder
  • ls - lists the content of the current folder
  • cd - used to navigate to a specified folder
  • mv - renames the folder(file as well)
  • rmdir - deletes a folder

As I conclude, let me discuss one more command

rm -r : used to delete a folder

Why to use "rm -r" if we can use "rmdir"?

rmdir deletes a folder only when it is empty, whereas rm -r deletes the folder along with sub folders and files from the specified folder.

For the above command r is a flag or option that tells to recursively delete from the specified folder. There are many other flags as well with various commands.

That's it for this blog!