linux practical - shell commands Flashcards

1
Q

how to check the version of the bash shell

A

echo $SHELL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to change the password in linux

A

passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do you clear the terminal

A

clear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

who do you display who is the current login user in the terminal

A

whoami

the login user name is also displayed on the terminal prompt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to display the current system date

A

date

eg output:
Tue Sep 15 12:00:29 SGT 2022

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Display the Day of the Week

A

Format: %A
Example: date +%A
Output: Tuesday

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Display the Day of the Month

A

Format: %d
Example: date +%d
Output: 14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Display the Month

A

Format: %B
Example: date +%B
Output: January

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Display the Year

A

Format: %Y
Example: date +%Y
Output: 2022

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Flashcard: Change Date Separator
Format: 2023 - 01 - 14

A

example: %Y-%m-%d
Output: 2022-01-14
Description: In this example, the date separator is changed from default ‘/’ to ‘-‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Display the Timezone

A

Format: %Z
Example: date +%Z
Output: EST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Display the Day of the Week (abbreviated)

A

Format: %a
Example: date +%a
Output: Tue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Flashcard: Display the Month (numerical)

A

Format: %m
Example: date +%m
Output: 01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Display the current year in a different format (YY)

A

Command: date +%y
Description: Display the current year in the format of YY (Year)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why the date command failed run when the format string does not have the single or
double quotes

A

When a format string contains spaces, it should be quoted by single or double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to display the current calendar of the month

A

cal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

display the calendar for 2023

A

cal 2023

18
Q

how to display a calendar with monday as the first date

A

cal -m

19
Q

how to display the calendar for may 2023

A

cal 5 2023

20
Q

how to display current, previous and next date

A

cal -3

21
Q

how to display the specific date on cal

A

cal 12 8 2022

will display 12 august 2022 on the calendar

22
Q

how to display the current month and the next 2 months

A

cal -3 2 2023

23
Q

Perform mathematical calculations

A

Command: bc -l
Example: 2+2
Output: 4
Description: bc -l can be used to perform mathematical calculations, like addition, subtraction, multiplication, division, and more. You can also use mathematical functions such as log, sin, cos, sqrt and more.

24
Q

how to Define variables to do maths calculation

A

Command: bc -l
Example: a=3; b=4; a*b
Output: 12

Example: sqrt(2)
Output: 1.41

25
Q

how can commands be embedded within a string

A

Commands can be embedded within a string with “$(command)” or using backquotes
to quote the command.

echo “hello whoami
echo “hello “$(whoami)

26
Q

what does the man command do ?

A

the man manual command provides information about commands.

man date gives you more information about the man command

27
Q

Interpreting command syntax in man pages:

what is []

A

Arguments are optional

example: [+FORMAT]

28
Q

Interpreting command syntax in man pages:

what is …

A

Represents a list

example: [file …]

29
Q

Interpreting command syntax in man pages:

what is |

A

or

example: [-u|–utc|–universal]

30
Q

Interpreting command syntax in man pages:

what is -

A

Any combination of available options in any order

example: [ -hlwsqv]

31
Q

what is the whatis command used for ?

A

The whatis command is used to display a short description of the command.

32
Q

why is information for commands after installation not shown immediately

A

The whatis command uses a database for searching. Information may not be
available for commands immediately after installation as the database is updated
nightly.

33
Q

how to scroll command history

A

Up and down arrow key

34
Q

Repeat a command by the command history number

A

!n

35
Q

Repeat the last command.

A

!!

36
Q

how to display a list of commands executed

A

run the history command

37
Q

how to logout from account

A

logout command

38
Q

how to logout from shell

A

exit command

39
Q

how to add user in linux

A

adduser guest

40
Q

difference between su - guest and su guest

A

The difference between “su guest” and “su - guest” is that the latter includes the option “-“. The “-“ option is used to switch to the new user and also to change to that user’s home directory, and it also execute the target user’s profile and environment files.