Understanding the Shell Environment Flashcards

1
Q

What is the shell?

A

The Shell is a binary application to interact with the system directly. It is a text mode interface

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

What is the default shell in SUSE?

A

The default shell in SUSE is bash

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

Where can you see the available shells?

A

Available shells are in /etc/shells

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

What command shows the aliases for the user?

A

The command #alias give you the list of aliases for the user

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

What type of variables are there?

A

There are shell variables and environment variables

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

What are functions?

A

Functions are like script-like grouping of commands

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

What is an alias?

A

They are like shortcuts to larger commands

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

What are the shells modes?

A

Login, via ssh, using su - or sudo -I

Non-login, using su

Interactive when you execute a command

Non-interactive when you run remotely ssh user@host “somecommand”

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

What are the files used for interactive logins?

A

/etc/profile and .profile are used for interactive logins

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

What are the files used for non-interactive logins?

A

/etc/bash.bashrc and .bashrc as used for non-interactive logins

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

What man page gives you info about the shell?

A

man bash

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

What command shows you the list of files you have run?

A

history

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

What files keeps the history in store?

A

The file /home/user/.bash_history keeps the history

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

How do you re-run command 77 in the history?

A

!77

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

What keys do you have to use to re-run the last command you ran?

A

To re-execute the last command just type !!

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

What do variables contain?

A

Variables contain data

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

What command can you use to see the variables?

A

echo $VAR_NAME

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

What command can you use to see ALL the variables?

A

env

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

What command displays all variables and functions?

A

set

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

To set a variable, run this syntax:

A

VARIABLE=content

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

To make a brand new variable available to all shells, you have to…

A
export it:
#export VAR=content
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Special variables are:

A

$? shows the exit code of the previous command
$0 shows the name of the command executed
$* shows all the arguments a command had
$# shows how many arguments were used
$$ shows the PID of the shell you are in

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

Which are the exit code values?

A

0 means no errors, zero errors

Something else, usually 127 or 1 means an error in command just run

24
Q

Piping and redirection uses these values:

A

Stdin, 0, accepts input from pipes

Stdout, 1, is displayed or piped

Stderr, 2, is printed on the screen

25
Q

what is the bit bucket?

A

/dev/null is the bit bucket in the system

26
Q

What is the difference between > and&raquo_space; ?

A

> writes and overwrites if done twice in a row

> > appends

27
Q

What does this do? 1> /file

A

writes stdout to a file

28
Q

What does this do? 2>/dev/null

A

sends stdout to the bit bucket

29
Q

What does this do? 2» /file

A

appends to a file

30
Q

What does this do?

A

sends a file as stdin to a command

31
Q

What does the #tee command do?

A

The #tee command is a splitter, so, it lets the initial command print the stdout to the screen and writes that same stdout to a file.

32
Q

What is the syntax of the #tee command?

A
#find /home -type f -iname Jose.txt | tee jose_file
/home/Jose.txt
33
Q

How can you run 2 or more unrelated commands in the same command line

A

use a semi-colon between the commands (;)

34
Q

How can you run 2 or more unrelated commands in the same command line?

A

You can do the same with && but they will both show in the screen only if the first command actually succeeds. If the first command fails, the sequence stops:

35
Q

What does this do? ||

A

|| a double piple between 2 commands means to run the second command only if the first one fails

36
Q

What does this command do? cp /dir1/* dir2

A

it copies only the files within dir1 and not the directory itself

37
Q

Does the #mv command use the same inodes before and after the move?

A

the mv command uses the same inode numbers before and after the move

38
Q

Is #mv recursive by default?

A

mv is recursive by default

39
Q

Can #rm remove non-empty directories?

A

no, for that use # rm -rf

40
Q

To remove the contents of a directory, but not the dir itself, do:

A

rm -rf dir2/dir1/*

41
Q

In case the dir you want to delete is not empty, use:

A

rmdir –ignore-fail-on-non-empty dir_name

42
Q

What info does the #stat command display?

A

stat give you links, perms, size, access, modify, change timestamps, block size, etc

43
Q

What time stamp does # cat change?

A

cat changes the access time

44
Q

What time stamp does # chmod change?

A

chmod changes the modify time

45
Q

What time stamp does #ls -l display?

A

ls -l always shows the modify time

46
Q

Does writing content inside a file change the change timestamp?

A

yes

47
Q

to reset your terminal, use the command…

A

reset

48
Q

What is the command that refreshes a command o/p every 2 seconds?

A

watch refreshes the stdout every 2 seconds for a command. #top has watch integrated

49
Q

What are common options for the find command?

A
  • name
  • iname
  • newer: searches for a file newer than a given file
  • user
  • exec runs a command against that the find command found, remember it finishes with \;
50
Q

What does grep do?

A

it fetches contents of files based on the arguments/options given

51
Q

What are some grep options?

A
  • i case insensitive
  • r recursively searches throught a target directory
  • n shows the line number of the search result at the beginning of each line in the stdout
  • v inverts the search, shows all BUT the string
  • w searches for whole words only, exact string match only
52
Q

What is the difference between archiving and compressing?

A

archiving: tar, same size as original file
compressing: does compress

53
Q

Name a few common tar options

A

cvf new.tar things_to_tar
xvf file_to_extract.tar
tf file.tar

54
Q

Syntax of compression:

A

gzip: tar -czvf new.tar.gz directory_to_compress
bzip2: tar -cjvf new.tar.bz2 directory_to_compress
xz: tar -cJvf new.tar.xz directory_to_compress

55
Q

to see the contents of the compressed tar:

A

tar -tzvf
tar -tjvf
tar -tJvf

56
Q

What happens if you don’t tar something and just compress it?

A

if you don’t tar something and just compress it, the compression tool will replace the original file (gzip does not compress directories)
You have to tar them first