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
Q

Take the countries file containing 7 countries and put them into separate files name newa-d

A

split -n 4 countries new

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

Use sed to change delsin to nathan permanently

A

sed ‘s/Kenny/Lenny’

s - substitute

sed ‘s/Kenny/Lenny/g’

g - globally

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

Remove the name nathan from the file via sed

A

sed ‘s/nathan//g’ sed

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

Delete all lines containing Nathan via sed

A

sed ‘/nathan/d’ sed

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

Delete empty lines via sed

A

sed ‘/^$/d’ seinfeld-characters

30
Q

Remove line 3 via sed

A

sed ‘3d’ sed

31
Q

Change all tabs to spaces via sed

A

sed ‘s/\t/ /g’ sed

32
Q

Show only lines 3 and 4 via sed

A

sed -n ‘3p;4p’ sed

33
Q

Show everything but lines 2 and 8 via sed

A

sed ‘2d;8d’ sed

34
Q

Put a space between every line via sed

A

sed G sed

35
Q

Except for line 1 change nathan to delsin via sed

A

sed ‘1!s/nathan/delsin/g’ sed

36
Q

Replace nathan with delsin via vim

A

:%s/nathan/delsin

37
Q

Show the calendar for december 25th 2024

A

cal 2024-12-25

38
Q

Define these terms:
Application/service
Script
Process
Daemon
Threads
Job

A

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
Q

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

A

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
Q

Most frequently used kill options

A

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
Q

kill a process by name

A

pkill sleep

42
Q

kill sleep and all it’s child processes

A

killall sleep

43
Q

What is crontabs daemon name?

Show all crontab entries

Create a crontab entry

delete all crontab entries

A

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
Q

Schedule this single job for a minute in the future:

echo “fart” > fart.txt

Afterword, show all at entries
Now remove them

A

at 12:22 PM (enter)
echo “fart” > fart.txt
(^ d)

atq

atrm 1 (number of job)

45
Q

Create a single job at 2:45 AM on Oct 16th, 2021

A

at 2:45 PM 101621

46
Q

What are all crontab directories

A

/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
Q

What is the nice scale?

A

-20 - 19
Lower the number, higher priority

48
Q

Make a sleep process
stop it
show what happened to it
send it to the background
send it back to the foreground

A

sleep 9000
^z
jobs
bg 1
fg 1

49
Q

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

A

nohup sleep 75 &

nohup sleep 75 > /dev/null 2>&1 &

nohup records everything you did.

50
Q

Run sleep and give it a nice value

A

nice -n 5 sleep 10

51
Q

Show the input and output statistics for disks and have it update every second

A

iostat 1

52
Q

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

A

netstat -rnv

53
Q

Show available memory

A

free

54
Q

show cpu and memory info

A

cat /proc/cpuinfo
cat /prco/meminfo

55
Q

show logs from system boot

A

cat /var/log/boot.log

56
Q

Where are ntp logs stored

A

cd /var/log/chrony

57
Q

view cron logs

A

cat /var/log/cron
aparantly it’s in /var/tab to??

58
Q

Show maillogs

A

cat /var/log/maillog

59
Q

Where is the hostname located?

A

/etc/hostname

60
Q

Show info on hardware - specifically cpu

A

dmidecode -t processor

61
Q

Show if your computer is 64 or 32 bit

A

arch

62
Q

Create a log that follows everything you do

A

script activity.log
exit

63
Q

Recover root password

A

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
Q

Show what the environmental variable SHELL holds

A

printenv SHELL
echo $SHELL

65
Q

Create a temporary environmental variable

A

export VAR=test

66
Q

Create a permanent environmental variable

A

make a backup just in case
cp .bashrc bahrc.backup
vi .bashrc
TEST=’123’
export TEST

67
Q

Set a permanent global variable

A

vi /etc/profile or /etc/bashrc
I think /etc/profile needs a relogin

TEST=’123’
export TEST

68
Q

Explain setuid, setgid, and stickybits

A

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
Q

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

A

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
Q

Describe the process of changing the root password when it’s forgotten

A

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
Q

Timeout a user or everyone for inactivity

A

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/