Month: December 2021

Create a file in Linux

Last Updated on December 7, 2021 by sandeeppote

Create a file with touch command

To create a new file, use touch command followed by the name of the file-

This should create a empty file.

touch thirdfile.txt

To create multiple files using touch command-

touch thirdfile-1.txt thirdfile-2.txt

Create a file with cat command

To create a new file with cat command use redirection operator followd by file name.

This will allow to add content to the file

cat > fourthfile.txt

Cratea a file using echo command

To create a new file using echo command use redirection operator followed by file name will create empty file or add content before redirection operator to add content while creating a file.

echo "This is fifth file." > fifthfile.txt

Create a empty file with echo command

echo > sixthfile.txt

Ubuntu – Package Management

Last Updated on December 6, 2021 by sandeeppote

DPKG – Debian Package Manager used to install, uninstall, list and check the status of the package

It comes with .deb file.

DPKG does not honour dependecies hence we need to use APT for Ubuntu

APT stands for Advanced Packaging Tool and relies on DPKG

Use apt update command to refresh the repository-

sudo apt update

Use apt upgrade to upgrade exisitng package-

sudo apt upgrade

To install a package-

sudo apt install <package name>

To uninstall or remove package-

sudo apt remove <package name>

To search package e.g:- python-dev

sudo apt search python-dev

To list all the packages in repository-

sudo apt list

Linux File Types

Last Updated on December 5, 2021 by sandeeppote

Everything in Linux is file

There are following type of files-

Regular files – Images/scripts/configuration and Data files

Directory – Type of files which saves other files and directories

Special files – have other types

  • Character Files – Represent devices – like Mouse and keyboards
  • Block Files – Represent block devices that writes data in chunk to the devices like HDD and RAM
  • Links – Hard links and Soft Links
  • Socket Files – enables the commnuication between 2 process
  • Named Pipes – passes data from one process to another

Use file command to get the file type-

file <<filename>>

Use ls -ld command to get the file type-

ls -ld firstfile.txt

First character represents the file type

IdentifierFile Type
dDirectory
Regular File
cCharacter Device
lLin
sSocket File
pPipe
bBlock Device

Filesystem Hierarchy

/- Root Partition

/opt – any third party program should be put in this directory

/mnt- mounts the file system from external network temporary to this folder

/tmp- copy any temporary files to this location

/media – copy any media files in this folder

/dev – contains the file character device file like external devices like mouse and keyboard

/bin – basic programs and binaries are located in this directory

/etc – configuration files

/lib and /lib64 – contains shared libraries

/usr – user related data reside in this folder

/var – system writes data such as logs

Linux Runlevels

Last Updated on December 5, 2021 by sandeeppote

A runlevel is a categorization number that determines what services are started and
what services are stopped

Runlevel #NameDescription
0HaltAll services are shut down and the server is stopped
1Single User ModeThe root account is automatically logged in to the server and other users cannot log in to the server
2Multiuser ModeUsers can log in to the server through CLI and network service are not started
3Extended Multiuser ModeUsers can log in to the server through CLI and network service are started
4User DefinedUser can cusomize the runlevel
5Graphical ModeUser can log in through CLI and GUI with network services started
6RebootThe server is rebooted

Check the current runlevel use following command-

runlevel

To see the default target

systemctl get-default

To change the default target use following command

systemctl set-default multi-user.target

Commands to understand Linux kernel and hardware

Last Updated on May 14, 2022 by sandeeppote

Understand the OS versoin and Linux machine hardware

Use uname command to display information of kernel

uname

For more information of kernel use-

uname -r

5 is Kernel Version

11 is Major Version

0 is Minor Version

1022 is patch release

azure is specific info

To understand CPU of machine use lscpu command

lscpu

In this case Architecture is x86_64 with CPU socket 1 and threads that run in parallel is 4.

To understand physical disk use lsblk command

lsblk

sda shows block devices of type disk

Use lsmem command to get the memory of the Linux machine

lsmem

Use free -m command to get the free memory i.e. total vs used memory

free -m

Append the command with sudo to run the command as super user