MISC 1 Flashcards
Create multiple files:
list1 - list3
touch list{1..3}
Change file permissions for user group and other in one command without using octal
chmod ug=rwx,o=1 this
change the ownership and group of this from root to a different user and group
chown
Allow files to gain the same ACL as the parent directories
setfacl -Rm u:rwx:user this
Show brief info pertaining to a command
whatis ls
if this doesn’t work you need to
mandb
what command do you use if you want to display stdout on terminal and stick it in a file
echo “Hello, world!” | tee -a this
Get the last line then the first line of a file
tail -n 1
head -n 1
Show the first third and fifth letter of each line for a file
then show this in bytes
cut -c 1,3,5 this.txt
cut -b 1,3,5 this.txt
Show every line after the 6th colon of /etc/passwd using cut
cut -d: -f 6 /etc/passwd
Delimiter is basically using : instead of space
Show only the 1st and 3rd column of ls using awk
ls -l | awk ‘{print $1,$3}’
Print the last column of ls -l
ls -l | awk ‘{print $NF}’
search for tim in /etc/passwd
only show the 3rd column
remember that each item is spaced by a colon (:) rather than a space
awk -F : ‘/tim/ {print $1}’ /etc/passwd
echo “Hello, Larry” and change larry with Nathan via awk
echo “Hello, Larry” | awk ‘{$2=”Nathan”; print=$0}’
Show only lines with 15 characters or more
awk ‘length ($0) > 15’ seinfeld-characters
If the last line of ls contains Seinfeld, print it
ls -l | awk ‘{if($NF == “seinfeld”) print $0;}’
How many number of times does Seinfeld appear in seinfeld.txt? using grep
grep -ci “seinfeld” seinfeld.txt
Show the line number and how many times Seinfeld appears in seinfeld.txt using grep
grep -ni “seinfeld” seinfeld.txt
Show everything BUT seinfeld in seinfeld.txt using grep
grep -vi “seinfeld” seinfeld.txt
Print ls -l stdout in opposite of alphabetical order on the third column and then delete duplicates
sort -k3 -r seinfeld | uniq
Order seinfeld alphabetically and then remove duplicates.
Show the amount of duplicates per item
sort seinfeld | uniq -c
Order seinfeld alphabetically and then show only the words that were duplcates
sort seinfeld | uniq -d
What are the three numbers that pop up when you use this command
wc seinfeld-characters?
-l -w -c
line
word
byte
Archive your directory, and then show what’s in it, then open it
tar cvf this.tar /home/delsin
tar tvf this.tar
tar xvf this.tar
cut a file down to 120 bytes via truncate
truncate -s 120 this.txt
Take the countries file containing 7 countries and put them into separate files name newa-d
split -n 4 countries new
Use sed to change delsin to nathan permanently
sed ‘s/Kenny/Lenny’
s - substitute
sed ‘s/Kenny/Lenny/g’
g - globally
Remove the name nathan from the file via sed
sed ‘s/nathan//g’ sed
Delete all lines containing Nathan via sed
sed ‘/nathan/d’ sed
Delete empty lines via sed
sed ‘/^$/d’ seinfeld-characters
Remove line 3 via sed
sed ‘3d’ sed
Change all tabs to spaces via sed
sed ‘s/\t/ /g’ sed
Show only lines 3 and 4 via sed
sed -n ‘3p;4p’ sed
Show everything but lines 2 and 8 via sed
sed ‘2d;8d’ sed
Put a space between every line via sed
sed G sed
Except for line 1 change nathan to delsin via sed
sed ‘1!s/nathan/delsin/g’ sed
Replace nathan with delsin via vim
:%s/nathan/delsin
Show the calendar for december 25th 2024
cal 2024-12-25
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
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
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)
kill a process by name
pkill sleep
kill sleep and all it’s child processes
killall sleep
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
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)
Create a single job at 2:45 AM on Oct 16th, 2021
at 2:45 PM 101621
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
What is the nice scale?
-20 - 19
Lower the number, higher priority
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
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.
Run sleep and give it a nice value
nice -n 5 sleep 10
Show the input and output statistics for disks and have it update every second
iostat 1
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
Show available memory
free
show cpu and memory info
cat /proc/cpuinfo
cat /prco/meminfo
show logs from system boot
cat /var/log/boot.log
Where are ntp logs stored
cd /var/log/chrony
view cron logs
cat /var/log/cron
aparantly it’s in /var/tab to??
Show maillogs
cat /var/log/maillog
Where is the hostname located?
/etc/hostname
Show info on hardware - specifically cpu
dmidecode -t processor
Show if your computer is 64 or 32 bit
arch
Create a log that follows everything you do
script activity.log
exit
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
Show what the environmental variable SHELL holds
printenv SHELL
echo $SHELL
Create a temporary environmental variable
export VAR=test
Create a permanent environmental variable
make a backup just in case
cp .bashrc bahrc.backup
vi .bashrc
TEST=’123’
export TEST
Set a permanent global variable
vi /etc/profile or /etc/bashrc
I think /etc/profile needs a relogin
TEST=’123’
export TEST
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!
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
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
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/