Ans: ‘Kernal’ basically refers to that core component of the computer operating system that provides basic services for the other parts as well as interacts with user commands. When it comes to ‘Linux Kernal’, it is referred as low-level system software providing an interface for user-level interactions.
Linux Kernal is considered as free and open source software which is capable of managing hardware resources for the users. As it is released under General Public Licence (GPL), it becomes legal for anyone to edit it.
Que 2) Differentiate between LINUX and UNIX?
Ans: Although there are multiple differences between LINUX and UNIX, enlisted below table covers all the major differences.
LINUX | UNIX |
---|---|
LINUX is an open source software development and free operating system used for computer hardware & software, game development, PCs, etc. | UNIX is an operating system which is basically used in Intel, HP, internet servers, etc. |
LINUX has priced as well as freely distributed and downloaded versions. | Different versions/flavours of UNIX have different price structures. |
Users of this operating system could be anyone including home users, developers, etc. | This operating system was basically developed for mainframes, servers and workstations except for OSX which is designed such that it can be used by anyone. |
File support system includes Ext2, Ext3, Ext4, Jfs, Xfs, Btrfs, FAT, etc. | File support system includes jfs, gpfs, hfs, etc. |
BASH (Bourne Again Shell) is the Linux default shell i.e. text mode interface which supports multiple command interpreters. | Bourne shell serves as the text mode interface which is now compatible with many others including BASH. |
LINUX provides two GUIs, KDE and Gnome. | Common desktop environment was created which serves as a GUI for UNIX. |
Examples: Red Hat, Fedora, Ubuntu, Debian, etc. | Examples: Solaris, All Linux |
It provides higher security and has about 60-100 viruses listed till date. | It is also highly secured and has about 85-120 viruses listed till date. |
Ans: Linux operating system basically consists of 3 components which are enlisted below
- Kernel: This is considered as the core part and is responsible for all major activities of Linux operating system. Linux Kernel is considered as free and open source software which is capable of managing hardware resources for the users. It consists of various modules and interacts directly with the underlying hardware.
- System Library: Most of the functionalities of the operating system are implemented by System Libraries. These act as a special function using which application programs accesses Kernel’s features.
- System Utility: These programs are responsible for performing specialized, individual level tasks.
Ans: LINUX is used widely because it is completely different from other operating systems where every aspect comes with something extra i.e. some additional features. Some of the major reasons to use LINUX are listed below
- It is an open source operating system where programmers get the advantage of designing their own custom OS
- Software and the server licensing required to install Linux is completely free and can be installed on many computers as required
- It has low or minimum but controllable issues with viruses, malware, etc
- It is highly secured and supports multiple file systems
Ans: Following are some important features of LINUX operating system
- Linux kernel and application programs can be installed on any kind of hardware platform and thus is considered as portable.
- It serves the purpose of multitasking by serving various functions simultaneously.
- It provides the security services in three ways namely, Authentication, Authorization, and Encryption.
- It supports multiple users to access the same system resource but by using different terminals for operation.
- Linux provides hierarchical file system and its code is freely available to all.
- It has its own application support (to download and install applications) and customized keyboards.
- Linux distros provide live CD/USB to their users for installation.
Ans: LILO (Linux Loader) is the boot loader for Linux operating system to load it into the main memory so that it can begin its operations. Bootloader here is a small program that manages a dual boot. LILO resides in MBR (Master Boot Record).
Its major advantage is that it allows the fast bootup of Linux when installing in the MBR.
Its limitation lies in the fact that it is not possible for all computers to tolerate modification of MBR.
Que 7) What is Swap space?
Ans: Swap space is the amount of physical memory that is allocated for use by Linux to hold some concurrent running programs temporarily. This condition usually occurs when Ram does not have enough memory to support all concurrent running programs. This memory management involves the swapping of memory to and from physical storage.
There are different commands and tools available to manage the Swap space usage.
Que 8) What do you understand by Root account?
Ans: As the name suggests, it is like a system administrator account which gives you the ability to fully control the system. Root account serves as the default account whenever Linux is installed.Below mentioned functions can be performed by Root account
Below mentioned functions can be performed by Root account
- Create user accounts
- Maintain user accounts
- Assign different permissions to each account created and so on..
Ans: When there are multiple windows available on the current desktop and there appears the problem of minimizing and maximizing windows or restoring all the current programs, there ‘Virtual Desktop’ serves as an alternative. It allows you to open one or more programs on a clean slate. Virtual desktops are basically stored on a remote server and serve the following benefits:
Virtual desktops are basically stored on a remote server and serve the following benefits
- Cost savings as the resources can be shared and allocated as and when required.
- Resources and energy are more efficiently used.
- Data integrity is improved.
- Centralized administration
- Less compatibility issues.
Ans: GUI stands for the Graphical user interface. GUI is considered as the most attractive and user-friendly because it consists of the usage of images and icons. These images and icons are clicked and being manipulated by the users for the purpose of communication with the system.
Advantages of GUI:
- Allows users to navigate and operate the software with the help of visual elements.
- More intuitive and rich interface is possible to be created.
- Less chances of occurrence of errors as complex, multi-step, dependent tasks are easily grouped together.
- Productivity is enhanced with the means of multitasking as with a simple click of the mouse, the user is able to maintain multiple open applications and transitions between them.
- End-users have less control over the operating system and file systems.
- Although it is easier to use mouse and keyboard for navigation and controlling operating system, the whole process is a bit slow.
- It requires more resources because of the elements that need to be loaded such as icons, fonts, etc.
Ans: CLI stands for Command Line Interface. It is a way for humans to interact with computers and is also known as Command line user interface. It relies on textual request and response transaction process where user types declarative commands to instruct the computer to perform operations.
Advantages of CLI
- Very flexible
- Can easily access commands
- Much faster and easier to use by expert
- Does not use much CPU processing time.
- Learning and remembering type commands is hard.
- Have to be typed precisely.
- Can be very confusing.
- Surfing web, graphics, etc are few tasks which are hard or impossible to do on the command line.
Ans: Different parts of LINUX say kernel, system environment, graphical programs, etc are developed by different organizations. LINUX Distributions (Distros) assemble all these different parts of Linux and give us a compiled operating system to be installed and used.
There are around six hundred Linux distributors. Let us see some of the important ones
- UBuntu: It is a well known Linux Distribution with a lot of pre-installed apps and easy to use repositories libraries. It is very easy to use and works like MAC operating system.
- Linux Mint: It uses cinnamon and mate desktop. It works on windows and should be used by newcomers.
- Debian: It is the most stable, quicker and user-friendly Linux Distributors.
- Fedora: It is less stable but provides the latest version of the software. It has GNOME3 desktop environment by default.
- Red Hat Enterprise: It is to be used commercially and to be well tested before release. It usually provides the stable platform for a long time.
- Arch Linux: Every package is to be installed by you and is not suitable for the beginners.
Ans: It is always required to keep a check on the memory usage in order to find out whether the user is able to access the server or the resources are adequate. There are roughly 5 methods that determine the total memory used by the Linux.
This is explained as below
- Free command: This is the most simple and easy to use the command to check memory usage. For example: ‘$ free –m’, the option ‘m’ displays all the data in MBs.
- /proc/meminfo: The next way to determine the memory usage is to read /proc/meminfo file. For example: ‘$ cat /proc/meminfo’
- Vmstat: This command basically lays out the memory usage statistics. For example: ‘$ vmstat –s’
- Top command: This command determines the total memory usage as well as also monitors the RAM usage.
- Htop: This command also displays the memory usage along with other details.
Ans: Every file and directory in Linux are assigned three types of owners namely ‘User’, ‘Group’, and ‘Others’. Find the three kinds of permissions defined for all the three owners
- Read: This permission allows you to open and read the file as well as list the contents of the directory.
- Write: This permission allows you to modify the contents of the file as well as allows adding, removing and renaming files stored in the directories.
- Execute: User can access and run the file in the directory. You cannot run a file unless the execute permission is set.
Ans: The maximum length for any filename under Linux is 255 characters.
Que 17) How permissions are granted under LINUX?
Ans: A system administrator or the owner of the file can grant permissions using the ‘chmod’ command. Following symbols are used while writing permissions
- ‘+’ for adding permission
- ‘-‘ for denying permission
u : user; g: group; o: other; a: all; r: read; w: write; x: execute.
Que 18) What are the different modes when using the vi editor?
Ans: The 3 different kinds of modes in vi editor are enlisted below
- Command Mode/ Regular Mode
- Insertion Mode/ Edit Mode
- Ex Mode/ Replacement Mode
Ans: Enlisted below are the directory commands along with descriptions
- pwd: It is a built-in command which stands for ‘print working directory’. It displays the current working location, working path starting with / and directory of the user. Basically, it displays the full path to the directory you are currently in.
- Is: This command list out all the files in the directed folder.
- cd: This stands for ‘change directory’. This command is used to change to the directory you want to work from the present directory. We just need to type cd followed by the directory name to access that particular directory.
- mkdir: This command is used to create an entirely new directory.
- rmdir: This command is used to remove a directory from the system.
Ans: Difference between Cron and Anacron can be understood from the below table
Cron | Anacron |
---|---|
Cron allows the user to schedule tasks to be executed every minute. | Anacron allows the user to schedule tasks to be run either on a specific date or the first available cycle after the date. |
Tasks can be scheduled by any normal user and are basically used when tasks have to be completed/executed at a particular hour or minute. | Anacron can be used only by super users and is used when a task has to be executed irrespective of hour or minute. |
It is ideal for servers | It is ideal for desktops and laptops |
Cron expects the system to be running 24x7. | Anacron does not expects the system to be running 24x7. |
Ans: The work of Ctrl+Alt+Del key combination on Linux operating system is same as is for Windows i.e. to restart the system. The only difference is that there is no confirmation message displayed and a system is rebooted directly.
Que 22) What is the role of case sensitivity in affecting the way commands are used?
Ans: Linux is considered as cases sensitive. Case sensitivity can sometimes serve as the reason for displaying different answers for the same command as you might enter different format of commands each time. In terms of case sensitivity, the command is same but the only difference occurs with regard to uppercase and lowercase letters.
For example cd, CD, Cd are different commands with different outputs.
Que 23) Explain Linux Shell?
Ans: For executing any commands user uses a program known as the shell. Linux shell is basically a user interface used for executing the commands and communicating with Linux operating system. Shell does not use the kernel to execute certain programs, create files, etc. There are several shells available with Linux which includes the following
- BASH (Bourne Again SHell)
- CSH ( C Shell)
- KSH ( Korn Shell)
- TCSH
- Built-in shell commands: These commands are called from the shell and executed directly within the shell. Examples: ‘pwd’, ’help’, ’type’, ’set’, etc.
- External/ Linux commands: These commands are totally shell independent, have their own binary and are located in the file system.
Ans: As the name suggests, the shell script is the script written for the shell. This is a program file or says a flat text file where certain Linux commands are executed one after another. Although the execution speed is slow, Shell script is easy to debug and can also simplify everyday automation processes.
Que 25) Explain the features of Stateless Linux server?
Ans: The word stateless itself means ‘no state’. When on a single workstation, no state exists for the centralized server, and then the stateless Linux server comes into the picture. Under such conditions, scenarios like keeping all the systems on the same particular state can occur.
Some of the features of Stateless Linux server are explained below
- Stores prototype of every machine
- Store snapshots
- Store home directories
- Uses LDAP which determines the snapshot of state to be run on which system.
Ans: Process management in Linux uses certain system calls. These are mentioned in below table with a brief explanation
System calls | Explanation |
---|---|
Fork() | To create a new process |
Exec() | For execution of a new program |
Wait() | To make the process to wait |
Exit() | Exit/terminate the process |
Getpid() | To find the unique process id |
Getppid() | To find the parent process id |
Nice() | To bias the currently running process property |
Ans: There are many commands present in Linux which are used to look at the contents of the file.
Some of them are enlisted below
- head: Displays the beginning of the file
- tail: Displays the last part of the file
- cat: Concatenate files and print on the standard output.
- more: Displays the content in pager form and is used to view text in the terminal window one page or screen at a time.
- less: Displays the content in pager form and allows backward and single line movement.
Ans: It is well known that every command takes an input and displays an output. Keyboard serves as the standard input device and screen serves as the standard output device. Redirection is defined as the process of directing data from one output to another or even cases exist where output serves as an input data for another process.
There are basically three streams available in which input and output of Linux environment are distributed.
These are explained as below
- Input Redirection: ‘<’ symbol is used for input redirection and is numbered as (0). Thus it is denoted as STDIN(0).
- Output Redirection: ‘>’ symbol is used for output redirection and is numbered as (1). Thus it is denoted as STDOUT(1).
- Error Redirection: It is denoted as STDERR(2).
Ans: Linux is an open source operating system and nowadays it is growing rapidly in the tech world/market. Although the entire code written in Linux can be read by anyone, then to it is considered as more secure because of the following reasons
- Linux provides its user with limited default privileges which are basically restricted to the lower levels .i.e. in the case of any virus attack, it will reach only local files and folders where the system-wide damage is saved.
- It has a powerful auditing system which includes detailed logs.
- Enhanced features of IPtables are used in order to implement a greater level of security for Linux machine.
- Linux has tougher program permissions before installing anything on your machine.
Ans: Command grouping is basically done by the use of braces ‘()’ and parenthesis ‘{}’. Redirection is applied to the entire group when the command is grouped.
- When commands are placed within the braces, then they are executed by the current shell. Eg: (list)
- When the commands are placed within the parenthesis, then they are executed by a subshell. Eg: {list;}
Ans: Linux pwd command displays the whole path of the current location you are working in starting from the root ‘/’. For example, to print the current working directory enter “$ pwd”.
It can be used for the bellow purposes
- To find the full path of the current directory
- Store the full path
- Verify the absolute and physical path
Ans: ‘cd’ stands for change directory and is used to change the current directory on which user is working.
cd syntax : $ cd {directory}
Following purposes can be served with ‘cd’ commands
- Change from current to a new directory
- Change directory using the absolute path
- Change directory using the relative path
- cd~: Brings you to the home directory
- cd-: Brings you to the previous directory
- . : Bring you to the parent directory
- cd/: Takes you to the entire system’s root directory
Ans: Grep stands for ‘global regular expression print’. This command is used for matching a regular expression against text in a file. This command performs pattern-based searching and only the matching lines are displayed as output. It makes use of options and parameters that are specified along with the command line.
For example: Suppose we need to locate the phrase “our orders” in HTML file named as “order-listing.html”. Then the command will be as follows:
$ grep “our orders” order-listing.html
The grep command outputs the entire matching line to the terminal.
Que 34) How to create a new file and modify an existing file in vi editor? Also, enlist the commands used to delete information from vi editor.?
Ans: Find below the commands with the description
- vi filename: This is the command used to create a new file as well as modify an existing file.
- View filename: This command opens an existing file in read-only mode.
- X: This command deletes the character which is under the cursor or before the cursor location.
- dd: This command is used to delete the current line.
Ans: Every computer is connected to network internally or externally for the purpose of exchanging information. Network troubleshooting and configuration are essential parts of and network administration. The networking commands enable you to quickly troubleshoot connection issues with another system, check the response of another host, etc.
Network administrator maintains system network which includes network configuration and troubleshooting. Mentioned below are few commands along with their description:
Mentioned below are few commands along with their description
- Hostname: To view the hostname (domain and IP address) of the machine and to set the hostname.
- Ping: To check if the remote server is reachable or not.
- ifconfig: To display and manipulate route and network interfaces. It displays network configuration. ‘ip’ is the replacement of ifconfig command.
- netstat: It displays network connections, routing tables, interface statistics. ‘ss’ is the replacement of netstat command which is used to get more information.
- Traceroute: It is network troubleshooting utility which is used to find the number of hops required for a particular packet to reach the destination.
- Tracepath: It is same as traceroute with a difference that it does not require root privileges.
- Dig: This command is used to query the DNS name servers for any task related to DNS lookup.
- nslookup: To find DNS related query.
- Route: It shows the details of the route table and manipulates IP routing table.
- mtr: This command combines ping and track path into a single command.
- Ifplugstatus: This command tells us whether the network cable is plugged in or not.
1.Creating files, Reading files and Updating file content
To create file very first command in Linux
[root@ArkIT ~]# cat > firstfile
This is a first file created using cat command
As mentioned in above ‘>’ redirect symbol we have to use along
with cat command to create file with content. Whenever you type cat >
FILENAME hit enter, than it will just show blank screen below the command now
type some data and press CTRL+d first will save and exit.
To read file content below is the command example
[root@ArkIT ~]# cat firstfile
This is a first file created using cat command
[root@ArkIT ~]# cat >> firstfile
Second line of this file
[root@ArkIT ~]# cat firstfile
This is a first file created using cat command
Second line of this file
To append the file content ‘>>’ double grater than we have
to use. Type data and press CTRL+d to save.
2. List files and directories
To list files and directories in Linux we have to usels command
[root@ArkIT ~]# ls
anaconda-ks.cfg Desktop Documents Downloads file firstfile initial-setup-ks.cfg linux Music Pictures Public rhce Templates Videos
long list with detailed information show. ls -l command will show detailed list of files and
directories.
[root@ArkIT ~]# ls -l
total 24
-rw-------. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Mar 17 20:59 Desktop
drwxr-xr-x. 2 root root 6 Mar 17 20:59 Documents
drwxr-xr-x. 2 root root 6 Mar 17 20:59 Downloads
-rw-r--r--. 1 root root 1084 Apr 28 08:16 file
list and sort files based on created date
[root@ArkIT ~]# ls -ltr
total 24
-rw-r--r--. 1 root root 2016 Mar 17 20:58 initial-setup-ks.cfg
-rw-------. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
-rw-r--r--. 1 root root 1812 Apr 28 05:59 rhce
-rw-r--r--. 1 root root 1227 Apr 28 06:02 linux
-rw-r--r--. 1 root root 1084 Apr 28 08:16 file
-rw-r--r--. 1 root root 72 May 6 22:45 firstfile
ls -ltr means l =
long list, t = time, r = recursively
3. Let you know current working directory
To show in which directory your currently working use pwd commnad
[root@ArkIT ~]# pwd
/root
4. more – file perusal filter for crt viewing
more command is used
to filter for paging through text one screen full at a time.
[root@ArkIT ~]# cat anaconda-ks.cfg |more
[root@ArkIT ~]# more -d anaconda-ks.cfg
[root@ArkIT ~]# more anaconda-ks.cfg
5. copy files and directories from source to destination
To copy the files and directories from one location to other
location we have to use cp
command
To copy only files use below command. If you use same command for
directories will not work, have to use -r option along with cp command
[root@ArkIT ~]# cp firstfile /opt/
[root@ArkIT ~]# cp Music/ /opt/
cp: omitting directory ‘Music/’ <<< --- if you didn't use -r option this error will come
[root@ArkIT ~]# cp -r Music/ /opt/
[root@ArkIT ~]# ls -l /opt/
total 4
-rw-r--r--. 1 root root 72 May 7 07:15 firstfile
drwxr-xr-x. 2 root root 6 May 7 07:17 Music
whenever copying the files & directories we required to
preserve time stamps to preserving the time stamps of files & directories
use option ‘-p’ along with cp
command
[root@ArkIT ~]# ls -l
-rw-------. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg << -- Original file
[root@ArkIT ~]# cp -p anaconda-ks.cfg /opt/
[root@ArkIT ~]# ls -l /opt/anaconda-ks.cfg
-rw-------. 1 root root 1968 Mar 18 02:26 /opt/anaconda-ks.cfg <<--- copied file
6. Delete files and directories
To delete files and directories use rm command
[root@ArkIT ~]# rm file <<-- Delete regular file with confirmation
rm: remove regular file ‘file’? y
[root@ArkIT ~]# rm -f firstfile <<-- Delete Regular file without asking confirmation
[root@ArkIT ~]# rm -rf Public/ <<-- Delete Directory without asking for confirmation
To delete normal file use rm command it will ask you for the
conformation when deleting. If do not want to prompt any confirmation use -f
option. To delete directories use rm -rf .
Note: Be careful whenever your
running rm -rf, avoid wildcard * while running rm command, Go to the same
directory and run rm -rf using wildcard *.
7. Moving files and directories
Moving files meaning that changing the location of files from one
to another path. use mv
command
Syntax: mv [source]
[destination]
[root@ArkIT opt]# mv Music/ /root/
mv: overwrite ‘/root/Music’? y
8. Creating New Directories
Most of the guys who are not fimilier with Linux also they know
about mkdir command
[root@ArkIT ~]# mkdir /Testing <<-- Creating Directory under /
[root@ArkIT ~]# mkdir test <<-- Creating Directory in current path
[root@ArkIT ~]# mkdir -p /Test/Best/Rest/ <<-- Creating Collaborative directories
9. Changing directories
To go from one directory to another directory we have to use cd command
as you see in above screenshot . (dot) represents current
directory. ..(dot dot) represents its parent directory, what is the use of
them..?
whenever we use cd command cd
../../../which means we are going two directories back from current.
[root@ArkIT ~]# cd /tmp/ <<-- switch directory to /tmp
[root@ArkIT /]# cd /var/log/cups/ <<-- Switch to multiple directories yet the same time
[root@ArkIT cups]# cd ../../../ <<-- Going two directories back
[root@ArkIT /]# cd -
/var/log/cups <<-- Going to previously changed path
[root@ArkIT cups]# cd ~ <<-- Whereever your go back to User HOME directory
[root@ArkIT ~]# pwd
/root
~ (tild) is used to switch back to HOME path
10. Deleting empty directories
We can also make use of rm
command but some time we would
like to delete only empty directories (any directory didn’t contain any data)
so rmdir command is very handy whenever we would like to delete empty
directories. as a example we have taken two directories One is having few files
in it another one is empty.
[root@ArkIT ~]# rmdir /test <<-- Directory having few files in it not deleted
rmdir: failed to remove ‘/test’: Directory not empty
[root@ArkIT ~]# rmdir /Testing/ <<-- Directory is empty deleted successfully
11. Print files
To print files from Linux command line we can use lpr command
[root@ArkIT ~]# lpr rhce <<-- Print rhce file to default printer
[root@ArkIT ~]# lpr rhce -P PRINTERNAME <<-- Print rhce file to specified printer
[root@ArkIT ~]# lpr -#5 rhce <<--- Print only 5 pages out of all pages
12. List who is logged into system and run-levels
show who logged in to server and which run level is running
currently
[root@ArkIT ~]# who
root tty1 2016-05-06 22:06
root pts/0 2016-05-07 07:10 (192.168.4.1)
root pts/1 2016-05-07 09:17 (192.168.4.1)
[root@ArkIT ~]# who -r
run-level 3 2016-05-06 22:05
[root@ArkIT ~]# who -d
[root@ArkIT ~]# who -H
NAME LINE TIME COMMENT
root tty1 2016-05-06 22:06
root pts/0 2016-05-07 07:10 (192.168.4.1)
root pts/1 2016-05-07 09:17 (192.168.4.1)
[root@ArkIT ~]# who -a
system boot 2016-05-06 22:05
run-level 3 2016-05-06 22:05
root + tty1 2016-05-06 22:06 12:22 1604
root + pts/0 2016-05-07 07:10 02:45 3973 (192.168.4.1)
root + pts/1 2016-05-07 09:17 . 4995 (192.168.4.1)
13. Clear screen
Typing all the commands on screen and its output in screen will
look like messy to clear all this output and commands typed use clear command
Video Player
00:00
00:00
14. Check disk and partition spaces
To list partition space and its utilization you have to use df command
[root@ArkIT ~]# df -t xfs
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 18307072 3113572 15193500 18% /
[root@ArkIT ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/rhel-root 18317312 109332 18207980 1% /
[root@ArkIT ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 18% /
[root@ArkIT ~]# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17878 3041 14838 18% /
df -t <FileSystem> – it will list only the partition which
are formated with specified file system type
df -i – it will show with inode utilization
df -h – human redable format
df -m – all partition in MB size
15. Searching for files and its content
Searching for the content in file without opening the file use
grep command
[root@ArkIT ~]# grep commands linux
all unix commands with examples
linux commands cheat sheet
list of linux commands pdf
in above example we were searching for ‘commands’ string in
‘linux’ file
[root@ArkIT ~]# grep -v commands linux
linux lab exercises
linux practice labs
linux high performance computing
above example will exclude the specified string (it means which
lines does not contain string will be displayed)
For more and more examples see this
16. Check CPU and Memory utilization
top command is used to check CPU utilization, memory utilization
and more.
17. Stream editor command
sed is stream editor to replace the text in file without opening
in text editors, insert lines, delete lines and replace strings
[root@ArkIT ~]# sed -i 's/oldstring/newstring/g' FILENAME
18. killing processes when struck, hang OR not required
To kill the processes when they struck up, Hang state OR some
unwanted processes not required we can kill them
Send an signal using signal id. Signal id 9 means SIGKILL
[root@ArkIT ~]# kill -9 7330
[root@ArkIT ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
19. Listing running processes
when we run an command / script which will generate an process
with process ID and CPU will assign an Nice value priority for it.
[root@ArkIT ~]# ps
PID TTY TIME CMD
4995 pts/1 00:00:00 bash
7416 pts/1 00:00:00 ps
[root@ArkIT ~]# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 60032 7804 ? Ss 05:30 0:02 /usr/lib/systemd/systemd --switched-root --sy
root 2 0.0 0.0 0 0 ? S 05:30 0:00 [kthreadd]
[root@ArkIT ~]# ps -U root -u root u <<-- list all processes running by ROOT user
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 60032 7804 ? Ss 05:30 0:02 /usr/lib/systemd/systemd --switched-root --sy
root 2 0.0 0.0 0 0 ? S 05:30 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 05:30 0:00 [ksoftirqd/0]
20. Changing the files and directory permissions
This command most of the Linux administrators know, I think
nobody will work as Linux Administrator without knowing this command. The
command is chmod command
[root@ArkIT ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
[root@ArkIT ~]# chmod 760 anaconda-ks.cfg
[root@ArkIT ~]# chmod o+x anaconda-ks.cfg
[root@ArkIT ~]# ls -l
-rwxrw---x. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
[root@ArkIT ~]# chmod g+x anaconda-ks.cfg
[root@ArkIT ~]# ls -l anaconda-ks.cfg
-rwxrwx--x. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
We can use chmod command along as numeric numbers and alpha
chmod command
§
4 = read
§
2 = write
§
1 = execute
§
u = rwx — User permissions
§
g = rwx — Group permissions
§
o = rwx — Other permissions
21. Changing group ownership for files and directories
Changing ownership of files and directories usingchown and chgrp
command
chown USERNAME:GROUPNAME FILENAME
[root@ArkIT ~]# ls -l anaconda-ks.cfg
-rwxrwx--x. 1 root root 1968 Mar 18 02:26 anaconda-ks.cfg
[root@ArkIT ~]# chown root:project1 anaconda-ks.cfg
[root@ArkIT ~]# ls -l anaconda-ks.cfg
-rwxrwx--x. 1 root project1 1968 Mar 18 02:26 anaconda-ks.cfg
As shown in above example ownership of anaconds-ks.cfg has been
changed to project1 group and user root.
[root@ArkIT ~]# chgrp u1 anaconda-ks.cfg
[root@ArkIT ~]# ls -l anaconda-ks.cfg
-rwxrwx--x. 1 root u1 1968 Mar 18 02:26 anaconda-ks.cfg
22. Creating and extracting compressed files (zip files)
tar is the command used to create archive and extract archive
files
[root@ArkIT ~]# tar -czvf test.tar.gz *
anaconda-ks.cfg
Desktop/
Documents/
Downloads/
tar command options
§
-c = create
§
-z = gzip type file
§
-v = verbose
§
-f = file
§
-x = extract
[root@ArkIT ~]# tar -xvf test.tar.gz
23. Connecting to remote host using secure shell
In regular times we use this command to connect remote Linux based
host. To connect remote host using root user we have to use below command.
[root@ArkIT ~]# ssh root@192.168.4.21
Above comand will not support GUI to connect remote host using GUI
support, we have to use below command
[root@ArkIT ~]# ssh -XY root@192.168.4.21
24. Securely copy the files and directories to remote host
To copy the files from present host to remote host we have to use scp command
[root@ArkIT ~]# scp anaconda-ks.cfg root@192.168.4.21:/root/Desktop/
25. cheeking system Date and Time
To check system Date and Time we have to usedate command
[root@ArkIT ~]# date
Sat May 7 14:18:32 IST 2016
[root@ArkIT ~]# date +%D:%M:%Y
05/07/16:18:2016
Top 60 Linux Interview
Questions & Answers
1) What is Linux?
Linux is an operating system based on
UNIX, and was first introduced by Linus Torvalds. It is based on the Linux
Kernel, and can run on different hardware platforms manufactured by Intel,
MIPS, HP, IBM, SPARC and Motorola. Another popular element in Linux is its
mascot, a penguin figure named Tux.
2) What is the
difference between UNIX and LINUX?
Unix originally began as a propriety
operating system from Bell Laboratories, which later on spawned into different
commercial versions. On the other hand, Linux is free, open source and intended
as a non-propriety operating system for the masses.
3) What is 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.
4) What is 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.
5) What is LILO?
LILO is a boot loader for Linux. It
is used mainly to load the Linux operating system into main memory so that it
can begin its operations.
6) What is a swap
space?
A swap space is a certain amount of
space used by Linux to temporarily hold some programs that are running
concurrently. This happens when RAM does not have enough memory to hold all
programs that are executing.
7) What is the
advantage of open source?
Open source allows you to distribute
your software, including source codes freely to anyone who is interested.
People would then be able to add features and even debug and correct errors
that are in the source code. They can even make it run better, and then
redistribute these enhanced source code freely again. This eventually benefits
everyone in the community.
8 ) What are the basic
components of Linux?
Just like any other typical operating
system, Linux has all of these components: kernel, shells and GUIs, system
utilities, and application program. What makes Linux advantageous over other
operating system is that every aspect comes with additional features and all
codes for these are downloadable for free.
9) Does it help for a
Linux system to have multiple desktop environments installed?
In general, one desktop environment,
like KDE or Gnome, is good enough to operate without issues. It’s all a matter
of preference for the user, although the system allows switching from one
environment to another. Some programs will work on one environment and not work
on the other, so it could also be considered a factor in selecting which
environment to use.
10) What is the basic
difference between BASH and DOS?
The key differences between the BASH
and DOS console lies in 3 areas:
– BASH commands are case sensitive while DOS commands are not;
– under BASH, / character is a directory separator and \ acts as an escape
character. Under DOS, / serves as a command argument delimiter and \ is the
directory separator
– DOS follows a convention in naming files, which is 8 character file name
followed by a dot and 3 character for the extension. BASH follows no such
convention.
11) What is the
importance of the GNU project?
This so-called Free software movement
allows several advantages, such as the freedom to run programs for any purpose
and freedom to study and modify a program to your needs. It also allows you to
redistribute copies of a software to other people, as well as freedom to
improve software and have it released to the public.
12) Describe the root
account.
The root account is like a systems
administrator account, and allows you full control of the system. Here you can
create and maintain user accounts, assigning different permissions for each
account. It is the default account every time you install Linux.
13) What is CLI?
CLI is short for Command Line
Interface. This interface allows user to type declarative commands to instruct
the computer to perform operations. CLI offers an advantage in that there is
greater flexibility. However, other users who are already accustom with using
GUI find it difficult to remember commands including attributes that come with
it.
14) What is GUI?
GUI, or Graphical User Interface,
makes use of images and icons that users click and manipulate as a way of
communicating with the computer. Instead of having to remember and type
commands, the use of graphical elements makes it easier to interact with the
system, as well as adding more attraction through images, icons and colors.
15) How do you open a
command prompt when issuing a command?
To open the default shell (which is
where the command prompt can be found), press Ctrl-Alt-F1. This will provide a
command line interface (CLI) from which you can run commands as needed.
16) How can you find
out how much memory Linux is using?
From a command shell, use the
“concatenate” command: cat /proc/meminfo for memory usage information. You
should see a line starting something like: Mem: 64655360, etc. This is the
total memory Linux thinks it has available to use.
You can also use commands
free – m
vmstat
top
htop
to find current memory usage
17) What is typical
size for a swap partition under a Linux system?
The preferred size for a swap
partition is twice the amount of physical memory available on the system. If
this is not possible, then the minimum size should be the same as the amount of
memory installed.
18) What are symbolic
links?
Symbolic links act similarly to
shortcuts in Windows. Such links point to programs, files or directories. It
also allows you instant access to it without having to go directly to the
entire pathname.
19) Does the
Ctrl+Alt+Del key combination work on Linux?
Yes, it does. Just like Windows, you
can use this key combination to perform a system restart. One difference is
that you won’t be getting any confirmation message and therefore, reboot is
immediate.
20) How do you refer to
the parallel port where devices such as printers are connected?
Whereas under Windows you refer to
the parallel port as the LPT port, under Linux you refer to it as /dev/lp .
LPT1, LPT2 and LPT3 would therefore be referred to as /dev/lp0, /dev/lp1, or
/dev/lp2 under Linux.
21) Are drives such as
harddrive and floppy drives represented with drive letters?
No. In Linux, each drive and device
has different designations. For example, floppy drives are referred to as
/dev/fd0 and /dev/fd1. IDE/EIDE hard drives are referred to as /dev/hda,
/dev/hdb, /dev/hdc, and so forth.
22) How do you change
permissions under Linux?
Assuming you are the system
administrator or the owner of a file or directory, you can grant permission
using the chmod command. Use + symbol to add permission or – symbol to deny
permission, along with any of the following letters: u (user), g (group), o
(others), a (all), r (read), w (write) and x (execute). For example the command
chmodgo+rw FILE1.TXT grants read and write access to the file FILE1.TXT, which
is assigned to groups and others.
23) In Linux, what
names are assigned to the different serial ports?
Serial ports are identified as
/dev/ttyS0 to /dev/ttyS7. These are the equivalent names of COM1 to COM8 in
Windows.
24) How do you access
partitions under Linux?
Linux assigns numbers at the end of
the drive identifier. For example, if the first IDE hard drive had three
primary partitions, they would be named/numbered, /dev/hda1, /dev/hda2 and /dev/hda3.
25) What are hard
links?
Hard links point directly to the
physical file on disk, and not on the path name. This means that if you rename
or move the original file, the link will not break, since the link is for the
file itself, not the path where the file is located.
26) What is the maximum
length for a filename under Linux?
Any filename can have a maximum of
255 characters. This limit does not include the path name, so therefore the
entire pathname and filename could well exceed 255 characters.
27)What are filenames
that are preceded by a dot?
In general, filenames that are
preceded by a dot are hidden files. These files can be configuration files that
hold important data or setup info. Setting these files as hidden makes it less
likely to be accidentally deleted.
28) Explain virtual
desktop.
This serves as an alternative to
minimizing and maximizing different windows on the current desktop. Using
virtual desktops, each desktop is a clean slate where you can open one or more
programs. Rather than minimizing/restoring all those programs as needed, you
can simply shuffle between virtual desktops with programs intact in each one.
29) How do you share a
program across different virtual desktops under Linux?
To share a program across different
virtual desktops, in the upper left-hand corner of a program window look for an
icon that looks like a pushpin. Pressing this button will “pin” that
application in place, making it appear in all virtual desktops, in the same
position onscreen.
30) What does a nameless
(empty) directory represent?
This empty directory name serves as
the nameless base of the Linux file system. This serves as an attachment for
all other directories, files, drives and devices.
31) What is the pwd
command?
The pwd command is short for print
working directory command. It’s counterpart in DOS is the cd command, and is
used to display the current location in the directory tree.
32) What are daemons?
Daemons are services that provide
several functions that may not be available under the base operating system.
Its main task is to listen for service request and at the same time to act on
these requests. After the service is done, it is then disconnected and waits
for further requests.
33) How do you switch
from one desktop environment to another, such as switching from KDE to Gnome?
Assuming you have these two
environments installed, just log out from the graphical interface. Then at the
Log in screen, type your login ID and password and choose which session type
you wish to load. This choice will remain your default until you change it to
something else.
34) What are the kinds
of permissions under Linux?
There are 3 kinds of permissions
under Linux:
– Read: users may read the files or list the directory
– Write: users may write to the file of new files to the directory
– Execute: users may run the file or lookup a specific file within a directory
35) How does case
sensitivity affect the way you use commands?
When we talk about case sensitivity,
commands are considered identical only if every character is encoded as is,
including lowercase and uppercase letters. This means that CD, cd and Cd are
three different commands. Entering a command using uppercase letters, where it
should be in lowercase, will produce different outputs.
36) What are environmental
variables?
Environmental variables are global
settings that control the shell’s function as well as that of other Linux
programs. Another common term for environmental variables is global shell
variables.
37) What are the
different modes when using vi editor?
There are 3 modes under vi:
– Command mode – this is the mode where you start in
– Edit mode – this is the mode that allows you to do text editing
– Ex mode – this is the mode wherein you interact with vi with instructions to
process a file
38) Is it possible to
use shortcut for a long pathname?
Yes, there is. A feature known as
filename expansion allows you do this using the TAB key. For example, if you
have a path named /home/iceman/assignments directory, you would type as
follows: /ho[tab]/ice[tab]/assi[tab] . This, however, assumes that the path is
unique, and that the shell you’re using supports this feature.
39) What is
redirection?
Redirection is the process of
directing data from one output to another. It can also be used to direct an
output as an input to another process.
40) What is grep
command?
grep a search command that makes use
of pattern-based searching. It makes use of options and parameters that is
specified along the command line and applies this pattern into searching the
required file output.
41) What could possibly
be the problem when a command that was issued gave a different result from the
last time it was used?
One highly possible reason for
getting different results from what seems to be the same command has something
to do with case sensitivity issues. Since Linux is case sensitive, a command
that was previously used might have been entered in a different format from the
present one. For example, to lists all files in the directory, you should type
the command ls, and not LS. Typing LS would either result in an error message
if there is no program by that exact name exist, or may produce a different
output if there is a program named LS that performs another function.
42) What are the
contents in /usr/local?
It contains locally installed files.
This directory actually matters in environments where files are stored on the
network. Specifically, locally-installed files go to /usr/local/bin,
/usr/local/lib, etc.). Another application of this directory is that it is used
for software packages installed from source, or software not officially shipped
with the distribution.
43) How do you
terminate an ongoing process?
Every process in the system is
identified by a unique process id or pid. Use the kill command followed by the
pid in order to terminate that process. To terminate all process at once, use
kill 0.
44) How do you insert
comments in the command line prompt?
Comments are created by typing the #
symbol before the actual comment text. This tells the shell to completely
ignore what follows. For example: “# This is just a comment that the shell will
ignore.”
45) What is command
grouping and how does it work?
You can use parentheses to group
commands. For example, if you want to send the current date and time along with
the contents of a file named OUTPUT to a second file named MYDATES, you can
apply command grouping as follows: (date cat OUTPUT) > MYDATES
46) How do you execute
more than one command or program from a single command line entry?
You can combine several commands by separating
each command or program using a semicolon symbol. For example, you can issue
such a series of commands in a single entry:
ls –l cd .. ls –a MYWORK which is equivalent to 3 commands: ls -l cd.. ls -a MYWORK
**Note that this will be executed one
after the other, in the order specified.
47) Write a command
that will look for files with an extension “c”, and has the occurrence of the
string “apple” in it.
Answer:
Find ./ -name “*.c” | xargsgrep –i “apple”
48) Write a command
that will display all .txt files, including its individual permission.
Answer:
ls -al *.txt
49) 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’ | xargsgrep “ORANGE”
50) What, if anything,
is wrong with each of the following commands?
a) ls -l-s
b) cat file1, file2
c) ls – s Factdir
Answers:
a) there should be space between the 2 options: ls -l -s
b) do not use commas to separate arguments: cat file1 file2
c) there should be no space between hyphen and option label: ls –s Factdir
51) What is the command
to calculate the size of a folder?
To calculate the size of a folder use
the command du –sh
folder1.
52) How can you find
status of a process?
Use the command
psux
53) How can you check
the memory status ?
You can use the command
free -m to display output in MB
free -g to display output in GB
54) Explain how to
color the Git console?
To color the Git console you
can use the command git
config—global color.ui auto. In
the command, the color.ui variable sets the default value for variable such as color.diff and color.grep.
55) How can you append
one file to another in Linux?
To append one file to another in
Linux you can use command cat
file2 >> file 1. The
operator >> appends the output of the named file or creates the file if
it is not created. While another command cat file 1 file 2 > file 3 appends two or more files to
one.
56) Explain how you can
find a file using Terminal?
To find a file you have to use
command, find . –name
“process.txt” .
It will look for the current directory for a file called process.txt.
57) Explain how you can
create a folder using Terminal?
To create a folder, you have to use
command mkdir. It will be something
like these : ~$ mkdir Guru99
58) Explain how
you can view the text file using Terminal?
To view the text file, go to the
specific folder where the text files are located by using the command cd and then type less filename.txt.
59) Explain how to
enable curl on Ubuntu LAMP stack?
To enable curl on Ubuntu , first
install libcurl, once done use following command sudo/etc/init .d /apache2
restart or sudo service apache2 restart.
60) Explain how to
enable root loging in Ubuntu?
The command which enables root loging
is
61) How you can
run an Linux program in the background simultaneously when you start your Linux
Server?
By using nohup. It will stop the process
receiving the NOHUP signal and thus terminating it you log out of the program which was invoked with. & runs the process in the background.
62) Uninstall libraries in linux?
by using #sudo apt -get remove library_name
– BASH commands are case sensitive while DOS commands are not;
– under BASH, / character is a directory separator and \ acts as an escape character. Under DOS, / serves as a command argument delimiter and \ is the directory separator
– DOS follows a convention in naming files, which is 8 character file name followed by a dot and 3 character for the extension. BASH follows no such convention.
– Read: users may read the files or list the directory
– Write: users may write to the file of new files to the directory
– Execute: users may run the file or lookup a specific file within a directory
– Command mode – this is the mode where you start in
– Edit mode – this is the mode that allows you to do text editing
– Ex mode – this is the mode wherein you interact with vi with instructions to process a file
-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.
a) ls -l-s
b) cat file1, file2
c) ls – s Factdir
a) there should be space between the 2 options: ls -l -s
b) do not use commas to separate arguments: cat file1 file2
c) there should be no space between hyphen and option label: ls –s Factdir
62) Uninstall libraries in linux?
by using #sudo apt -get remove library_name
Best data structure and algorithms online course
ReplyDeleteThe Logicmojo is a good hub for providing online courses.We offer the best free online courses to learn and Best Data Structures And Algorithms Course,Data Structures Online Course,Best Algorithms Course,System Design interview question,data structure and algorithms in JAVA,Best data structure and algorithms online course etc. For more info visit our website today.
Best data structure and algorithms online course