Linux Commands

Linux Commands

What is Linux and why it's used?

Linux is an open-source operating system (OS). An operating system is the software that directly manages a system's hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and makes the connections between all of your software and the physical resources that do the work.

There are some commands.

How to create Users in Linux

adduser

How to set up the password in Linux

passwd

Print information about users

who

Check the Hostname on the Computer.

hostname

Display Login name

whoami

Current path chack

pwd

Difference between "Relative and Absolute path"

  • Relative path -- start from the current work directory.

  • Absolute path -- The full path to a file or directory.

How can we cope with raw data from one source to another?

dd

How to download the File in Linux?

wget

How to Unzip the file?

tax -xvzf

How to Display List in Linux?

ls

Create a file in Linux

touch, vi, vim, nano

Edit an existing file.

vi, vim, nano

Rename a file

mv "filename" "new filename"

Search for a string in a file.

grap "search name" "file name"

Search for multiple strings at one time

egrap "key1!|key2|key3"

Read a file without using the "cat command"

less, more, nano

Advantages of using less command

  • we can easily read big files.

  • forward and backward search is easy.

  • Navigation from top to bottom is easy.

Check a file permission

LL=ll

ls -l

getfacl file_name "if we want to check only one file permission"

Check IP address

  • ifconfig

  • ip addr

check the top 5 lines in a file

head -5 file name

check the last 5 line

tail -5 file_name

How to list the hidden file

ls -la

Recently used command

history

what is the Root user

  • Admin or superuser

  • /root home directory for root user

  • /root directory

which command can you use for finding files on a Linux system?

find

locate

Counting words and lines.

  • wc

  • wc -l

How to combine two commands?

we can use "|" = Bar

com1|cam2

check the difference between the two files

diff file1 file2

Use of the "shred" command

Permanently delete a file which is unable to recover.

  • shred -u file_name

  • shred --remove file_name

Check system architecture info.

  • lscpu

  • dmidecode

How to combine two file

cat file1 file2

Find the type of file

file -i "file name"

How to sort the content of a file

sort file_name

sort file_name | sort (use it in Alfabatucal)

Different ways to access a Linux server remotely from a

  • putty

  • gitbash

  • cmd

    [use-- ssh -i "key_name""user_name""public_IP"]

File permissions

Give the Different types of permissions for a file in Linux.

chmod -x/+x (Executable)

chmod -r/+r (Read)

chmod -w/+w (Write)

(-) this is used to take out the permission of any Linux file.

(+) this is used to grant permission for any Linux file.

which permission allows a user to run an executable file(script)

  • Need Executable permission

  • ./file_name.sh /path/of/file_name

How to change the file owner or group?

chown

chown $USER "/path/for/you/want/access"

Redirection

How to write the o/p command into a file

command > file_name

Ex-

ls -l

ls -l >my_file

Check the file "cat my_file"

How to write something in a file without deleting the existing content

we can append the file using

>>

How to redirect an error of a command into a file?

  • To redirect an error we need to use

    2>

  • To redirect both error and output,

    2 > &1

Automation

How to Automate any task or script?

  • cronjobs

    For which we have a "crontab"

  • "at command"

How to check scheduled jobs

  • crontab -l

What is the meaning of this cronjob *****

  • minute (0-59) *

  • hour (0-23) **

  • day of the month (1-31) ***

  • month (1-12) ****

  • day of the week () *****

If your cronjob didn't work, How would you check?

  • check system time,

  • crontab entry,

  • check /var/log/messages

Service

How to check whether the service is Running or not?

  • systemctl status "service_name"

How to start or stop any service

  • systemctl start "service_name"

  • systemctl stop "service_name"

System Monitoring

How to check for free disk space?

df -h

How to check the directory's content for all lists of the size?

du -h

How to check the directory size?

du -s

Check the memory usage ?

free -h

Check the CPU usage.

top

Check CPU Utilization ?

sar -u

Process

What is a process

A process is a series of steps or actions that are taken to achieve a particular result or goal.

How to check the process I'D?

ps -C "process_name"

ps -ef | grap "process_name"

How to Terminate/stop the running process?

kill

kill -9 "kill -9 used for forcefully"

How to check whether an IP/service is accessible or not?

  • ping

  • telnet

Which command to use to get info about ports?

netstat -tln

How to check open ports on a Linux system?

  • netstat putan | grap port_no

  • ss -tulw

How to check network interfaces in Linux?

  • ifconfig

  • netstat -l

Differences between telnet and SSH?

  • ssh is secured and telnet is not a secure connection.

Which service should be running on the server to allow you to connect remotely?

  • ssh or sshd

What is an SSH connection?

  • SSH or secure shell is a network communication protocol that enables two computer devices to communicate and share data.

Why it's called a secure shell?

  • Because of communication, two computers share data over an insecure network.

  • Ex- Like the internet, log in to remote service

What is the default port for ssh?

  • 22 "is the default port"