Basics Flashcards

1
Q

View Specific Disk Partition

A

fdisk -l /dev/sda

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

View all Disk Partitions

A

fdisk -l

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

Find Out Top File Sizes

A

find -type f -exec du -Sh {} + | sort -rh | head -n 5

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

Disk space usage: Exclude Certain File System Type

A

df -x ext3

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

Disk space usage: Display Certain File System Type

A

df -t xfs

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

Display File System Inodes

A

df -i

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

File space usage: grand total for each argument

A

du -ch

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

File space usage: summary of a grand total disk usage size

A

du -sh

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

File space usage: displays the number of disk blocks

A

du

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

list running services

A

systemctl list-units --type=service --state=running

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

rpm package manager
query all packages

A

rpm -qa

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

kernel parameters

A

sysctl -a

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

display the largest folders/files including the sub-directories

A

du -Sh | sort -rh | head -5

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

how to handle this:
> $ sudo echo ‘127.0.0.1 bob’&raquo_space; /etc/hosts
zsh: permission denied: /etc/hosts

A

> $ echo ‘127.0.0.1 bob’ | sudo tee -a /etc/hosts
[sudo] password for gludwig:
127.0.0.1 bob

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

all Available fdisk Commands

A

fdisk /dev/sda

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

rsync: Count files recursively through directories

A

rsync –stats –dry-run -ax /etc /test

rsync –stats –dry-run -ax .

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

all File System Disk Space Usage

A

df -a

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

compile options

A

cat /boot/config-$(uname -r)

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

loaded kernel modules

A

lsmod
is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.

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

generate password having length 64

A

mkpasswd -l 64

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

Find Top 15 Processes by Memory Usage

A

top -b -o +%MEM | head -n 22

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

cat | cut

A

cat report.csv |cut -f 5-11,13- -d’,’ > cleanreport.csv

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

cat | sudo tee

A

cat

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

> new_file

A

> new_file
text text
^C

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

Disk space usage: display type

A

df -Thl

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

contents of an initramfs image

A

sudo lsinitrd

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

kernel ring messages

A

dmesg -T

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

which packages provides a tool

A

dnf whatprovides mkpasswd

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

search largest folder

A

sudo du -hax –exclude=”./usr/lib” / | sort -r -h | head -30 2> /dev/null

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

copy with attributes remaining

A

cp -a

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

full shell login

A

su -l

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

count of searched words in files

A

grep -r SEARCHED_WORD | wc -w

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

list file names in which the searched word is found

A

grep -l SEARCHED_WORD

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

list active services

A

systemctl list-units –type=service –state=active

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

list enabled services

A

systemctl list-unit-files | grep enabled

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

rpm package manager

list all files in a package

A

rpm -ql package_name

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

rpm package manager

find package which provides a files

A

rpm -qf $(which kill)
similar to:
dnf whatprovides kill

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

print a sequence of numbers

with equal width from 0 to 10 step 2

A

seq -w 0 2 10

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

print a sequence of numbers

comma separated from 1 to 100 step 1

A

seq -s, 1 1 100

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

write consecutive numbers from 0 to 9 in two columns

A

seq -w 0 9 | paste - -

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

grep: invert search result

A

grep -v SEARCH_TERM

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

grep empty lines

A

grep ‘^$’

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

grep file content without empty lines

A

cat sample.txt | grep -v ‘^$’

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

find all files recursively in the current directory where the file’s name start with “foo”

A

find . -name “foo*”

45
Q

jq: return all of the elements of an array

A

cat example.json | jq ‘.[]’

46
Q

jq: return the first element of an array

A

cat example.json | jq ‘.[0]’

47
Q

jq: get multiple fields from the second element

A

cat example.json | jq ‘.[1] | {name: .company.name, lat: .address.geo.lat}’

48
Q

calculate 5! on bash

A

echo {1..5} | tr ‘ ‘ ‘*’ | bc

49
Q

Find Which Process Accessing a Directory

A

fuser -v .

50
Q

Find Which Process Accessing .bashrc

A

fuser -v -m .bashrc

51
Q

kill a processes accessing a directory interactively

A

sudo fuser -ki .

52
Q

rename .txt into .txt_log

.txt to .txt_log for all *.txt

A

rename .txt .txt_log *.txt

53
Q

report a snapshot of the current processes

UNIX style, all processes, long format, full-format listing

A

ps -elf

54
Q

report a snapshot of the current processes

BSD style, all processes with a terminal (tty), all processes owned by you

A

ps ax

55
Q

report a snapshot of the current processes

BSD style, all processes with a terminal (tty), all processes owned by you, user-oriented format

A

ps aux

56
Q

report a snapshot of the current processes

BSD style, all processes with a terminal (tty), all processes owned by you, only running processes

A

ps axr

57
Q

report a snapshot of the current processes

GNU style, all processes, as tree

A

ps -e –forest

58
Q

report a snapshot of the current processes

UNIX style, extra full format

A
ps -F   
# RSS: resident set size == used RAM
59
Q

report a snapshot of the current processes

UNIX style, all processes, long format, don’t show flags, show rss

A
ps -ely
# RSS: resident set size == used RAM
60
Q

print a process tree

UNIX style

A

ps -ejH

61
Q

print a process tree

BSD style

A

ps axjf

62
Q

report a snapshot of the current processes

UNIX style, info about threads

A

ps -eLf

63
Q

report a snapshot of the current processes

BSD style, info about threads

A

ps axms

64
Q

report a snapshot of the current processes

UNIX style, add security data

A

ps -eM

65
Q

report a snapshot of the current processes

BSD style, add security data

A

ps axZ

66
Q

report a snapshot of the current processes

get every process running as root (real & effective ID)

A

ps -U root -u root u

67
Q

report a snapshot of the current processes

only the process IDs of syslogd

A

ps -C syslogd -o pid=

68
Q

get the process IDs of sshd

A

pgrep sshd

69
Q

report a snapshot of the current processes

Print only the name of PID 42

A

ps -q 42 -o comm=

70
Q

display a tree of processes

show command line parameters

A

pstree -a

71
Q

ping a range of ip addresses in one go

A

for ((i=1;i<10;i++)); do ping -c 1 -w 1 8.$i.8.8 &> /dev/null && echo 8.$i.8.8 is alive; done

72
Q

Edit Command Line in Your Editor

A

CTRL+X CTRL+E

73
Q

remove duplicate lines

A

awk ‘!seen[$0]++’ file

74
Q

print output in columns

A

mount | column -t

75
Q

print output in columns, use “:” as separator

A

cat /etc/passwd | column -t -s :

76
Q

rewrite mv /tmp/working-dir/readme.md /tmp/working-dir/readme.md.backup using brace ticks

A
mv /tmp/working-dir/readme.md{,.backup}
# everything in the brace gets replaced and the prefix is put in front
77
Q

print the command to copy a1.txt - a9.txt to backup

A

echo cp a{1..9}.txt backup-dir

78
Q

add Google public IPv4 DNS server

A

vi /etc/resolv.conf

nameserver 8.8.8.8

79
Q

create a file with a random part

A

mktemp file_name.XXXX

80
Q

create a directory with a random part

A

mktemp -p dir_name.XXXX

81
Q

find port numbers

A

cat /etc/services

82
Q

scp is replaced with rsync:

copy file ‘foo.txt’ to ‘me@server:/home/me/’

A

rsync foo.txt me@server:/home/me/

83
Q

scp is replaced with rsync:

copy folder ‘bar’ to ‘me@server:/home/me/’

A

rsync -r bar/ me@server:/home/me/

84
Q

rsync: symbolic links skipped by default

copy folder’bar’ to ‘me@server:/home/me/’ with symlinks

A

rsync -r –links bar/ me@server:/home/me/
or
rsync -a bar/ me@server:/home/me/

85
Q

rsync:

copy file ‘foo.txt’ to ‘me@server:/home/me/’ and specify a non-ssh port (8022)

A
rsync -e 'ssh -p 8022' foo.txt me@server:/home/me/
or
update the ~/.ssh/config file:
Host server
    Port 8022
86
Q

journalctl:

Jump to the end of the journal (-e), and enable follow mode (-f)

A

journalctl -ef

87
Q

journalctl:

filter for a unit

A

journalctl _SYSTEMD_UNIT=sshd.service

88
Q

journalctl:

display all messages generated by, and about, the sshd.service systemd unit

A

journalctl -u sshd.service

89
Q

journalctl:

all messages in the journal with a priority in the range emerg up to and including err

A

journalctl -p emerg..err

90
Q

journalctl:

all messages up to and including that level are displayed

A

journalctl -p err

91
Q

journalctl:
Only show messages from the last system boot.
This is useful for searching for information about a system crash. This requires a persistent journal to be configured.

A

on Centos
journalctl -b -1
#on Debian
journalctl -b

92
Q

journalctl:

with start and end date

A

journalctl –since “2015-02-02 20:30:00” –until “2015-03-31 12:00:00”

93
Q

journalctl:

verbose

A

journalctl -o verbose

94
Q

journalctl:

check

A

journalctl –verify

95
Q

journalctl:

enable user to read log entries

A

sudo usermod -aG systemd-journal BENUTZERNAME

96
Q

journalctl:

in UTC

A

journalctl –utc

97
Q

journalctl:

list boots

A

journalctl –list-boots

98
Q

journalctl:

by PID

A

journalctl _PID=8088

99
Q

journalctl:

kernel messages

A

journalctl -k

100
Q

journalctl:

by priority

A
journalctl -p err
# 0: emerg
# 1: alert
# 2: crit
# 3: err
# 4: warning
# 5: notice
# 6: info
# 7: debug
101
Q

journalctl:

print all to stdout

A

journalctl –no-pager

102
Q

journalctl:

as json

A

journalctl -o json

journalctl -o json-pretty

103
Q

journalctl:

only 20 log entries

A

journalctl -n 20

104
Q

journalctl:

disk usage

A

journalctl –disk-usage

105
Q

journalctl:

shrink by size

A

journalctl –vacuum-size=1G

106
Q

journalctl:

shrink since

A

journalctl –vacuum-time=1years

107
Q

linux namespace types

A
UTS:  Hostname and NIS domain name
Cgroup: Controls the system resources (like CPU, Memory…) the process can use.
IPC: POSIX message queues
Network: Network devices, stacks, ports, etc.
Mount: Mount points
PID: Process IDs
Time: Boot and monotonic clocks
User: User and group IDs
108
Q

how to get the return code of a program ran in the shell?

A

echo $?