Shell scripting has many benefits that make it crucial. It takes input from users, files it, and displays it on the screen. Moreover, it allows you to make your own commands and automate simple daily tasks. You can use Shell scripting to automate system administration tasks also. Shell scripting makes your processes more efficient by saving you a lot of energy and time. Due to this, it is quite essential and widely used.
Posted Date:- 2021-09-10 10:03:25
Yes. We use single quotes where we don’t want to perform the variables’ evaluation to values. On the other hand, we use double quotes where we want to perform the variables’ evaluation to values.
Posted Date:- 2021-09-10 10:02:28
While working with Vi Editor, different operations we perform are done in different modes.
1. Command Mode - Launching Vi automatically starts command mode.
2. Edit Mode - This mode provides an environment to edit text.
3. Ex Mode - Vi editor interaction is made available with file processing instructions.
Posted Date:- 2021-09-10 10:01:29
To put it in simple words, a thread is a small piece of code/instruction that needs to be executed in a process, whereas a process is a collection of one or more thread executions to complete one complete task.
Posted Date:- 2021-09-10 10:00:06
Owner permissions: The permissions granted to a user with all the rights at the root level.
Group permissions: The permissions granted to a user with all the rights in a particular group.
Other permissions: The permissions granted to a user with all the rights globally to a file.
Posted Date:- 2021-09-10 09:59:26
#!/bin/bash
X=10
Y=20
If [ $x –gt $y ]
Then
Echo “ x is greater than yâ€
Else
Echo “y is greater than xâ€
Fi
Posted Date:- 2021-09-10 09:58:35
For Loop:
for var in word1 word2 … wordn
do
Statement(s) to be executed for every word.
done
While Loop:
while command
do
Statement(s) to be executed if command is true
Done
Until Loop:
until command
do
Statement(s) to be executed until command is true
done
Posted Date:- 2021-09-10 09:57:56
We can create the directory giving read and execute access to everyone in the group and setting its sticky bit “t†on as follows:
mkdir direc1
chmod g+wx direc1
chmod +t direc1
Posted Date:- 2021-09-10 09:57:15
#!/bin/sh
echo “Hello, $LOGNAMEâ€
echo “Today’s date is `date`â€
echo “Username is `who i am`â€
echo “Current directory is `pwd`â€
Posted Date:- 2021-09-10 09:56:09
We can use ssh to do this:
ssh username@serverIP -p sshport
Once the above command is executed, enter the password.
Posted Date:- 2021-09-10 09:53:38
>> df: It is used to check the free disk space.
>> du: It is used to check the directory wise disk usage.
>> dfspace: It is used to check the free disk space in terms of MB.
Posted Date:- 2021-09-10 09:52:11
cron.allow which decides the users need to be permitted for using the crontab command.
cron.deny which decides the users need to be prevented from using the crontab command
Posted Date:- 2021-09-10 09:51:17
The five fields contain information on when to execute the command .
minute(0-59)
hour(0-23)
day(1-31)
month(1-12)
day of the week(0-6, Sunday = 0).
Posted Date:- 2021-09-10 09:50:36
Crontab stands for cron table because it uses the job scheduler cron to execute tasks. The crontab is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list.
Posted Date:- 2021-09-10 09:49:57
Boot block: it contains a small program called MBR which loads the kernel during system boot up.
Super block: super block contains all information about the file system.
Inode block: it contains inode for every file of the file system.
Posted Date:- 2021-09-10 09:49:17
Ps ux command user for find status of process.
Posted Date:- 2021-09-10 09:47:46
“s†bit also called “set user idâ€(SUID) bit. “s†on file causes the process to have the privileges of the owner of the file during the instance of the program.
Posted Date:- 2021-09-10 09:47:01
“c †and “b†permission fields are generally associated with a device file. It specifies whether a file is a special character file or a block special file.
Posted Date:- 2021-09-10 09:46:28
alias Aliasname=â€Command whose alias is to be createdâ€.
Posted Date:- 2021-09-10 09:45:58
This block contains the inode for every file of the file system along with all the file attributes except its name.
Posted Date:- 2021-09-10 09:44:56
Super block contains all the information about the file system like the size of file system, block size used by its number of free data blocks and list of free inodes and data blocks.
Posted Date:- 2021-09-10 09:44:24
Bootblock, super block, inode block and Datablock are found fundamental components of every file system on Linux.
Posted Date:- 2021-09-10 09:43:59
sed '^ [(backslash)011(backslash)040]*$/d' file1
where (backslash)011 is an octal equivalent of space and
(backslash)040 is an octal equivalent of the tab
Posted Date:- 2021-09-10 09:43:25
The command $? gives the exit status of the last command that was executed.
Posted Date:- 2021-09-10 09:42:59
du -s /home/user1 ….where user1 is the user for whom the total disk space needs to be found.
Posted Date:- 2021-09-10 09:42:28
Syntax:
for iterator in (elements)
do
execute commands
done
Posted Date:- 2021-09-10 09:41:59
/etc/shadow file has all the users listed.
awk –F ':' '{print $1}' /etc/shadow|uniq -u
Posted Date:- 2021-09-10 09:41:31
egrep is Extended grep that supports added grep features like “+†(1 or more occurrence of a previous character),â€?â€(0 or 1 occurrence of a previous character) and “|†(alternate matching)
Posted Date:- 2021-09-10 09:40:08
awk ‘END {print NR} fileName’
Posted Date:- 2021-09-10 09:39:37
“exec†overlays the newly forked process on the current process; so when I execute the command using exec, the command gets executed on the current shell without creating any new processes.
Posted Date:- 2021-09-10 09:39:10
0 – Standard Input1 – Standard Output2 – Standard Error
Posted Date:- 2021-09-10 09:38:45
A Shell consists of metacharacters, which are special characters in a data field or program that offers information about other characters. For example, the “ls s*†command in a Shell lists all the files beginning with the character ‘s’.
Posted Date:- 2021-09-10 09:38:21
IFS refers to Internal Field Separator. It is a system variable whose default value is space, tab, following by a new line. IFS denotes where a field or word ends in a line and where another begins.
Posted Date:- 2021-09-10 09:37:55
$ ls -lrt | grep ^-? the command used for displaying the list of files in a directory.
Posted Date:- 2021-09-10 09:37:31
The command that used for forwarding error to a file is 2> filename
Posted Date:- 2021-09-10 09:37:09
1. & - "Bitwise AND", evaluates both sides of the operation.
2. && - "Logical AND Operator", evaluates at the left side of the operation (If it is True) it continues at the right side.
Posted Date:- 2021-09-10 09:36:49
Control instructions are commands that allow you to specify how the different instructions in a script should be executed. Thus, their primary purpose is to determine the flow of control in a Shell program.
A Shell has four types of control instructions:
> Sequence control instruction enforces the instructions to be executed in the same order in which they are in the program.
> Selection/decision control instruction that enables the computer to determine which instruction should be executed next.
> Repetition/loop control instruction that allows the computer to run a group of statements repetitively.
Case-control instruction is used when you need to choose from a range of alternatives.
Posted Date:- 2021-09-10 09:35:56
The three modes of operation are:
> Command mode – This mode treats and interprets any key pressed by a user as editor commands.
> Insert mode – You can use this mode to insert a new text, edit an existing text, etc.
> Ex-command mode – A user can enter all commands at a command line.
Posted Date:- 2021-09-10 09:33:33
A file system has four blocks:
1. Superblock – This block offers information on the state of a file system such as block size, block group size, usage information, empty/filled blocks and their respective counts, size & location of inode tables, etc.
2. Bootblock – This block holds the bootstrap loader program that executes when a user boots the host machine.
3. Datablock – This block includes the file contents of the file system.
Inode table – UNIX treats all elements as files, and all information related to files is stored in the inode table.
Posted Date:- 2021-09-10 09:32:41
You can create shortcuts in Linux via two links:
Hard link – These links are linked to the inode of the file. They are always present in the same file system as the file. Even if you delete the original file, the hard link will remain unaffected.
Soft link – These links are linked to the file name. They may or may not reside on the same file system as the file. If you delete the original file, the soft link becomes inactive.
Posted Date:- 2021-09-10 09:31:50
Advantages of shell scripting:
1. Can design applications (software) according to their platform.
2. To run a sequence of commands as a single command.
3. Portable (It can be executed in any Unix-like operating system without any modifications)
Disadvantages of shell scripting:
1. Slow execution speed compared to any programming languages
2. When a tying error occurs during the creation then it will delete the entire data as well as partition data.
Posted Date:- 2021-09-10 09:30:42
The following command is used: [ $a -gt 12 ]
Posted Date:- 2021-09-10 09:29:36
It can handle very large JSON structures, including streams.
Ex:
$ jq . <<< '{ "foo": "lorem", "bar": "ipsum" }'
{
"bar": "ipsum",
"foo": "lorem"
}
Posted Date:- 2021-09-10 09:29:16
When running several commands "if" condition meets.
Posted Date:- 2021-09-10 09:28:51
The soft links can simply be made inactive in your delete the file and the same doesn’t have any impact on the hard link and i.e. the users can access the file copy.
Posted Date:- 2021-09-10 09:28:28
They are stored in a file which is tagged as Sh (Bourne Shell)
Posted Date:- 2021-09-10 09:28:07
Well, this is important due to so many reasons and a few important ones are spotlighted below.
1. When it comes to creating customized commands or creating your own, shell scripting is very useful and powerful.
2. There are a lot of tasks that can easily be automated in the process.
3. The users are responsible for providing the input and this clearly means there will be no errors in the output.
4. It is good enough to be considered for time-saving.
5. A lot of system administration tasks can be accomplished and can be automated.
Posted Date:- 2021-09-10 09:27:47
When a: Break†is used within a shell scripting loop is considered, it simply terminates the entire loop. On the other side, the “Continue†will make only the current iteration terminate.
However, you can have the loop available with you in the next iteration. These are the two powerful and in fact very useful features when it comes to constructing the shell.
Posted Date:- 2021-09-10 09:26:55
The answer to this question depends on the skills of a professional. There are various methods and it is not always necessary that all users consider a similar method for problem debugging. Also, it actually depends on the problem itself.
The first method that can help users to formulate the problem is simply inserting some debug statements. This will actually help the pinpoint to know how and where the problem was declared itself or reported. Another method that is also common and the users can make use of it is set-x.
Posted Date:- 2021-09-10 09:26:31
It can be done simply by executing the $ in the system. It will show all the arguments that have already passed from the command line to a script.
Sometimes you need to specify the argument’s numeric position and the users have to make sure that things are done in a rightful manner.
Posted Date:- 2021-09-10 09:25:36
Yes, this is possible and for this, the users are free to simply consider the UNIX test command. The option that is useful is the –d option. It is not always necessary that the information regarding the existence of a directory is displayed only when the directory is recognized by the system.
Information regarding all the directories whether known to the system or not can be displayed with this command. Generally, directories are present in the variable $mydir.
Posted Date:- 2021-09-10 09:24:04
= This is used for assigning value to the variable.
== This is used for string comparison.
Posted Date:- 2021-09-10 09:23:07
Given below are some common methods used to debug the problems in the script.
Debug statements can be inserted in the shell script to output/display the information which helps to identify the problem.
Using set -x we can enable debugging in the script.
Posted Date:- 2021-09-10 09:21:38
No, you don’t need a separate compiler to execute a Shell program. Since Shell itself is a command-line in the shell program and executes them.
Posted Date:- 2021-09-10 09:20:48
For pass arguments in script “scriptname arg1 arg2 arg3 …â€
For access arguments in script can be accessed inside the script as “$1 , $2 .. $nâ€
Posted Date:- 2021-09-10 09:18:57