MISC 1 Flashcards

1
Q

Create multiple files:
list1 - list3

A

touch list{1..3}

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

Change file permissions for user group and other in one command without using octal

A

chmod ug=rwx,o=1 this

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

change the ownership and group of this from root to a different user and group

A

chown

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

Allow files to gain the same ACL as the parent directories

A

setfacl -Rm u:rwx:user this

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

Show brief info pertaining to a command

A

whatis ls

if this doesn’t work you need to
mandb

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

what command do you use if you want to display stdout on terminal and stick it in a file

A

echo “Hello, world!” | tee -a this

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

Get the last line then the first line of a file

A

tail -n 1
head -n 1

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

Show the first third and fifth letter of each line for a file
then show this in bytes

A

cut -c 1,3,5 this.txt
cut -b 1,3,5 this.txt

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

Show every line after the 6th colon of /etc/passwd using cut

A

cut -d: -f 6 /etc/passwd

Delimiter is basically using : instead of space

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

Show only the 1st and 3rd column of ls using awk

A

ls -l | awk ‘{print $1,$3}’

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

Print the last column of ls -l

A

ls -l | awk ‘{print $NF}’

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

search for tim in /etc/passwd
only show the 3rd column
remember that each item is spaced by a colon (:) rather than a space

A

awk -F : ‘/tim/ {print $1}’ /etc/passwd

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

echo “Hello, Larry” and change larry with Nathan via awk

A

echo “Hello, Larry” | awk ‘{$2=”Nathan”; print=$0}’

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

Show only lines with 15 characters or more

A

awk ‘length ($0) > 15’ seinfeld-characters

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

If the last line of ls contains Seinfeld, print it

A

ls -l | awk ‘{if($NF == “seinfeld”) print $0;}’

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

How many number of times does Seinfeld appear in seinfeld.txt? using grep

A

grep -ci “seinfeld” seinfeld.txt

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

Show the line number and how many times Seinfeld appears in seinfeld.txt using grep

A

grep -ni “seinfeld” seinfeld.txt

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

Show everything BUT seinfeld in seinfeld.txt using grep

A

grep -vi “seinfeld” seinfeld.txt

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

Print ls -l stdout in opposite of alphabetical order on the third column and then delete duplicates

A

sort -k3 -r seinfeld | uniq

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

Order seinfeld alphabetically and then remove duplicates.
Show the amount of duplicates per item

A

sort seinfeld | uniq -c

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

Order seinfeld alphabetically and then show only the words that were duplcates

A

sort seinfeld | uniq -d

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

What are the three numbers that pop up when you use this command
wc seinfeld-characters?

A

-l -w -c
line
word
byte

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

Archive your directory, and then show what’s in it, then open it

A

tar cvf this.tar /home/delsin
tar tvf this.tar
tar xvf this.tar

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

cut a file down to 120 bytes via truncate

A

truncate -s 120 this.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Take the countries file containing 7 countries and put them into separate files name newa-d
split -n 4 countries new
26
Use sed to change delsin to nathan permanently
sed 's/Kenny/Lenny' s - substitute sed 's/Kenny/Lenny/g' g - globally
27
Remove the name nathan from the file via sed
sed 's/nathan//g' sed
28
Delete all lines containing Nathan via sed
sed '/nathan/d' sed
29
Delete empty lines via sed
sed '/^$/d' seinfeld-characters
30
Remove line 3 via sed
sed '3d' sed
31
Change all tabs to spaces via sed
sed 's/\t/ /g' sed
32
Show only lines 3 and 4 via sed
sed -n '3p;4p' sed
33
Show everything but lines 2 and 8 via sed
sed '2d;8d' sed
34
Put a space between every line via sed
sed G sed
35
Except for line 1 change nathan to delsin via sed
sed '1!s/nathan/delsin/g' sed
36
Replace nathan with delsin via vim
:%s/nathan/delsin
37
Show the calendar for december 25th 2024
cal 2024-12-25
38
Define these terms: Application/service Script Process Daemon Threads Job
Application/service - Word/NTP/Apache Script - List of instructions/applications/commands - all commands we've run are technically scripts Process - instance of a program that is currently executing on the system. Daemon - Continuously runs in background Thread - each thread shares the same memory space and resources as the parent process. (EX: One computer connecting to NFS creates one thread/ Another is created when another computer connects to NFS) Job - Created for a scheduled time
39
while in top show: only root processes processes full name by memory by cpu by cpu time by start time sort by PID change time/frequency updated
u root - see this user c - process full name A - start time M - Memory N - PID P - CPU T - TIME+ d 1 - change update time to 1 second
40
Most frequently used kill options
kill 1234 (kill PID 1234) kill -1 restart (sighup) kill -2 Interupt (like ^ C) (sigint) kill -9 Force kill (sigkill) kill -15 Kill a process like a gentleman (sigterm)
41
kill a process by name
pkill sleep
42
kill sleep and all it's child processes
killall sleep
43
What is crontabs daemon name? Show all crontab entries Create a crontab entry delete all crontab entries
crond crontab -l crontab -e 30 01 05 01 * echo "this" /home/delsinm/this.txt crontab -r In the past if I had to set to a new timezone I had to restart crond, otherwise it wouldn't work
44
Schedule this single job for a minute in the future: echo "fart" > fart.txt Afterword, show all at entries Now remove them
at 12:22 PM (enter) echo "fart" > fart.txt (^ d) atq atrm 1 (number of job)
45
Create a single job at 2:45 AM on Oct 16th, 2021
at 2:45 PM 101621
46
What are all crontab directories
/etc/con.hourly /etc/cron.d/0hourly /etc/con.daily /etc/con.weekly /etc/con.monthly hourly is for scripts ran at the top of the hour while 0hourly is for scripts ran every hour with different minute intervals
47
What is the nice scale?
-20 - 19 Lower the number, higher priority
48
Make a sleep process stop it show what happened to it send it to the background send it back to the foreground
sleep 9000 ^z jobs bg 1 fg 1
49
When you close a terminal that was running a process, the process closes. How do we continue running a process even after closing the terminal? Send the warnings to the void
nohup sleep 75 & nohup sleep 75 > /dev/null 2>&1 & nohup records everything you did.
50
Run sleep and give it a nice value
nice -n 5 sleep 10
51
Show the input and output statistics for disks and have it update every second
iostat 1
52
Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships Show condensed and easy to read ip info aside from ifconfig or ipaddr
netstat -rnv
53
Show available memory
free
54
show cpu and memory info
cat /proc/cpuinfo cat /prco/meminfo
55
show logs from system boot
cat /var/log/boot.log
56
Where are ntp logs stored
cd /var/log/chrony
57
view cron logs
cat /var/log/cron aparantly it's in /var/tab to??
58
Show maillogs
cat /var/log/maillog
59
Where is the hostname located?
/etc/hostname
60
Show info on hardware - specifically cpu
dmidecode -t processor
61
Show if your computer is 64 or 32 bit
arch
62
Create a log that follows everything you do
script activity.log exit
63
Recover root password
reboot Stop at the menu that shows the recovery mode and standard (should be the top one) press e to edit after rhgb quite: rd.break ^x mount -o remount,rw /sysroot chroot /sysroot passwd root touch /.autorelabel exit exit
64
Show what the environmental variable SHELL holds
printenv SHELL echo $SHELL
65
Create a temporary environmental variable
export VAR=test
66
Create a permanent environmental variable
make a backup just in case cp .bashrc bahrc.backup vi .bashrc TEST='123' export TEST
67
Set a permanent global variable
vi /etc/profile or /etc/bashrc I think /etc/profile needs a relogin TEST='123' export TEST
68
Explain setuid, setgid, and stickybits
THESE BITS ONLY WORK ON C EXECUTABLE AND NOT SHELL SCRIPTS setuid - the root user made the process/application but anyone that attempts to run it will run it as root, or whatever user initially made it setgid -The setgid affects both files as well as directories. When used on a file, it executes with the privileges of the group of the user who owns it instead of executing with those of the group of the user who executed it. When the bit is set for a directory, the set of files in that directory will have the same group as the group of the parent directory, and not that of the user who created those files. This is used for file sharing since they can be now modified by all the users who are part of the group of the parent directory. Finally, the sticky bit makes it to where only the user that created the file/directory can delete it. This must be placed on the directory and not the file!
69
1) Become root user 2) Create a directory called Animals 3) Create Animals group add users to Animals group then make the Animals directory group Animals. At this point, your users should be able to enter the directory if the group has execute capabilities. 4) You want group members to create files that they can all access since normally if a group member creates a file it will just be in their personal group. Change this to where it will be accessible for all users and make it's group always Animals 5) You don't want to let the other members be able to delete files one another has created aside from the owner who created initially, make it so. 6) Create an executable file as root that allows all users to use as root. (ONLY WORKS ON C NOT SHELL SCRIPTS) 7) Lastly, remove all of your special bits
su mkdir Animals groupadd Animals usermod -aG Animals delsinm chgrp Animals Animals chmod g+s Animals chmod o+t Animals cd Animals touch executable chmod u+s executable chmod u-s executable cd .. chmod o-t,g-s Animals
70
Describe the process of changing the root password when it's forgotten
rd.break - this will break off to the ram disk, this will drop you to where before the root filesystem is mounted ( the system locates that info in /etc/fstab. /sysroot will contain the filesystem for the time being but it's read only so: mount -o remount/rw /sysroot this just makes it to where we can modify the filesystem now that we have rw permission chroot /sysroot Your root directory is set to / by default, but since the filesystem is on /sysroot now, we'll want to change that root directory over to /sysroot
71
Timeout a user or everyone for inactivity
Time delsin's ssh session out at 5 seconds vi .bashrc TMOUT=5 source ~/.bashrc You can also do this in /etc/bashrc https://ostechnix.com/auto-logout-inactive-users-period-time-linux/