Basic Linux commands


So today we are going to learn basic Linux commands, with which you can use a Linux machine if you’re a newbie.
These are just short commands generally you can figure out the function by looking at the command.
NOTE : Each command may or may not have a switch. A switch is an extra letter added with the command to increase or alter or change its functions.

Again, there are thousands of commands in Linux, we will only be looking at the most easiest and always used commands. Once you’re familiarize with Linux, you can look at the more commands.

  • - pwd
    pwd shows you the current directory or place you’re in. So if you are working in one place for a long time and you forgot where you were, you can use pwd to get your current location.
Check current directory.

Check current directory.

 

  • cd
    – Cd stands for change directory.
    – This command is used to go into some other directory.
    – Suppose you’re in ‘/home/abc/123‘ and you want to got ‘/etc‘ then you can use cd.
    – You can also use cd..‘ to move one folder up or use ‘cd ‘ to go home location.
    How to use?
    cd destination_name
    cd /etc  (in this example)
    cd .. (to move one folder up)
    cd (to go the default starting folder)
Change Directory command.

Change Directory command.

 

  • ls
    – ls stands for list.
    – It lists content of the directory.
    – If there is a folder in that directory, it’ll show it in different color.
    Switch with ls :
    ls -a
    this will list all the files present in the folder, hidden files too
    ‘-a’ switch stands for all.
    how to use?
    ls (to show current list of files in current directory )
    ls 'destination' (enter name of folder in destination)
    ls -a
List command

List command

 

  • ll
    – ll shows the content of folder, but in detail.
    – ll shows the extra information of the files, like
    Who can get access to it, What are its permissions, To which admin group and user does it belong to and, Is there a file or a directory?
    – ‘d‘ stands for directory. ‘r’ stands for read access. ‘w‘ stands for write access. ‘x‘ shows the file is executable file.
    – ‘liveuser‘ ‘liveuser‘ stands for the group and user of that directory or file.
    How to use?
    ll (to show list of files in current location)
    ll 'destination'(enter name of folder in destination)
ll command.

ll command.

 

  • mkdir
    – Mkdir stands for make directory.
    – Used to create a new
    directory in the current location.
    – Suppose you’re in ‘/etc’ and you write mkdir rw05 then it will create a directory inside ‘/etc’ with name rw05
    – To create a new directory elsewhere specify the path put a ‘/’ and enter the new directory’s name you want to create.

    Switch with mkdir
    – With mkdir you can use a ‘-p’ switch.
    – This switch enables user to create multiple directories in single command. ‘p’ stands for parent.
    How to use?
    mkdir geekstarts  (mkdir ‘file name’)
    mkdir -p /tmp/vishu/123/456 (creates a directory named ‘123’ and ‘456’ inside ‘/tmp/vishu’ inside ‘123’ respectively).
Make Directory Command.

Make Directory Command.

 

  •  touch
    – Touch is used to create a blank file without any extension.
    How to use?
    touch hello
    touch /tmp/hello (touch /’enter destination here’/’enter filename here’)
Create empty file touch

Create empty file touch.

 

  • cat
    cat is used to view the contents of a file NOT DIRECTORY.
    How to use?
    cat /tmp/hello
View contents

View contents

View contents of file.

View contents of file.

 

  • rm
    – ‘rm’ is used to remove a file.
    – If you only write
    rm file name then it will remove that file if it is present there.
    – It will remove the directory and all the contents inside it.
    Switch with rm
    rm applies to files only. To remove folder and the contents
    of folder you can use ‘-r‘ switch
    -r‘ stands for recursively and ‘-f‘ stands for forcefully.
    How to use?
    rm pqr (Delete ‘pqr’ file)
    rm ‘name or location’
    rm -rf rw05 (Delete ‘rw05’ folder)
Delete a file

Delete a file

NOTE : If you use only -r then it will ask you before deleting anything, where as if you use -f with r, it will simply delete everything inside it without asking you. So try to avoid -f.

 

  • tree
    It will show the contents in the form of a tree.
    How to use?
    tree
Gives a graphical display in tree-like format.

Gives a graphical display in tree-like format.

 

  • cp
    – cp stands for copy.
    – It will copy a file from one place to other.
    Switch with cp
    – There may be more than one files in a directory,,so to copy directory we use ‘-r’ switch which is recursively.
    That is we are telling the Operating System to copy recursively the contents of one folder to other.
    How to use?
    cp /tmp/abc /opt (cp ‘source’ ‘destination’)
    cp -r /tmp /opt (copying tmp folder to opt)
Copying files.

Copying files.

 

  • mv
    – mv is like the cut paste of windows.
    – mv actually stands for move, but can be used to rename.
    How to use?
    mv /tmp/rwcw /usr (mv source destination)
    Suppose you need to rename a folder angel inside /home to rw05
    mv /home/angel /home/rw05 (Renaming angel folder to rw05)

 

Rename file.

Rename file.

 

  • date
    – it will simply show you the date and time.
Shows date and time.

Shows date and time.

  •  clear
    – Clear as the name suggests will clear the terminal screen.

The following commands can only be used by root users or by using sudo.

  • init 0
    – init 0 is used to shut down the machine.
  • init 6
    init 6 is used to shut down the machine.
  • fdisk -l
    – fdisk -l shows the current hard disks size and partitions. It gives a detailed view of your hard disk.
  • /etc/init.d/dhcpd start/stop/restart (/etc/init.d/’service name’ ‘start/stop/restart’)
    This command is used to start or stop or restart any service.

Leave a Reply