Linux 101 (NE classes, Udemy classes etc.) Flashcards

1
Q

How to append the user to a secondary group?

A

usermod -aG [group] [username]

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

How to see all users and groups in the system?

A

/etc/passwd, /etc/group

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

How to give a group root privileges?

A

via adding the %groupname ALL=(ALL) ALL line to the /etc/sudoers file

Meaning: “any members of group groupname on ALL hosts can sudo to ALL user accounts to run ALL commands.

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

How to change ownership to a file/directory?

How change group ownership of a file with the other command?

A

chown [user].[group] [file]
or
chown [user]:[group] [file]

chgrp [group] [file]

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

How to change file/dir permissions? (2 methods)

A

Symbolically: chmod u=rwx,g+rw etc..
Numerically: chmod 753

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

How to locate a path to a given command?

A

which [command]

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

How to search the manual for keywords

A

man -k [keyword]

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

How does umask work?

A

By substracting numerically the permissions from any given file, od dir. So if umask is 777, the new directory will have 000 permissions. For files umask substract from 666 instead of 777 as it is for directories.

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

How to move, copy , rename directories (that have something inside of them)?

A

mv [dir] [destination]
cp -r [dir] [destination]
mv [old_name_dir] [new_name_dir]

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

How to put a directory into tar file with compressing?

A

tar -czf [new .tar file name] [directory]

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

How to compress, and uncompress files using gzip?

A

gzip [filename]

gunzip [filename]

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

How to view contents of .gz files? How to view content of tar files? (In human readable format, no cat command)

A

zcat [file]

tar -tf [file]

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

How to find a file (that is in your working directory) that starts with a “b”, then has two random letters, fourth letter is either “g” or “f”, fifth is a number from 1 to 6, sixth is neither “g” or “f”, and it ends with .txt?

A

ll -d (or ll | grep…) b??[g,f][1-6][!g,f]*.txt

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

How to redirect output of a text file to some other file replace it’s contents, and not show error message in a single command?

A

cat [file1] [file that doesn’t exis]> > [file2] 2> /dev/null

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

How to redirect output of a text file to some other file with replacing it’s contents, and not show error message in a single command?

A

cat [file1] [file that doesn’t exist ] > [file2] 2> /dev/null

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

How to redirect output of a text file to some other file and append it to it’s contents, and redirect error message to that same file? In a single command

A

cat [file1] [file that doesn’t exist]&raquo_space; [file2] 2>&1

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

How to compare files in two ways?

A

diff [file1] [file2]

sdiff [file1] [file2]

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

How to display filetype?

A

file [file]

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

How to cat with number of lines displayed?

A

cat -n

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

How to display content of a binary file in a human readable form?

A

strings [file]

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

How to cut a selected portions of a file? Let’s say we want to print only name of a user, and his login bash from the /etc/passwd file.

A

grep [username] /etc/passwd | cut -d: -f1,7

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

How to customize shell prompt, and make the shell customization saved between sessions?

A

The shell customization information is storen in the PS1 env variable, and it content of that env could look like this: [ \t \u@\h \W]$
Most likely we want the customization options to be saved in between sessions, so we would have to put this line into the /~/.bash_profile:
export PS1=”[customization options]”.
This would load up those PS1 options everytime we login into interactive shell.

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

How to create an alias?

A

alias [aliasname]=[value]

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

How to make alias persist between sessions?

A

either put your alias into the /~/.bash_profile or /~/.bashrc file.

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

How to delete alias? How to see one’s contents? How to see all user’s aliases?

A

unalias [aliasname]
alias [aliasname]
alias

26
Q

How to see all environment variables?

A

printenv

27
Q

How to view environment variable content?

A

printenv [env name]

or echo $[env name]

28
Q

How to create environmental variable?

A

export [variable]=[value]

29
Q

How to remove enviromental variable?

A

unset [variable name]

30
Q

How to keep enviroment variables persist between sessions?

A

put your export variable command into /~/.bash_profile file

export [var]=[value]

31
Q

How to display current processes in the system?

A

ps

32
Q

How to display all processes in the system in the interactive way?

A

top

33
Q

How to kill a process?

A

kill [process name or PID]

34
Q

How to send a signall to a process?

A

kill [-signal id] [PID or process name]

35
Q

How to display a list of signals which we can send to a process?

A

kill -l

36
Q

How does the cronjob format look like? Give an example for running something every tuesdayt at 09:15 pm

A

[minute] [hour] [day of a month] [month of a year] [day of a week]
15 21 * * 2 /bin/pwd

37
Q

How to create a cronjob, list cronjobs, remove and edit them?

A

crontab [filename]
crontab -l
crontab -r
crontab -e

38
Q

How to change users with and without changing user’s enviroment and what does it mean?

A

So let’s say we are root user, and we want to change to “xyz” user with changing our enviroment into the xyz enviroment. We would have to use su - xyz. If we didn’t want to change enviroment, we would have to use su xyz, so the same as above but without “-“. If we do change enviroment when changing user, it just means that we will have the xyz users aliases, enviroment variables etc. If we wouldn’t, we would still have roots aliases, variables, etc.

39
Q

How to see what user we are?

A

whoami

40
Q

How to run a command as other user?

A

su -c ‘[command]’ - [user]

41
Q

How to run programs as other user?

A

sudo -u [user] [program]

42
Q

Where is shell history stored?

A

/~/.bash_history and we can see current history with “history” command, as bash_history files only stores commands from last user session.

43
Q

How to change history size?

A

By editing $HISTSIZE, so

export HISTSIZE=[number]

44
Q

How to run commands by their history number?

A

![number]

45
Q

How to run previous command?

A

!!

46
Q

How to run last commands that starts with “xyz”?

A

!xyz

47
Q

How to grab arguments from previous commands?

A

!:[number of argument]

48
Q

How to search for package in the network?

A

yum search [keyword]

49
Q

How to install a package?

A

yum install [package]

50
Q

How to uninstall a package?

A

yum remove [package]

51
Q

How to install a package that we have on our system already?

A

rpm -i [path to package]

52
Q

How to check filesize? How to check disk usage?

A

filesize - du

disk usage - df

53
Q

How to copy files over the network?

A

Using either SCP (secure copy) or SFTP (ssh file transfer protocol) or ftp.
Using graphical clients: eg. Cyberduck, Filezilla.

54
Q

how to start a command in background?

A

[command] &

55
Q

How to kill a foreground process and how to suspend one?

A

ctrl-c - kill

ctrl-z - suspend

56
Q

What is a foreground process and a background process?

A

Foreground processes refer to applications you are running that you are currently interacting with, and which applies equally to graphical user interfaces as it does to the command line. Background processes refer to applications that are running but not being interacted with by the user.

57
Q

how to background a suspended process?

A

bg [%num]

58
Q

how to foreground a background process?

A

fg [%num]

59
Q

how to list jobs in linux?

A

jobs

60
Q

what’s the difference between processes and a job in linux?

A

A process is any running program. A job is something started at the command line and is attached to that shell. So, all jobs are processes, but not all processes are jobs.