W1: Linux Introduction Flashcards
- Research: Computing Machines
a machine that can recieve an input, and automatically process it into an ouptput. Like the turing machine.
- Research: Turing Machine
‘the blueprint of modern computing’. Initially just a theoretical idea of a device that, when given a tape of whatever needed length of 1s and 0s, reads the tape and changes the 1s and 0s in accordance with its instructions. the tape of 1s and 0s starts as a question, and when the turing machine is finished with it, becomes the answer.
- Research: Von-Neumann Architechture
computer model designed by John Von-Neumann in 1945.
Input -> Memory -> Output
V> Processor (Control Unit <->Arithmetic Logic Unit)
Input is stored as command in Memory,
Processor fetches the commend from Memory,
Control Unit manages commands and input/output,
ALU handles the actual calculations,
CU stores complete commands in memory,
then output is displayed.
- Research: Operating System
program that allows a user to interact with the computer.
- Research: History of Linux
developed by Linus Torvalds.
started in 1991 as a pet project,
became community open source project
Linux 1.0.0 launched in 1994
- Research: What is Linux?
open source Operating System. Actually even Android is based in Linux
- CPU
The component of a computer system that controls the interpretation and execution of instructions. The CPU of a PC consists of a single microprocessor, while the CPU of a more powerful mainframe consists of multiple processing devices, and in some cases, hundreds of them.
- CPU cache
Store temporary files, using hardware and software components. An example of a hardware cache is a CPU cache. This is a small chunk of memory on the computer’s processor used to store basic computer instructions that were recently used or are frequently used.; that’s why it is faster.
- RAM
Form of computer memory that can be read and changed in any order, typically used to store working data and machine code.
- ROM
EPROM
Read-only memory is a type of non-volatile memory used in computers and other electronic devices. Data stored in ROM cannot be electronically modified after the manufacture of the memory device.
EPROM can be erased when exposed to certian ultraviolets.
Eraseable Programmable, read only memory.
- BIOS
a set of computer instructions in firmware which control input and output operations.
- Bus (address, data, control)
Bus: Circuits on the motherboard that connects the CPU to other components.
Address: single-directional, transports address signals from CPU to main memory
Data: Bi-directional, transports data between components.
Control: bi-directional, sends control signals (clock timings, interrupt requests) between components.
(CPU sends addresses to memory and I/O controller, but memory and I/O controller only respond with data and control signals)
- Hard disk
Data storage device using to read and write data onto a rotating disk coated with magnetic material.
- I/O device
secondary storage, keyboard, mouse, monitors, printers, any external device that could send input or recieve output.
- File system
The way in which files are named and placed logically for storage and retrieval.
- Program
A (passive) set of code and instructions meant to complete a task.
- Process
a running (active) instance of a program.
- USB
Universal Serial Bus
technology used to connect computers with peripheral devices
- Serial Port
a connector by which a device that sends data one bit at a time may be connected to a computer. (monitor port)
- Parallel port
a connector for a device that sends or receives several bits of data simultaneously by using more than one wire.
looks like the wider RS-232
- RS-232
Form of Serial Data transmission, or ‘Serial Connection’. (USB is also serial)
the type of connection.
delivers data as voltage signals.
- (U)EFI
UEFI is a set of specifications written by the UEFI Forum. They define the architecture of the platform firmware used for booting and its interface for interaction with the operating system. uses C, BIOS didn’t have C.
actively replacing BIOS
can be improved with the C support. has the option to increase home much disk space it uses.
- Boot Loader
a program that loads an operating system when a computer is turned on.
computer program responsible for booting a computer. When computer turns off, its software—operating systems, application code, and data—remains stored on non-volatile memory.
UEFI and BIOS are boot loaders, sorta.
- GRUB/LILO
GRUB: new boot loader with multi-OS device management. supports Windows, Linux, UNIX, macOS, BSD, and Solaris.
LILO: older boot loader with single OS device management. Only supports Linux.
- ATAPI
Advanced Technology Attatchment Packet Interface
ATA Packet Interface is a protocol that has been added to Parallel ATA and Serial ATA so that a greater variety of devices can be connected to a computer than with the ATA command set alone. It carries SCSI commands and responses through the ATA interface.
connection protocol, for wider variety of device connection, including SATA
- SATA
Serial Advanced Technology Attachment
refers to a type of connector cable that is used to attach components, like hard drives, to a motherboard. A solid-state drive (SSD) is a type of storage drive that allows for very fast read and write speeds. Comparing the drive type with a type of connector cable does not really make sense.
connection protocol for storage devices and others
- Master boot record
The Master Boot Record (MBR) is the information in the first sector of a hard disk or a removable drive.
Identifies how and where the system’s operating system (OS) is located in order to be booted (loaded) into the computer’s main storage or random access memory (RAM).
- Binary / octal / hex
…really?
the 1s and 0s, or rather numerical representation of data written in base 2, to be interpretted as true/falses as machine language.
octal is the base 8 representation of binary, or otherwise just base 8 numerology.
hex is the same but at base 16.
- MTBF
Mean time between failures (MTBF)
The average time between system breakdowns. Crucial maintenance metric to measure performance, safety, and equipment design, especially for critical or complex assets like generators or airplanes.
- Swap file
What is a swap file (swap space or page file)? A swap file is a system file that creates temporary storage space on a solid-state drive or hard disk when the system runs low on memory. The file swaps a section of RAM storage from an idle program and frees up memory for other programs.
A swap file allows Linux to simulate the disk space as RAM. When your system starts running out of RAM, it uses the swap space to and swaps some content of the RAM on to the disk space. This frees up the RAM to serve more important processes. When the RAM is free again, it swaps back the data from the disk.
- Virtual memory
Common technique used in a computer’s operating system. Uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random access memory (RAM) to disk storage.
- inode
file data structure that stores information about any Linux file except its name and data.
keep track of all the files on a Linux system. Except for the file name and the actual content of the file, inodes save everything else.
- ASCII table
ASCII, in full American Standard Code for Information Interchange, a standard data-encoding format for electronic communication between computers. ASCII assigns standard numeric values to letters, numerals, punctuation marks, and other characters used in computers.
limited to 128
- Unicode
Worldwide character encoding standard.
- wchar
wchar_t: 16-bit wide character used to store Unicode encoded as UTF-16LE. native character type on windows operating systems.
- UTF-7/8
both types of Unicode Transformation Format, the standard used to encode 16-bit Unicode characters such as international letters and special symbols in a format that can be transmitted through 7-bit or 8-bit systems.
- POSIX
What is POSIX in computer?
POSIX (Portable Operating System Interface) is a set of standard operating system interfaces based on the Unix operating system.
family of standards specified by IEEE for maintaining compatibility among operating systems. Therefore, any software that conforms to POSIX standards should be compatible with other operating systems that adhere to the POSIX standards.
- GNU
GNU’s Not Unix
GNU is a Unix-like operating system. That means it is a collection of many programs: applications, libraries, developer tools, even games. The development of GNU, started in January 1984, is known as the GNU Project.
- IP / TCP / UDP
TCP/IP is a stream-oriented protocol, while UDP is a packet-oriented protocol. This means that TCP/IP is considered to be a long stream of data that is transmitted from one end of the connection to the other end, and another long stream of data flowing in the opposite direction.
TCP: fast, but potential packet losses.
IP is safer, slower, but certian to reach the destination.
UDP can be used for every type of application that TCP can, as long as you also implement a proper retransmission mechanism. s
- Kernel
The kernel, or system core, ensures the smooth running of the operating system within a computer and is the interface between the software and the hardware. It is used in all devices with an operating system, for example, computers, laptops, smartphones, smartwatches, etc.
- System call
A system call is a routine that allows a user application to request actions that require special privileges. Adding system calls is one of several ways to extend the functions provided by the kernel.
create, delete, open, close, read, write,
- Waterfall
The waterfall model is a breakdown of project activities into linear sequential phases, meaning they are passed down onto each other
- Scrum
Scrum is a framework for project management that emphasizes teamwork, accountability and iterative progress toward a well-defined goal. The framework begins with a simple premise: Start with what can be seen or known. After that, track the progress and tweak, as necessary.
- Agile development
Agile is an iterative approach to project management and software development that helps teams deliver value to their customers faster and with fewer headaches. Instead of betting everything on a “big bang” launch, an agile team delivers work in small, but consumable, increments.
- File system: NTFS
New Technology File System:
Process that the Windows NT operating system uses for storing, organizing, and finding files on a hard disk efficiently. NTFS was first introduced in 1993, as apart of the Windows NT 3.1 release.
- File system: NFS
The Network File System (NFS) is a mechanism for storing files on a network. It is a distributed file system that allows users to access files and directories located on remote computers and treat those files and directories as if they were local.
- File System: FAT-16/32
The FAT32 file system cannot store individual files larger than 4 GB, while the NTFS file system can. Compared to FAT32, the NTFS file system has higher disk utilization and can manage disk space more effectively. The read and write speeds of NTFS are also faster than that of FAT32.
- File System: JFS
Journaled File System (JFS) is a 64-bit journaling file system created by IBM.
The “journaled” aspect of JFS means that the file system keeps tracks of changes to files and folders in a log file (or journal). This log can be used to backtrack certain changes in case of an unexpected power failure or system crash, which may prevent data corruption
- File System: ext4
Fourth extended file system, is a journaling file system for Linux. ext4’s most common use case is formatting volumes, hard drives, and other computing storage solutions. ext4 is the default file system for DigitalOcean Volumes Block Storage due to its stability and backwards compatibility.
Ext4 has better journaling capabilities and a higher maximum supported size of 1 exbibyte, while ExFAT is compatible with both Windows and MacOSX operating systems up to 16 exbibytes in size
- Disk Partition: Primary
Primary partition is a bootable partition and it contains the operating system/s of the computer, while logical partition is a partition that is not bootable. Multiple logical partitions allow storing data in an organized manner
- Disk Partition: Extended
A partition that can be divided into additional logical drives.
- Disk Partition: Logical
A logical partition can be formatted and assigned a drive letter. A logical partition must be created inside an extended partition.
If an extended partition does not already exist on the disk or the specified size of the logical drive exceeds the extended partition, no partition is created
gets past the 4 bootable drives limit. can help divide the disk into different file systems for logical organization.
1 apt-get update
checks for Ubuntu updates and installs them
- install SSH, Valgrind, htop, Ubuntu-restricted-extras, and Parcellite
sudo apt install openssh-client
sudo apt-get install openssh-client
apt search valgrind
sudo apt install valgrind
sudo apt install htop
sudo apt install ubuntu-restricted-extras
sudo apt-get install parcellite
- What are the sections of the manual? List and describe them.
1 General commands: commands used in the terminal
2 System calls: functions provided by the kernel
3 Library Functions: Functions in program libraries
4 Special files: usually devices in /dev and related drivers
5 file formats and conventions: file formats like etc/passwd
6 games: descriptions of commands that display database quotes
7: Miscellaneous: macro packages and conventions, boot parameters, and other things
8: System administation commands: commands mostly reserved for root
9: Kernel Routines: information about internal kernel operations
NAME - command name
SYNOPSIS - command structure
DESCRIPTION - comman’s description
OPTIONS - available command options
AUTHOR - command’s author
REPORTING BUGS - instructions on how to report bugs to developer
COPYRIGHT - command’s license info
SEE ALSO - points to related commands and full documentation
CONFIGURATION - configuration details for command/device
EXIT STATUS - possible exit status values
- Which sections of the manual contain a command write?
man -f write //searches for the page/section where the command is
outputs: write (1), and write(2)
- Create a C program that prints hello world and the main() function’s argv and envp arguments. Place it under your home directory.
- deleted?
mv a.out
…something
- when there is more than one date in the file system, how do you know which will run
mv something.out date
whichever is located in the local file from which the terminal is running.
whichever appears first on the PATH
- when would you use which and type
which: finds excecutable in your PATH
type determines of command is alias, function, build-in-command, cached excecuteable, etc.
type is a shell built-in, wouldn’t be found by which
preferable to use type, al
- Name three bash config files. when does each of them run?
/etc/profile : system wide initialisation, executed during login
/etc/bashrc : another system wide init file. executed every time bash shell is opened by a user.
~/.bash_profile : if exists, executed after /etc/profile during login
~/.bash_login : executed instead of ~/.bash_profile otherwise.
~/.profile : executed if either bash_profile nor bash_login exist during login.
~./bashrc : contains specific configs. read at login and each time a new Bash sehll is started. put aliases here.
~/.bash_logout : executed during logout
~/.inputrc : used to customize key bindings/key strokes
- Edit the environment variable PATH to run executables which are located in the current directory.
It would be a good idea to add the current directory to the end of the PATH. why?
in which file would you put this change?
echo $PATH
pwd //checks current directory //let’s say /home/daniel
export PATH=/home/daniel:$PATH
adding directories to the PATH makes it easier to call files within them from any other directory, without having to list out the directory path individually.
making a permanent cheange: affects the ~/.bashrc file
nano ~/.bashrc
export PATH=$PATH:the/file/path
- What happens to SHLVL when you run a shell within a shell? What happens when you exit the shell? Hint: look at ps – forest and ps -l.
the shell level gets ‘higher’, or rather deeper as we cause subshells within subshells
- write an alias to remove files ending with ~ from the current directory
alias rt~=’rm -r *~’
you can delete a file… but not the items within it
./*~
- In which file would you place an alias so that you have it when you start a new bash?
in ~/.bashrc
- Create a shell function that checks if a file exists. if it does, then copy it to /tmp
!/bin/sh
FILE=1
echo “please enter file name.”
read FILE
if test -f “$FILE”; then
cp “$FILE” tmp/”$FILE”
fi
- Add if/else, do/while and for constructs to the shell script for more functionality, including the ability to copy multiple files at once
!/bin/sh
FILE=”lol”
while [[ “$FILE” != “finish” ]]
do
echo “please enter file name. Enter ‘finish’ if you wish to abort”
read FILE
if test -f “$FILE”; then
cp “$FILE” /tmp/”$FILE”;
fi
done
- What happens to the files and directories in /tmp when you reboot?
oops they get deleted,
otherwise deleted after 10 days.(?)
- What is ulimit used for? Why would you use it for a core file?
ulimit is a program that lets you define file size limits for the shell and its sub-processes.
affects how many resources are spent on maintaining core files/errors. (imagine crashing 100 times)
core files help understand why programs terminate unexpectidly, which means they assist in big fixing. increasing core file ulimit helps get a bigger picture of a problem.
can set ulimit to 0 and then just not know why everything is on fire.
18 what happens when you cat a text file into /dev/tty? When you cat /dev/tty? (You may find ^C and ^D useful)
dev tty just replicates inputs;
tty= terminal type. it’s responsible for terminal typing all-the-same.
- what does set do?
displays and sets the names and values of shell and linux environment variables
- From your terminal, login to another computer and run gedit on a file in /tmp. ensure that the window that opens is on your computer, and not the remote computer
sudo apt-get install openssh-server ii.
^install openssh_server
ssh localhost
sh your_username@host_ip_address / sh daniel@host_ip_address
^ connect to
-X
- Who is currently logged into your system?
who
who -b
- when was the last time the machine was rebooted?
last reboot
- what is the IP address of your computer?
can run ip addr
ip a
fconfig
- How can you see the usage of the computer’s resources?
top
top -i //hides idle resources
- compare the output of top and htop. What is the correlation, if any, between them?
htop is more interactive, colorful, slightly better ui.
- How do you set the clock on your computer? why would you not do this?
sudo timedatectl set-time hh:mm:ss
several programs and websites will refuse to function if your machine clock is innacurate.
- Write a shell script that records the current time to a file in /tmp
!/bin/sh
touch “/tmp/date.txt”;
echo $(date)»_space; “/tmp/date.txt”;
- How long does it take to list all the files in the file system?
time -ls -m
- What options are there for editing and re-running previous commands in the shell?
you use the up and down arrows to cycle through previous commands,
!! // repeats the last command,
fc - s
CTRL+P
- What is the difference between crontab, at and batch
at: deliberately notices PATH and environment variables and sets them in place when the command runs.
cron: has its own seperate environment. cron sets the PATH to PATH=:/bin/usr/bin:/usr/lbin
Batch just calls “at” with the following flags:
at -q b -m now
Batch: non-urgent missions,
- Use at to remind yourself in 5 minutes that it ight be time to go to the bathroom.
sudo apt install update
sudo apt install at
echo “commit to bathroom” | at now +5 minutes
echo doesn’t work, it it feels like it should.
at now +5 minutes
> notify-send “commit to bathroom”
> CTRL+d
- Come back from the bathroom quicly. We have lots of work to do.
just 5 more minutes.
- Run sleep 100 & several times. use jobs, bg, fg, ^Z, and kill to manipulate the jobs.
jobs lists current jobs,
bg sends a job to the background,
fg sends to to the foreground,
^Z ends the current job
kill kills all current hobs
- What processes are running on your machine?
ps aux
- What is the PID
echo $$
- what happens when you run kill -9 with the PID of your shell as a parameter?
the shell commits un-alive
- nice is nice. Read about it.
lets you run a command at a priority lower than the command’s normal priority. default drop is 10, unless parameter is provided.
- Run xeyes on a remote computer. Ensure that it continues to run after you log out.
yes
- How would you stop the xeyes that some idiot is running on your computer?
ps aux,
locate the xeyes PID,
kill -9 PID
- Which directory are you in? go to $HOME
pwd,
cd $HOME
- Display hidden files in your home directory
ls -a
- cp the entire contents of your home directory to /tmp (including hidden files)
cp * -a $HOME /tmp
- Move what you just copied to /tmp/stupidity
mv * /tmp /tmp/stupidity
- What is the difference between ln and ln-s
ln creates a hard link, ln -s creates a soft link
soft link is “more powerful”.
soft link functions like a shortcut,
hard link is like a constantly updated copy.
- Instead of using cd all the time, try pushd and popd
pushd [OPTIONS] [DIRECTORY]
pushd /home // push the current directory to the top of the directory stack and change to /home
popd will pop the top directory from the stack and move ‘down’ the stack.
- Do the commands cp, mv, and rm each have the flags -i, -r and -f?
-what are these flags good for?
b. why does mv not have the -r flag?
cp has -i, -r and -f,
mv has -i and -f,
rm has -i, -r and -f
-i : interactive, prompts overwrite (prompts ‘are you sure’ before deleting somethigns sensitive)
-r: recursive, copies directories recursively. (includes all subfiles/subdirectories within the file)
-f: force, if the file cannot be opened, remove it and try again
mv doesn’t have the -r flag, it moves all files and contents already. meaning it already has the recursive property.
- What file systems are mounted? What type are they?
‘mount’.
findmnt
(ext4, sysfr, etc.)
“any external device is called a block device”
- How much disk space are you using? How much is still free?
df
though I’m preferring df -h.
used 11G, 7.2G available (/dev/nvme0n1p8)
- Create a text file with your deepest and darkest secrets.
touch weeb.txt
gedit weeb.txt
secret
- Update the permissions so only you can read and modifiy it.
chmod +rwx weeb.txt //adds read/write/excecute permissions
chmod -rwx
chmod ugo-rwx weeb.txt //remove rwx permissions from users, groups and others.
chmod 700 weeb.txt //adds rwx permissions to only the owner of the file
- Create a “friend” account for playing with permissions
useradd [OPTIONS] USERNAME
sudo useradd bob
sudo passwd bob [12345]
- Create a group for your friend and add the user “friend” to this group
groupadd bobsgroup
sudo usermod -a -G bobsgroup bob
- Set the permissions so that only you and your friends can read your secrets.
sudo chgrp g-rwx weeb.txt
chmod g+r weeb.txt
- Update the permissions so that only you can modify the file.
chmod g-wx weeb.txt
- It would be a good idea to erase the file.
agreed.
- Create a directory that others can browse but not modify.
mkdir -m go-wx directory
- What does execute permission on a directory signify?
execute permission defines whether a user can ‘enter’ the directory (make it their current directory)
- Find the Linux dictionary file.
gedit usr/share/dict/words
sudo find -name dict
- Count the number of words that start with a and end with z (use grep | wc) and print the number to a file in /tmp
grep ^a.*z$ /usr/share/dict/words | wc -w
^a has to start with a
z$ has to end with z
- could be anything in between
- Display the words containing qui respelled with kwi. You should learn to spell.
grep -E ‘qui’ /usr/share/dict/words
grep -E ‘qui’ /usr/share/dict/words > /tmp/kwi.txt
sed -i ‘s/qui/kwi/g’ /tmp/kwi.txt
cat /tmp/kwi.txt
- Record all your commands for the next few minutes to a file in /tmp
script /tmp/testScript.txt
exit | at now +5 minutes
- what are the last 20 words in the dictionary?
tail -20 /usr/share/dict/words
tail -n20 /usr/share/dict/words
- There are “magic” numbers at the beginning of many executeables. What are their values? (Usually the first size_t bytes for something written in C).
“Magic Numbers” are the first few bytes of each file, unique to the file type.
xxd boop.sh | head
the first few bytes of each file. roughly the first 16 bytes.
xxd date.sh | head: magic number is 23 21 2f 62 69 6e 2f 73
- What are possible orderings of the following elements: fileName, cmd, <, >, 2 in a single statement?
cmd <fileName> 2
cmd fileName <2>
cmd filename filename</fileName>
- Make tea and read about tee.
named after and functions like a T-pipe.
wc -l text1.txt|tee -a text2.txt
outputs the bit count of text1.txt to console, but also appends it to text2.txt (-a flag appends. removing the -a flag will overwrite the contents of text2.txt)
- Create a file named .myuncs that will contain all the commands and usefal aliases. Save this file on the disk-on-key (/media/student_name/MIZI (you need to first change the disk-on-key label to MIZI).
mount //find ‘on /media/disk (/dev/sda1)
sudo apt install mtools
umount /media/daniel/’UBUNTU 22_0’
sudo mlabel -i /dev/sda1 :: MIZI
sudo touch /media/daniel/MIZI/.myunsc
compgen -c -a|tee /media/daniel/MIZI/.myunsc
- Find 2 ways to bypass a locked computer (if you don’t know the password).
enter ubuntu recovery mode and open root shell prompt,
mount -rw -o remount/ (remount root with write access)
ls /home (list available users)
psswrd username (resets user’s password)
reboot the computer, press E to prompt grub edit screen,
find the line starting with linux, append init=/bin/bash to the end of that line
CTRL+x to save changes. this will boot into linux kernel with read and write permissions/ passwordless root shell.
ls /home, passwrd username. set a new password and shut down.
- Create a .tar file of your home directory. Compress it. Restore it in /tmp/derpy.
-We don’t use full paths with .tar! (Only relative.) Why?
sudo tar cf home.tar home
mkdir /tmp/derpy
sudo tar -xf home.tar.gz -C /tmp/derpy
sudo tar -cf home.tar /home
sudo tar -xf home.tar -C /tmp/derpy
-c : create
-x : extract
-z : compress?
- cat the .tar file into /dev/null.
cat home.tar.gz > /dev/null
and into the void it goes
- Create a new file in your home directory, and create a new .tar file.
sudo touch newFile
sudo tar -f new.tar newFile
- Compare the old and new .tar file contents. At which line do they differ?
The head lines, effectively
cmp file1 file2
- time to sleep.
sleep NUMBER[suffix]
sleep 2m // 2 minutes
sleep 10s // 10 seconds
sleep 1d // sleep 1 day
sleep 5 // 5 seconds
- What is sync good for?
synchronizes cache data to permanent system memory.
prevents data loss.
syncs all cache data by default, otherwise
sync [OPTIONS] [file]
- When would you use swapon and swapoff?
activate and deactivate partitions ins specific devices.
- What is the difference between a swap file and a swap partition?
swap file handling is more flexible, but slower. (can’t enlarge a swap partition without disk management tools)
Swap partitions are straight up faster, and more common.
- Learn how to use GDB
GNU Project Debugger. helps poke into C programs while they are executing and see what exactly makes programs crash. operates on exe files (binary files produced by compilation process.)
already installed:: type into console:
gdb
(exit with q)
can run:
gdb ./a.out/
https://www.geeksforgeeks.org/gdb-step-by-step-introduction/
- Create a Core fle anc check it out using GDB
gcc -std=c99 -g -o test breakme.c
gdb ./test
break main
run
gcore
gdb ./test core.83282
- Use Valgrind to check your program for any memory allocation leaks.
sudo apt install valgrind
valgrind EXECUTEABLE