Linux Basic Commands

Written in

by

Basic commands

cd

mkdir

cp

cp – R

cat

touch

mv

whoami

id – to find the id of the user

su

ssh username@ip

sudo /ls/root – to perform root level tasks

wget & curl  url -O somfile.txt – to save the file

cat /etc/*release* – to find the release version

vi Editor

  1. Command Mode
  2. Insert Mode

By default vi opens in command mode, to switch to insert mode  “i” to get back to command mode esc

Command Mode

x – to delete a character

dd – to delete a entire line

yy – to copy a line

p – to paste a line

: – to write a command

:w – to write the change

:q – Quit without saving

/ – to find

:wq – save changes and quit

n – to find next occurrence

Package managers

By default rpm (redhat package manager) is the package manager but it will no install the dependencies

rpm -q  – to query a package

rpm -I – to install a package

rpm -e – to remove a package

To install a package with dependencies use YUM Package manager

yum repolist                                                  – To find the available packages

ls /etc/yum.repos.d/                                    – To Find the available repos

cat /etc/yum-repos.d/Centos-Base.repo – To find the avaialble repo for cent-os

yum list packagename                                  – Find the installed package

yum remove packagename                         – To remove a package

yum list ansible –showduplicates              – To find the duplicate repository

DNS

/etc/hosts

/etc/resolv.conf

/etc/nsswitch.conf – Order of dns order is mentioned

Preference in always the local server, if not specified on the above file

Create a entry in /etc/resolv.conf with search entry to resolve the name without domain name (within organization)

A Record – Name to IP

AAAA Record (quad A record) – name to IPV6

Cname – alias record

 nslookup does not lookup local server

 dig – similar to nslookup

Services

The services can be started, stopped and status can be checked from the below commands

 service httpd start

       (or)

systemctl start httpd

systemctl  stop httpd

systemctl  status httpd

systemctl enable httpd  – to enable during startup

systemctl disable httpd – to disable during startup

How to create an app and start using ctl commands

  1. Create a file under /opt/code/my_app
  2. Update the contents of the file

 echo myworld

Test the script by running the below command

/usr/bin/python3 /opt/code/my_app

User the curl command to check whether the service is in listening state

curl http://localhost:5000

Navigate to “/etc/systemd/system” or “/lib/systemd/system” and create a file with the service name

myapp_service

Update the contents of the file as below

[unit]

Description of the app

[Service]

Mention the service start details and the dependency services and scripts that has to be started along with the app

[Install]

To start the service during boot, mention the service after which this service has to start

Once the file is configured then stystemctl commands can be used to start, stop and to check the application status.

Tags