Saturday, 24 October 2015

Terminal Commands Crash Course Part I

Hey geeks, whats up? I hope you are still following our posts. And if you do, there's one thing that we've
been using a lot since the dawn of this blog: Linux Terminal Commands. So, i decided to write a post about the basic terminal commands.  This post is for beginners and  enthusiasts who would like to learn and explore the basics of terminal commands. Also, this is NOT a complete reference guide, but just a starting point. So let's begin.

Press Ctrl+Alt+T to open a terminal. This shortcut works on most distributions of Linux like Ubuntu. If that is not the case, search for Terminal somewhere and you will find it.

BASIC LINUX TERMINAL COMMANDS


 

The date command


This command displays the current system date, time and timezone. Simply type date and press Enter.

The cal command


This command displays the calendar, with the current date highlighted.

The pwd command


The pwd command lists the Present Working Directory, that is, the current folder in which you are working. When you open a terminal, you are in the home folder (folders are also called "Directories" in Linux). This is usually /home/user, where user is the username that you had set while installing linux.

The clear command


This command clears the terminal i.e. it removes the previously typed commands in the terminal. The shortcut for this command is Ctrl+L.

The ls command


The ls command is used to list all the files and folders in a folder. The contents of current directory are shown. Note that the contents of this folder may vary from one distribution of Linux to another, and of course, one system to another.

Terminal Commands

Now, if you want to see the contents of a different folder, say /usr, type ls /usr and it will display the contents of that particular folder.

The paths in Linux can be of two types: Absolute and Relative. An "absolute" path is the actual path or position at which a file or folder is present. Everything in Linux is inside the "root" folder, denoted by a "/" symbol. So,  /home/niks/Desktop is an absolute path. On the other hand, the "relative" path is the path of a file or folder  relative to the current working directory (displayed by pwd). So, if pwd shows /home/niks, then Desktop/ is the relative path to Desktop. The ls command can understand both types of paths. So, the following two commands are same (assuming pwd to be /home/niks):

ls Desktop/
ls /home/niks/Desktop

Every command in Linux can be modified by specifying options. The options are specified alongwith the command and usually begin with a '-' (for single character options) and "--" (for multiple character options). The ls command can also be modified using some options. We will discuss some of them here.

-a : In linux, the hidden files begin with a dot ".". For instance, ".nikhil" is a hidden file and will not be shown by ls command. To see such hidden files, type ls -a.

-l : This option displays more details about the files/folders. Technically speaking, it displays the contents of a folder in "Long Listing" format, that is, it shows some more information namely:

=>File type (d for folder, - for file, l for links etc)
=>The permissions (r for read, w for write and x for executing) for user owner, group owner and others.
=>Number of hard links
=>The owner and group name
=>The size in bytes
=>The date and time when it was last modified (called timestamp)
=>The name of file/folder

My advice is, just don't go into the details of what they mean right now. It will become clearer once you start using Linux a bit more.

Terminal Commands

-h: By using this option alongwith -l, the size of each file or folder is shown in "human readable" form, i.e. in kilobytes, megabytes or gigabytes.

To specify more than one option to ls, you can type either of the following:
ls -lh
ls -hl
ls -l -h

All the above commands are equivalent.

Terminal Commands

The cd command


cd stands for "change directory". It allows you to change the current workinf directory in your terminal. Here also, we can provide both absolute and relative paths. Some examples are given below. You can use pwd after each commad to confirm that the current working directory is changing:
cd /etc/
cd ../usr/bin
cd ..
cd ./bin

Another thing to note is that while using relative paths, you can use "." to denote the current directory and ".." to denote the parent directory, that is, the directory or folder in which the user is currently present. So, the parent directory of /home/niks is /home, and that of /home/niks/Downloads is /home/niks. Note that root is eventually an "ancestor" of all directories, meaning that everything is present inside root (/).

Terminal Commands

Now, just go through the above commands and try them out...we will discuss some more commands in the next section. Comment below for queries!

2 comments:

  1. […] In this post, we will talk about some more basic terminal commands in Linux. If you haven’t checked out the first part of this post, do check it out here. […]

    ReplyDelete
  2. […] so that we can demonstrate how it works. If you are a total beginner with Linux, i suggest you learn about the basic commands linux here. These will eventually be helpful if you want to learn more about hacking and stuff. We will be […]

    ReplyDelete