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
what is the bit bucket?
/dev/null is the bit bucket in the system
26
What is the difference between > and >> ?
> writes and overwrites if done twice in a row >> appends
27
What does this do? 1> /file
writes stdout to a file
28
What does this do? 2>/dev/null
sends stdout to the bit bucket
29
What does this do? 2>> /file
appends to a file
30
What does this do?
sends a file as stdin to a command
31
What does the #tee command do?
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
What is the syntax of the #tee command?
``` #find /home -type f -iname Jose.txt | tee jose_file /home/Jose.txt ```
33
How can you run 2 or more unrelated commands in the same command line
use a semi-colon between the commands (;)
34
How can you run 2 or more unrelated commands in the same command line?
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
What does this do? ||
|| a double piple between 2 commands means to run the second command only if the first one fails
36
What does this command do? cp /dir1/* dir2
it copies only the files within dir1 and not the directory itself
37
Does the #mv command use the same inodes before and after the move?
the mv command uses the same inode numbers before and after the move
38
Is #mv recursive by default?
mv is recursive by default
39
Can #rm remove non-empty directories?
no, for that use # rm -rf
40
To remove the contents of a directory, but not the dir itself, do:
rm -rf dir2/dir1/*
41
In case the dir you want to delete is not empty, use:
rmdir --ignore-fail-on-non-empty dir_name
42
What info does the #stat command display?
stat give you links, perms, size, access, modify, change timestamps, block size, etc
43
What time stamp does # cat change?
cat changes the access time
44
What time stamp does # chmod change?
chmod changes the modify time
45
What time stamp does #ls -l display?
ls -l always shows the modify time
46
Does writing content inside a file change the change timestamp?
yes
47
to reset your terminal, use the command...
#reset
48
What is the command that refreshes a command o/p every 2 seconds?
watch refreshes the stdout every 2 seconds for a command. #top has watch integrated
49
What are common options for the find command?
- 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
What does grep do?
it fetches contents of files based on the arguments/options given
51
What are some grep options?
- 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
What is the difference between archiving and compressing?
archiving: tar, same size as original file compressing: does compress
53
Name a few common tar options
cvf new.tar things_to_tar xvf file_to_extract.tar tf file.tar
54
Syntax of compression:
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
to see the contents of the compressed tar:
tar -tzvf tar -tjvf tar -tJvf
56
What happens if you don't tar something and just compress it?
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