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
Disk space usage: display type
df -Thl
26
contents of an initramfs image
sudo lsinitrd
27
kernel ring messages
dmesg -T
28
which packages provides a tool
dnf whatprovides mkpasswd
29
search largest folder
sudo du -hax --exclude="./usr/lib" / | sort -r -h | head -30 2> /dev/null
30
copy with attributes remaining
cp -a
31
full shell login
su -l
32
count of searched words in files
grep -r SEARCHED_WORD | wc -w
33
list file names in which the searched word is found
grep -l SEARCHED_WORD
34
list active services
systemctl list-units --type=service --state=active
35
list enabled services
systemctl list-unit-files | grep enabled
36
rpm package manager | list all files in a package
rpm -ql package_name
37
rpm package manager | find package which provides a files
rpm -qf $(which kill) similar to: dnf whatprovides kill
38
print a sequence of numbers | with equal width from 0 to 10 step 2
seq -w 0 2 10
39
print a sequence of numbers | comma separated from 1 to 100 step 1
seq -s, 1 1 100
40
write consecutive numbers from 0 to 9 in two columns
seq -w 0 9 | paste - -
41
grep: invert search result
grep -v SEARCH_TERM
42
grep empty lines
grep '^$'
43
grep file content without empty lines
cat sample.txt | grep -v '^$'
44
find all files recursively in the current directory where the file's name start with "foo"
find . -name "foo*"
45
jq: return all of the elements of an array
cat example.json | jq '.[]'
46
jq: return the first element of an array
cat example.json | jq '.[0]'
47
jq: get multiple fields from the second element
cat example.json | jq '.[1] | {name: .company.name, lat: .address.geo.lat}'
48
calculate 5! on bash
echo {1..5} | tr ' ' '*' | bc
49
Find Which Process Accessing a Directory
fuser -v .
50
Find Which Process Accessing .bashrc
fuser -v -m .bashrc
51
kill a processes accessing a directory interactively
sudo fuser -ki .
52
rename .txt into .txt_log | .txt to .txt_log for all *.txt
rename .txt .txt_log *.txt
53
report a snapshot of the current processes | UNIX style, all processes, long format, full-format listing
ps -elf
54
report a snapshot of the current processes | BSD style, all processes with a terminal (tty), all processes owned by you
ps ax
55
report a snapshot of the current processes | BSD style, all processes with a terminal (tty), all processes owned by you, user-oriented format
ps aux
56
report a snapshot of the current processes | BSD style, all processes with a terminal (tty), all processes owned by you, only running processes
ps axr
57
report a snapshot of the current processes | GNU style, all processes, as tree
ps -e --forest
58
report a snapshot of the current processes | UNIX style, extra full format
``` ps -F # RSS: resident set size == used RAM ```
59
report a snapshot of the current processes | UNIX style, all processes, long format, don't show flags, show rss
``` ps -ely # RSS: resident set size == used RAM ```
60
print a process tree | UNIX style
ps -ejH
61
print a process tree | BSD style
ps axjf
62
report a snapshot of the current processes | UNIX style, info about threads
ps -eLf
63
report a snapshot of the current processes | BSD style, info about threads
ps axms
64
report a snapshot of the current processes | UNIX style, add security data
ps -eM
65
report a snapshot of the current processes | BSD style, add security data
ps axZ
66
report a snapshot of the current processes | get every process running as root (real & effective ID)
ps -U root -u root u
67
report a snapshot of the current processes | only the process IDs of syslogd
ps -C syslogd -o pid=
68
get the process IDs of sshd
pgrep sshd
69
report a snapshot of the current processes | Print only the name of PID 42
ps -q 42 -o comm=
70
display a tree of processes | show command line parameters
pstree -a
71
ping a range of ip addresses in one go
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
Edit Command Line in Your Editor
CTRL+X CTRL+E
73
remove duplicate lines
awk '!seen[$0]++' file
74
print output in columns
mount | column -t
75
print output in columns, use ":" as separator
cat /etc/passwd | column -t -s :
76
rewrite mv /tmp/working-dir/readme.md /tmp/working-dir/readme.md.backup using brace ticks
``` mv /tmp/working-dir/readme.md{,.backup} # everything in the brace gets replaced and the prefix is put in front ```
77
print the command to copy a1.txt - a9.txt to backup
echo cp a{1..9}.txt backup-dir
78
add Google public IPv4 DNS server
vi /etc/resolv.conf | nameserver 8.8.8.8
79
create a file with a random part
mktemp file_name.XXXX
80
create a directory with a random part
mktemp -p dir_name.XXXX
81
find port numbers
cat /etc/services
82
scp is replaced with rsync: | copy file 'foo.txt' to 'me@server:/home/me/'
rsync foo.txt me@server:/home/me/
83
scp is replaced with rsync: | copy folder 'bar' to 'me@server:/home/me/'
rsync -r bar/ me@server:/home/me/
84
rsync: symbolic links skipped by default | copy folder'bar' to 'me@server:/home/me/' with symlinks
rsync -r --links bar/ me@server:/home/me/ or rsync -a bar/ me@server:/home/me/
85
rsync: | copy file 'foo.txt' to 'me@server:/home/me/' and specify a non-ssh port (8022)
``` rsync -e 'ssh -p 8022' foo.txt me@server:/home/me/ or update the ~/.ssh/config file: Host server Port 8022 ```
86
journalctl: | Jump to the end of the journal (-e), and enable follow mode (-f)
journalctl -ef
87
journalctl: | filter for a unit
journalctl _SYSTEMD_UNIT=sshd.service
88
journalctl: | display all messages generated by, and about, the sshd.service systemd unit
journalctl -u sshd.service
89
journalctl: | all messages in the journal with a priority in the range emerg up to and including err
journalctl -p emerg..err
90
journalctl: | all messages up to and including that level are displayed
journalctl -p err
91
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.
on Centos journalctl -b -1 #on Debian journalctl -b
92
journalctl: | with start and end date
journalctl --since "2015-02-02 20:30:00" --until "2015-03-31 12:00:00"
93
journalctl: | verbose
journalctl -o verbose
94
journalctl: | check
journalctl --verify
95
journalctl: | enable user to read log entries
sudo usermod -aG systemd-journal BENUTZERNAME
96
journalctl: | in UTC
journalctl --utc
97
journalctl: | list boots
journalctl --list-boots
98
journalctl: | by PID
journalctl _PID=8088
99
journalctl: | kernel messages
journalctl -k
100
journalctl: | by priority
``` journalctl -p err # 0: emerg # 1: alert # 2: crit # 3: err # 4: warning # 5: notice # 6: info # 7: debug ```
101
journalctl: | print all to stdout
journalctl --no-pager
102
journalctl: | as json
journalctl -o json | journalctl -o json-pretty
103
journalctl: | only 20 log entries
journalctl -n 20
104
journalctl: | disk usage
journalctl --disk-usage
105
journalctl: | shrink by size
journalctl --vacuum-size=1G
106
journalctl: | shrink since
journalctl --vacuum-time=1years
107
linux namespace types
``` 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
how to get the return code of a program ran in the shell?
echo $?