12/180: Basics of Linux

Navneet Ojha
5 min readMar 30, 2021

--

Today is day 12 of my 180 days challenge, proudly heading ahead. Currently feeling sleep but then I have to remind my self that I have to make learning as a ritual to be performed daily and writing blog for that. Writing the blog helps me revise all things I learned in a day. So I find writing more useful.

We are going to discuss the basics of Linux Operating System. I have been using ubuntu from quite long so all my writing will be based on that experience.

If you want to download Ubuntu, you can do it from the below link

Download Ubuntu Desktop | Download | Ubuntu

For installing it, you can make the ISO file bootable using some software, and make sure the bootable file is in some pen drive, so it is easy to install via pendrive, insert the bootable pendrive and press the Boot key in my case it F2, you will get the option to install and the go ahead step by step.

My main purpose of todays blog is to discuss the day to day commands which are required if you are all time linux use.

Let’s with very basic commands:

ls -> listing file

ls -ltr -> is for listing files in timely order and the recently created files will be at the last.

cp -> copy file cppath of the file” “ path where you want the copy of it

mv -> move file mvpath of the file” “ path where you want to move it

In move file, the copy from the original directly gets removed and placed to the other directory path.

Finding files and Directories

Lets say if you are not aware of where your files can be you can use below commands

find and locate

find .-name “filename which you want to find” (“.” refers to the current directory)

find /-name “filename which you want to find” (“.” refers to the root directory)

What is the basic difference between find and locate?

Locate was a prebuilt database which should be regularly updated. Find iterates over file system

Locate sometime not provide the correct data because the database is not updated so you can run updatedb command before using locate.

How to change password in Ubuntu

If you are acting as root then you need to add command and the username with it.

passwd username

If you are the user, you can directly use the command passwd, then it will ask for old password, new password and retype new password.

After filling all the correct values your password will be changed.

Directory Listing attributes

when you type ls -l command, you get the list of files

It displays Type, Link, Owner, Group, Size, Month, Day, Time and at the last is file name, let’s discuss one by one everything in the columns we have

Type: drwxr-xr-x (By d means its a directory, r (read), w(write), x(execute), -(no permission))

Owner: it refers to who is owner of the file just like that group, to which group the file belongs.

Creating files and directories

  1. touch (touch filename)
  2. cp (copy file to directory)
  3. vi (vi filename, file will get opened to close you need to type ESC:wq!)
  4. mkdir (for creating directory, mkdir filename)

Linux File Types

  1. - Regular files
  2. d Directory
  3. l link
  4. c Speacial file or device (like if keyboard is attached it will be display in the list with c)
  5. s Socket
  6. p Name pipe
  7. b Block Device

Wild Cards

A character that can be used as a substitute for any of a class of characters in search

  1. * represents zero or more characters
  2. ? represents a single character
  3. [] represents a range of character

Let’s say if we want to list the files who starting characters are Abc , then we can do ls -l Abc*, it will display all the files having Abc as prefix

Hard and Soft Links

Let’s first understand what is Inode?, It is a pointer or number given to a file on hard disk.

Soft Links (ln -s): Link will be removed if source file is removed or renamed. The soft link is pointing to the actual file and the actual file is pointing to the inode.

Hard Links (ln): Deleting or removing the original file will not affect the linked file, because it is directly linked to inode so it maintains a pointer in the hard disk.

File Permissions

We can change file permissions using chmod command

now as we know r(4) is for read, w(2) is for write and x(1) is for execute. So we can change permissions like this chmod r+x filename , r+x means read and execute permissions, we can also define wheather we want to give permission to owner group or others, if we want to give permission to group we can use chmod g-w filename, here we are removing write access from group.

File Ownership

chown -> changes ownership of file

chgrp -> changes group ownership of file

Help commands

There are few help commands which you can use if you are stuck somewhere

  1. whatis commandName (whatis ls, will show you the meaning of ls command)
  2. commandName — help (ls — help, will show you the options you can use with ls)
  3. man commandName (man ls, it will display the manual for ls command)

Pipes

Pipes | , we use it when we need to connect output of one command to other command for example: if we do simply ls -ltr, it will display long list but I want to see all the list step by step, so I can pipe my list output with more, so it will display page by page like this ls -ltr | more

File Display Commands

  1. Cat (to see text inside files)
  2. more (to display more content of file)
  3. less
  4. head (to display top lines of files)
  5. tail (to display last lines of file)

This is all for today, tomorrow I am going to post the topic of memcached.

--

--

Navneet Ojha
Navneet Ojha

Written by Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

No responses yet