Linux Questions and Answers

 

Explain Unix and Linux

UNIX – It originally began as a propriety operating system from Bell Laboratories, which later spawned into different commercial versions.

Linux – It is free, open source, and intended as a non-propriety operating system for the masses. It’s an operating system based on UNIX and was first introduced by Linus Torvalds.

 

Explain Kernel, Shell, and Bash in Linux

Kernel – The Linux Kernel is a low-level systems software whose main role is to manage hardware resources for the user. It is also used to provide an interface for user-level interaction.

Shell – It is the utility that processes user’s requests. When we type in a command at our terminal, the shell interprets the command and calls the program that we want. Various types of shells which are available with most Unix variants are BASH, C Shell, Bourne Shell and Korn Shell.

echo $SHELL — command to find out which shell is being used.

BASH — BASH is short for Bourne Again SHell. It was written by Steve Bourne as a replacement to the original Bourne Shell (represented by /bin/sh). It combines all the features from the original version of Bourne Shell, plus additional functions to make it easier and more convenient to use. It has since been adapted as the default shell for most systems running Linux.

 

what are bin, sbin, lib, opt, and var in Linux

bin folder of Linux – The /bin directory contains binaries for use by all users. The ‘/bin’ directory also contains executable files, Linux commands that are used in single-user mode, and common commands that are used by all the users, like a cat, cp, cd, ls, etc. According to the FHS, the /bin directory should contain /bin/cat and /bin/date (among others). The ‘/bin’ directory doesn’t contain directories.

sbin folder of Linux – The /sbin contains binaries to configure the operating system. The ‘/sbin’ directory also contains executable files, but unlike ‘/bin’ it only contains system binaries that require root privilege to perform certain tasks and are helpful for system maintenance purposes. e.g. fsck, root, init, ifconfig, etc. Many of the system binaries require root privilege to perform certain tasks.

lib folder of Linux – The ‘/lib’ directory contains shared libraries which are often used by the ‘/bin’ and ‘/sbin’ directories. It also contains kernel module. These filenames are identable as ld* or lib*.so.*.

opt folder of Linux – The term ‘opt’ is short for optional. Its main purpose is to store optional application software packages. In many cases this is software from outside the distribution repository. Add-on applications from individual vendors should be installed in ‘/opt’. In some systems ‘/opt’ is empty as they may not have any add-on application. A large package can install all its files in /bin, /lib, /etc subdirectories within /opt/$packagename/. If for example the package is called wp, then it installs in /opt/wp, putting binaries in /opt/wp/bin and man pages in /opt/wp/man.

var folder of Linux – var is a standard subdirectory of the root directory in Linux and other Unix-like operating systems that contains files to which the system writes data during the course of its operation./var is specific for each computer; that is, it is not shared over a network with other computers. /var/lib (contains dynamic data libraries and files)

 

What is the proc file system in Linux?

Proc file system (procfs) is a virtual file system created on the fly when the system boots and is dissolved at the time of system shutdown.

It contains useful information about the processes that are currently running, it is regarded as a control and information center for the kernel.

The proc folder contains some familiar-sounding files, and then a whole bunch of numbered directories. The numbered directories represent processes, better known as PIDs, and within them, a command occupies them. The files contain system information such as memory (meminfo), CPU information (cpuinfo), and available filesystems.

 

What is an inode?

Linux must allocate an index node (inode) for every file and directory in the filesystem. Inodes do not store actual data. Instead, they store the metadata where you can find the storage blocks of each file’s data.

Inodes are a part of the Linux filesystem that store metadata for files, including location, size, permissions, read and write

 

Explain the “who” command in Linux

who — by this command, we can see the user name and their ip addresses who have logged in to server.

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-23.png

 

whoami — this command shows the current logged-in terminal user name

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-24.png

 

who am i (with spaces)

This command shows you the logged-in terminal number and username and more detailed information.

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-25.png

 

date: displays the current date

date +”%D %H:%M:%S”

Options:

d – The da of the month (1-31)

y – The last two digits of the year

H,M,S – Hour Minute and second respectively

D – the date in mm/dd/yy

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-26.png

 

Explain usage of “cal” Command in Linux

This cal command is used to see the calendar for any specific month or a complete year

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-27.png

 

Explain the usage of “top” Command in Linux

The top command displays CPU processes in a full-screen GUI. A great way to see the activity on your computer in real-time. Type “q” to quit

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-28.png

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-29.png

 

Explain the usage of “uptime” Command in Linux

The Uptime command in Linux shows an online summary of the system status

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-30.png

 

history command in Linux

It’s a very useful command which lists previously executed commands

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-31.png

 

Info command

Use the “Infor” command to list the various commands and their documentation.

 

man: show online documentation by program name

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-32.png

Once the manual of a command is opened, you can Type “q” to quit

 

which Command

This command shows the full path of shell commands found in your path. For example, if you want to know exactly where the “grep” command is located on the filesystem, you can type:

“which grep”. The output should be something like this:

/bin/grep

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-33.png

 

where is command

It Locates the program, source code, and manual page for a command (if at all information is available).

For example, to find out where “ls” and its man page are, type: “whereis ls” The output will look something like: ls: /bin/ls /usr/share/man/man1/ls.1.gz

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-34.png

 

locate command

A quick way to search for files anywhere on the filesystem. For example, you can find all files and directories that contain the name “mozilla” by typing locate mozilla

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-35.png

 

touch command

The touch command is the easiest way to create new, empty files also to update timestamps.

touch file1 file2 file3

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-36.png

 

cat command

cat command allows viewing the content of file. “cat” commands can be also used to concatenate files and redirect output in a terminal or files.

cat abc (where abc is filename)

cat abc any_filename

cat abc any_filename > new_file

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-37.png

 

cp command

This command is used to copy files

cp abc1.txt abc2.txt ( It will copy content of a file abc1.txt to abc2.txt)

cp abc1.txt /home/techie/work/ ( This command will copy abc1.txt file inside work folder)

 

ls command – list files in a directory and their attributes

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-38.png

 

mv – Move command is used to change the file name and to move content to a different directory location

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-39.png

 

rm – This command is used to remove files

rm filename (removes file)

rm -rf filename (forcefully removes files)

rm -rf * (forcefully removes entire files in the present directory)

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-40.png

 

ln – This command creates a link (name) to the file

There are two types of links :

Symlink Link and Hard Link : Both are pointers to files; the difference is the kind of pointer.

A hardlink can only work on the same filesystem, it is simply a different name for the same inode (files are internally referenced by inodes). Hardlinks usually only work for files, not directories.

ln filename.txt abc.link here abc.link is the hard link to the file “filename.txt”

A symlink (symbolic link) is a special file containing a path to another file. This path can be absolute or relative. symlinks can work across file systems, and can even point to different files, if you for example unplug an external hard drive and replace it with another one, which has a different file at the same path. A symlink can point to either files or directories.

ln -s filename.txt abc.symlink

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-41.png

 

chmod – (change file permissions)

The chmod command is used to change access permissions to files and directories.

The format is chmod permissions filename

chmod 755 file.txt

 

ls command

To see what permissions a file or directory has in Linux, you use the ls command with option -l (eg: ls -l) which gives a long format listing.

techiematerials@rishu-linux:~/test$ ls -l

-rw-rw-r– 2 techiematerials techiematerials 0 Apr 17 11:40 abc.link

lrwxrwxrwx 1 techiematerials techiematerials 12 Apr 17 11:41 abc.symlink -> filename.txt

-rw-rw-r– 2 techiematerials techiematerials 0 Apr 17 11:40 filename.txt

The permissions are the first 10 characters of the line (-rwxrwx—) and can be broken down as follows.

rwx

(4+2+1)

r—

(4+2+1)

r—

(4+2+1)

1 root root 765 Apr 23 file.txt
File type Owner Group All Links Owner Group Size Mod date Filename

The r,w and x stand for…

  • r = read
  • w = write
  • x = execute

The first character on the line shows what type of file or directory it is, and can be one of these things…

  • = file
  • d = directory
  • l = symbolic link
  • b = block-type special file
  • c = character-type special file
  • p = named pipe
  • S = socket
  • s = XENIX semaphore
  • m = XENIX shared data (memory) file
  • D = Solaris door
  • n = HP-UX network special file

The remaining 9 characters are broken down into 3 groups of 3 characters. The first three are the permissions for the owner, the middle three are permissions for the group which has access to the file and the last three are the permissions for everybody else.

 

Usage of the “find” command in Linux

find –  A very powerful command, but sometimes tricky to use. It can be used to search for files matching certain patterns, as well as many other types of searches.

Few examples are :

    • find . -name \*mp3

This example starts searching in the current directory “.” and all subdirectories, looking for files with “mp3” at the end of their names.

    • The find command is used to list files within a particular time duration.

find /var/tmp -mtime +2 -a -mtime -8 -ls

    • The Find command to list files of particular size

find . -size 6M

find . -newer – to list newer files

    • find . -type f -name “*.txt”  to find files with “.txt” at the end of their names
    • find /jenkins/jobs/ -type f -name “config.xml” -exec cp –parent -rf {} ~/jobs_backup \;

this command will copy entire config.xml file from location “/jenkins/jobs” to ~/jobs_backup location.

 

Write a command that will look for files with an extension “c”, and has the occurrence of the string “apple” in it.

find . -name “*.c” | xargs grep –i “apple”

 

Write a command that will do the following:
-look for all files in the current and subsequent directories with an extension c,v
-strip the v from the result (you can use sed command)
-use the result and use a grep command to search for all occurrences of the word ORANGE in the files.

find ./ -name “*.c,v” | sed ‘s/,v//g’ | xargs grep “ORANGE”

 

foreach command

The foreach command implements a loop where the loop variable(s) take on values from one or more lists.

icd2s {integ} foreach i (`cat /home/integ/sanjay/abc`)

foreach? echo $i

foreach? /grid/common/bin/rsync -azv –progress  –rsync-path=/grid/common/bin/rsync inet03:/icd/ckits/$i/ /icd/ckits/$i/

foreach? end

 

diff — Command to find the difference between two files

$ diff filename1 filename2 (It compares two files for differences )

$vimdiff filename1 filename2 “OR” sdiff filename1 filename2

It will display the two files side by side

 

head command in Linux

This command display content of files.  It shows the first few lines of a file (ex:   head -5 filename)

 

tail command

This command also displays the content of files, but it shows last few lines of a file (ex:    tail -10 filename)

 

grep command

It displays lines that match the pattern (ex:   grep good filename)

 

file command – It examines files and tells you whether text, data, etc

https://www.techiematerials.com/wp-content/uploads/2017/04/word-image-42.png

 

more and less commands – are used to view large files one page at a time

less is the standard pager for Linux and in general less is more powerful than more.

 

Memory usage

cat /proc/cpuinfo – Displays information about your CPU.

cat /proc/meminfo – Display lots of information about current memory usage.

 

WC

wc [options] [file name] – command is used to count lines, words, and characters, depending on the option used.

$ wc sample1.txt

65 2776 17333 sample1.txt

This means the sample1.txt file has 65 lines, 2776 words, and 17333 characters

We can just print the number of lines, number of words, or number of characters by using the following options:

-l : Number of lines

-w : Number of words

-c : Number of characters

To find the number of content of the folder we can use command:  ls foldername |wc –l

 

cmp command is used to compare two files whether they are identical or not

 

useradd – Use this command to create a new user

[root@techie root]# useradd username

 

passwd – This command is used to give a password to a user

[root@techie root]# passwd rishu

 

userdel – This command is used to remove a user from Linux

[root@techie root]# userdel rishu

 

groupadd  to add a new group

[root@techie root]# groupadd groupname

 

groupdel  to delete a group

[root@techie root]#groupdel groupname

 

chown —to change the ownership of a file or directory

[root@techie root]# chown ownername filename

chown samuel abcd

 

chgrp to change the group ownership of a file or directory

[root@techie root]#chgrp newgroupownername filename

chgrp samuel abcd

 

PS Command

ps –u username – This command is used to displays the process of the specified user

ps –aux  — This command displays all processes including user and system process

$ps –aux |grep “user1” —  Displays all processes including user and system process and grep for the process running by the user – “user1”

ps -ef  Command that displays entire processes running in the system:

ps -ef | grep java   Command to list entire java process

 

LSOF

lsof: use lsof to see what application is listening on any port.

ex- use this cmd to check which app is listening on port 80:

sudo lsof -i TCP:80

 

DF

df   This command reports file system disk space usage

df -h .   This command list current disk space usage

 

du -sh

du -sh abc.txt – This command displays abc.txt file size

du   This command shows disk usage in a directory.

du -s This command provides a summary for the current directory.

 

free

This command displays the amount of free and used memory in the system.

free -g

 

uname -a

This command prints system information to the screen (kernel version, machine type, etc.)

 

Command to control program execution in Shell

  • &              — run job in the foreground
  • DEL,^c   — kill job in foreground
  • ^z            — suspend job in foreground
  • fg             — restart suspended job in foreground
  • bg            — run suspended job in background
  • ;               — delimit command on same line
  • ()             — group command on same line
  • !               — re-run earlier command from history list
  • nice         — run program at lower priority
  • at             — run program at later time
  • ps             — Lists currently running process (programs).

 

Explain “crontab” in linux

The crontab command submits, edits, lists, or removes cron jobs. A cron job is a command run by the cron daemon at regularly scheduled intervals

export EDITOR=vi; to specify an editor to open the crontab file.

  • crontab -e    Edit your crontab file or create one if it doesn’t already exist.
  • crontab -l      Display your crontab file.
  • crontab -r      Remove your crontab file.

Crontab file syntax:

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

https://www.techiematerials.com/wp-content/uploads/2017/04/crontab.jpg

Notes :

A. ) Repeat patterns like /2 for every 2 minutes or /10 for every 10 minutes are not supported by all operating systems. If you try to use it and crontab complain it is probably not supported.

B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed.

Crontab Example

A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

30     18     *     *     *         rm /home/someuser/tmp/*

Changing the parameter values as below will cause this command to run at different time schedule below :

min hour day/month month day/week Execution time
30 0 1 1,6,12 * – 00:30 Hrs  on 1st of Jan, June & Dec.
0 20 * 10 1-5 –8.00 PM every weekday (Mon-Fri) only in Oct.
0 0 1,10,15 * * – midnight on 1st ,10th & 15th of month
5,10 0 10 * 1 – At 12.05,12.10 every Monday & on 10th of every month

Disable Email from crontab:
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

/dev/null 2>&1

 

 

telnet – This command enables remote network login to another computer

 

ftp – This command enables the network file transfer program

 

rlogin – remote login to a trusted computer

 

rsh – execute a single command on a remote trusted computer

rcp remote file copy from / to “trusted “ computer

ifconfig  – It shows the IP address of the linux box

syntax:$ ifconfig

netstat – netstat command is used to check the connectivity of the network.

netstat –rn

Network statistics ( netstat ) is a networking tool used for troubleshooting and configuration, that can also serve as a monitoring tool for connections over the network. Both incoming and outgoing connections, routing tables, port listening, and usage statistics are common uses for this command.

 

What is the use of vmstat command?

Virtual memory statistics reporter, also known as vmstat , is a Linux command-line tool that reports various bits of system information. Things like memory, paging, processes, IO, CPU, and disk scheduling are all included in the array of information provided

 

What is swap memory in Linux?

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM.

 

What is the load average in Linux?

The load average is the average system load on a Linux server for a defined period of time. In other words, it is the CPU demand of a server that includes sum of the running and the waiting threads.

Typically, the top or the uptime command will provide the load average of your server with output that looks like:


These numbers are the averages of the system load over a period of one, five, and 15 minutes.

 

What is systemd in linux?

systemd is a Linux initialization system and service manager that includes features like on-demand starting of daemons, mount and automount point maintenance, snapshot support, and processes tracking using Linux control groups. systemd provides a logging daemon and other tools and utilities to help with common system administration tasks.

systemd is the default init system for the major Linux distributions

 

gzip – command is used to compress the file, and gunzip is used to decompress it.

usage: gzip <file name>

It provides the extension .gz and removes the original file. The compression ratio depends on the type, size and nature of the file.

 

gunzip <file name with.gz>  – This command decompress a file

gunzip sample_copy.txt.gz

If you want to compress the directory contents recursively, use -r option with gzip command

 

tar command is used to create an archive that contains a group or file or entire directory structure.

It is generally used for back ups.

usage: tar [options] <output file.tar> <file1 or dir> . . .

The following are the options:

  • -c Create an archive
  • -x Extract files from archive
  • -t Display files in archive
  • -f arch Name the archive arch

Cmd:-

$ tar -cvf compression.tar compression

$ gzip compression.tar

$ //will create compression.tar.gz file

>> For un-compression the file first use gunzip command, which will create a tar file and then use tar command to untar the contents

$ gunzip compression.tar.gz

$ tar -xvf compression.tar

To just view the contents of the tar file use -t option

$ tar -tvf compression.tar

>> Instead of doing tar first and then gzip next, we can combine both using the option -z

tar -cvzf compression.tar.gz compression

>> We can de-compress .tar.gz again in a single command using the option -z with -x

tar -xvzf compression.tar.gz

 

zip – command can be used for archiving as well as compressing the contents of the directory or the file

usage: zip [options] output.zip <files to be zipped or directory>

$ zip sample1.zip sample1.txt

Use -r option to recursively zip the contents of the directory

$ zip -r compression.zip compression

// will create compression.zip file

>> To un-compress the file use unzip command

unzip compression.zip

// will un-compress the compression.zip file

 

Controlling program input/output for c-shell

  • |             – pipe output to input
  • >            – redirect output to a storage file
  • <            – redirect input from a storage file
  • >>         – append redirected output to storage file
  • script    – make file record of all terminal activity
  • tee         – Sends the output in two directions at a time

Syntax: tee [options ] filename.

Ex : $ls –l |tee file2

It will list all the files in the current directory and as well store in the file called file2.

$ls –l |tee –a file2

It will append the list to file2.

 

NMAP

nmap –  Nmap short form of Network Mapper is an open-source tool for exploring networks, performing security scans, network audits, and finding open ports on remote machines.

Use the below command to install Nmap :

# yum install nmap                                                  [on Red Hat based systems]
$ sudo apt-get install nmap                                   [on Debian based systems]

 

nmap command to find all ports being used in a machine/server :

sudo nmap -sT -O localhost

 

 

sed   – This command works by sequentially reading a file into memory and then performing the specified action. It is used for substitution.

sed ‘s/hi/hello/’ filename – This will display the file called filename after the substitution.

sed -i ‘s/hello/hi/’ filename – This command will do substitution(insert) in the file “filename”.

sed ‘s/hi/hello/g’ filename – This command will make Global replacement .. i.e if it will replace all the “hi” to “hello” ( Without “g” option it will just replace first “hi” of a line to “hello”)

“e” is used for multiple Substitutions

sed -e ‘s/hi/hello/g’ -e ‘s/fine/good/g’ filename

Eg-1. How to remove the headers from a file using the command in Linux?

sed ‘1 d’ file.txt

The only problem with the above command is that it outputs the file on standard output without the first line. In order to save the output to a file, we need to use the redirect operator which will redirect the output to a file.

sed ‘1 d’ file.txt > new_file.txt

Well, the built-in switch ‘-i‘ for the sed command, can perform this operation without a redirect operator.

sed -i ‘1 d’ file.txt

Eg-2. How will you check the length of a line from a text file?

A ‘sed –n ‘n p’ file.txt‘, where ‘n‘ represents the line number and ‘p‘ print out the pattern space (to the standard output). This command is usually only used in conjunction with the -n command-line option. So, how to get the length count? Obviously! we need to pipeline the output with ‘wc‘ command.

# sed –n ‘n p’ file.txt | wc –c

To get the length of line number ‘5’ in the text file ‘tecmint.txt‘, we need to run.

# sed -n ‘5 p’ tecmint.txt | wc -c

Eg-3. Given a file, replace all occurrence of the word “ABC” with “DEF” from 5th line till end in only those lines that contains word “MNO”

sed –n ‘5,$p’ file1|sed ‘/MNO/s/ABC/DEF/’

Eg-4. Print the 10th line without using tail and head command.

sed –n ‘10p’ file1

Eg-5. How do we delete all blank lines in a file?

sed ‘^ [(backslash)011(backslash)040]*$/d’ file1

where (backslash)011 is octal equivalent of space and

(backslash)040 is octal equivalent of tab

Eg-6. How will I insert a line “ABCDEF” at every 100th line of a file?

sed ‘100i\ABCDEF’ file1

 

 

Explain awk in Linux

AWK  is a programming language. You can write awk scripts for complex operations or you can use awk from the command line. Just as sed, awk reads one line at a time, performs some action depending on the condition you give it and outputs the result.

Example : $ ls -ltr | awk ‘ {print $9} ‘

The action to be performed by awk is enclosed in braces, and the whole command is quoted.

The syntax is : awk ‘ condition { action }’

 

nohup command

when using the command shell, if we prefix nohup, it prevents the command from being aborted even if we log out or exit the shell. nohup stands for “no hangup”.

syntax :

nohup commands-to-be-executed &

Example :

nohup sh customScript.sh &

nohup /path/to/script/CustomScript.pl arg1 arg2 &

The “&” symbol at the end runs commands in the background, returning us to the command prompt while it is running.

It is good to use nohup in conjunction with & if we want to continue running other commands.

 

Explain rsync command and its usage

Rsync stands for “remote sync”. It is a tool by which we can sync data (files/folders) locally as well as remotely. With the help of the rsync command, you can copy and sync data’s across directories, disks, and networks and can perform data backups between two Linux machines.

Syntax :

# rsync options source destination

Some options used with the rsync command:

-v : verbose

-r : copies data recursively (but it doesn’t preserve timestamps and permission while transferring data)

-a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps

-z : compress file data

-h : human-readable, output numbers in a human-readable format

 

To install rsync :

# yum install rsync (On Red Hat based systems)

# apt-get install rsync (On Debian based systems)

Example 1. : Sync two directories in a local server

rsync -zvr /var/www/html/techie/ /root/temp

Example 2. Synchronize Only One File

rsync -v /var/www/html/techie/conf.txt /root/temp/

 

Example 3. Synchronize Files From Local to Remote

rsync -avz /var/www/html/techie/ adminuser@192.157.100.14:/home/temp/techie/

(You will asked to enter password of remote server)

Example 4. Synchronize Files From Remote to Local

rsync -avz adminuser@192.157.100.14:/var/www/html/techiem/ /root/temp

(You will asked to enter password of remote server)

 

What is mounting

The mount command attaches the filesystem of an external device to the filesystem of a system. It instructs the operating system that filesystem is ready to use and associate it with a particular point in the system’s hierarchy. Mounting will make files, directories and devices available to the users.

How to mount

Mounting is done with the mount command. When mounting, you must tell the mount command what device or partition is you want to mount and what is the mount point. The mount point must be a directory that already exists on your system. For example, to mount your floppy:
$ mount /dev/fd0 /mnt/floppy

How to unmount

Unmounting is done with the umount command. No, I didn’t make a typo: the command really is umount, not unmount. When unmounting, you’ll need to tell umount what mounted device to unmount, either by telling what’s the device or the mount point. For example, if /dev/fd0 is mounted to /mnt/floppy, you’ll unmount it with
$ umount /mnt/floppy
or
$ umount /dev/fd0It’s not wise to remove the floppy from the floppy drive without unmounting it first! In the worst case the data you were writing to the floppy wasn’t written into it yet. With CD-ROMs you can’t do this: the tray won’t even open if you haven’t unmounted the CD first.

 

How to Create Permanent aliases

To define a permanent alias we must add it in ~/.bashrc file.

vi ~/.bashrc

alias k=kubectl

All created aliases will work the next time we log in via ssh or open a new terminal. To apply aliases immediately we can use the following command:

source ~/.bash_aliases

 

IOSTAT command in Linux

The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates.

The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks

1) Get report and statistic : iostat

The first section of iostat output contains CPU report

The second section of iostat command output, contains device utilization report

iostat uses the files below to create reports.

  • //proc/stat contains system statistics.
  • /proc/uptime contains system uptime.
  • /proc/diskstats contains disks statistics.
  • /sys contains statistics for block devices.
  • /proc/self/mountstats contains statistics for network filesystems.
  • /dev/disk contains persistent device names.
2) iostat command that show more details statistics information iostat -x
3) iostat command that show only the cpu statistic : iostat -c
4) Display only the device report : iostat -d
5) Show extended I/O statistic for device only : iostat -xd
6) Capture the statistics in kilobytes or megabytes : iostat -k
7) Display cpu and device statistics with delay : iostat -k 2 3

 

 

What is the use of the cut command in Linux?

A ‘cut’ is a very useful Linux command which proves to be helpful when we need to cut a certain specific part of a file and print it on standard output, for better manipulation when the field of the file and file itself is too heavy.

For example, extract the first 10 columns of a text file ‘txt_tecmint‘.

# cut -c1-10 txt_tecmint

To extract the 2nd, 5th, and 7th columns of the same text file.

# cut -d;-f2 -f5 -f7 txt_tecmint

cut -d “:” -f 1

 

List default ports used by various processes.

Port No. Name Comment
21 ftp File Transfer Protocol (FTP) port; sometimes used by File Service Protocol (FSP)
22 ssh Secure Shell (SSH) service
23 telnet The Telnet service
25 smtp Simple Mail Transfer Protocol (SMTP)
80 http HyperText Transfer Protocol (HTTP) for World Wide Web (WWW) services
115 sftp Simple File Transfer Protocol services
143 imap Internet Message Access Protocol (IMAP)
161 snmp Simple Network Management Protocol (SNMP)
389 ldap Lightweight Directory Access Protocol (LDAP)
443 https Secure Hypertext Transfer Protocol (HTTP)
636 ldaps Lightweight Directory Access Protocol over Secure Sockets Layer (LDAPS)
873 rsync rsync file transfer services
992 telnets Telnet over Secure Sockets Layer (TelnetS)
3306 mysql MySQL database service
33434 traceroute Traceroute network tracking tool

 

Leave a Reply

Your email address will not be published. Required fields are marked *