Chapter 3 Flashcards
What does man file do?
Determines file type
How do we create a directory with a subdirectory?
Mkdir -p dir/subdir
When working with directories (as opposed to files), which command does not need a recursive flag?
mv
What are the five key flags in the tar command?
- c create archive
- x extract archive
- r append to an archive
- f read from or write to a file
- t list the contents of the archive
How to get a big picture overview of the filesystem?
df -h
How to get a big picture overview of the filesystem?
df -h
How do we create an archive with tar and all the files that are called “file_[smth]?
tar cf archive.tar file_*
How do we add a file to an archive?
tar rf archive.tar
How do we check an archive for a specific file with tar? hint: first display the entire archive and then look for what you need
tar tvf archive.tar | grep extra.txt
t = tail v = verbose
How do we compress a normal archive to a maximum degree?
gzip -9 archive.tar
How do we create a bzip2 archive with tar?
tar cjf archive.tar.bz2
How to create a zip archive?
zip -r archive.zip file1_*
How do we determine number of words in a file?
wc
What does wc do?
It counts words
How can we count the number of lines rather than words in an input file?
wc -l
How do we list the recently used commands starting with cat? (or anything else really, cat si just one example)
!cat
What does the cut command do?
It removes sections from lines of files
What does the cut command do?
It removes sections from lines of files
What’s the basic syntax of reading input from a file?
command < file
What’s the basic syntax of sending input to a file?
command > file
What’s the basic syntax of appending input to a file?
command»_space; file
How do we look for all results that end - END! - with Apple or Ball?
grep -E “Apple$|Ball$”
What do we find when we look for grep -E “Ap*le”
A followed by 0 or more p’s followed by “le”
What’s the difference between looking for “Ap*le” and “Ap+le”?
the plus means 1 or more p’s and the star means 0 or more p’s
What’s the difference between looking for “Ap?le” and “Ap+le”?
question mark means looking for “maybe another p” followed by le;
plus means 1 or more ps
the ? won’t grep apple because we can only keep results with 1 or no p’s (but not 1+)
How do we match an A followed by p through z followed by le?
“Ap[p-z]le”
How to write down all words that end with “x”
x$
How to look for all three-letter words that start with a y or end with a z?
grep -E “^y..$|..z$”
What does the head command do?
Outputs the first 10 lines of a file
What does the tail command do?
Outputs the last 10 lines of a file
How do we go to the top of the file and bottom of the file in vim?
gg to the top and G to the bottom
How do we add line numbers to vim lines?
set nu
How do we switch into the insert mode and insert at the cursor in vim?
i
How do we switch into the insert mode and insert at the start of the line in vim?
I
How do we switch into the insert mode and insert under the current line in vim?
o
How do we write a file in vim?
:w
How do we quit vim?
:q
How do we write and quit?
:wq
How do we find the amount of available storage space on the hardware?
df -h
Where does the CPU information live on a linux machine?
cat /proc/cpuinfo
How do you find out how much RAM is installed?
sudo cat /proc/meminfo
which command displays the total amount of free and used physical and swap mem‐
ory in the system, as well as the buffers and caches used by the ker‐
nel?
free
How to determine the BIOS version?
sudo lshw
how do we start a shell script?
!/bin/bash
What’s the basic syntax for if statements in bash?
if [some test]
then
command
fi
What’s the basic syntax for for-loops in bash?
for variable in list;
do command;
done
— note the use of semicolon!! –
What’s the standard distribution release?
a release made available after a development period. during this time, all software is updated to a version and then frozen and tested to verify that all software versions work well together.
What’s a rolling release?
It’s a release that is kept up to date using small and frequent updates to the core of the OS
How do we count the number of processes that are currently running in our system?
ps aux | wc -l
How do we view information about the load of our system?
cat /proc/loadavg OR uptime
How many processes are running as a default user?
ps -U cloud_user | wc -l
How do we find a pid of process x?
ps aux | grep x
Where do we check a process for a number of threads?
cat /proc/[PID of a process]/status
How do you verify that the web server is running
Type curl -I localhost
What is stored in the /etc/boot folder?
System boot configuration~ contains boot configuration files and parameters, Linux Kernel, and initial RAM disk
What is stored in the /etc/fstab folder?
Partition Mount Point. it contains a list of local users and their attributes
What is stored in the /etc/passwd folder?
User Attributes - a list of local users and their attributes
What is stored in the /etc/group folder?
group attributes
What is stored in the /etc/hosts folder?
A list of IP addresses and hosts that we want to associate with these addresses
What’s stored on the sys directory?
Pseudo file system that the kernel uses to give us information about devices
What’s sysfs?
A virtual file system the purpose of which is to export information about various kernel subsystems and associated drivers
How do we get a relatively interactive view of the processes?
Use top command
Dev file system?
A pseudo file system that contains device files - normally with block or character devices; it reads hard drive as a file
What does a kernel ring buffer do?
The kernel ring buffer holds messages related to the operation of the kernel - a ring buffer is simply a buffer of a constant size
What is a CPU?
Central Processing Unit. It processes computer functions and performs calculations
What’s RAM?
Random Access Memory. It’s a high-performance, volatile storage
What’s secondary storage?
HDD/SSD/DVD. It’s persistent storage for data not currently in use
What’s an NIC?
network interface card. It permits connections to a network
What does swap memory do?
It uses hard disk as RAM
What are hardware drivers?
These are the devices that reside in the running kernel (or are loaded as a module) and they enable the OS to use the hardware
How do we determine the user’s IP address?
sudo ip addr show
How do we determine the user’s MAC address?
sudo mac addr show
How do we determine the gateway?
sudo ip route show
How do we determine the DNS server?
cat /etc/resolv.conf | grep nameserver
How do you perform a DNS lookup and find the IP address given a human-readable name?
host www.google.com
How do you perform a DNS lookup and find the IP address given a human-readable name USING EXTERNAL DNS?
You add the address of the external DNS server to the host command, e.g. like so: host www.google.com 1.1.1.1
How do we test the connectivity to a website?
we ping it with a c1 flag:
ping -c1 www.linuxacademy.com
How do we view general system logs and messages?
/var/log/messages/
How do we view general system logs for Debian-based systems?
/var/log/syslog
How do we view authentication logs?
/var/log/auth.log
How do we view red-hat-based system logs?
/var/log/secure
How do we view system boot logs?
/var/log/boot.log
How do we view system cron job logs?
/var/log/cron.log
How do we view kernel logs?
/var/log/kern.log
How do we view authentication failure logs?
/var/log/faillog
What’s the key distinction between routers and switches?
Switches forward packets within a network, routers forward packets between networks
Who are system users?
Users generally deployed when the applications are installed; their home directories are set to application folders and they normally do not have a login shell
What privileges does a standard user have?
They are provided with a login shell, a home directory, limited permissions to view file system configurations, and no permission for modifying system configurations.. They may be granted the ability to perform privileged actions using sudo
What privileges does a root user have?
It has full access to all permissions on the system and is used for system-level administration tasks
How to identify what group does user_a belong to?
id user_a
How do you know user_a ‘s home directory?
getent passwd user_a
What is user_a ‘s login shell?
cat /etc/passwd | grep user_a
How do we create a user with a default home directory?
sudo useradd -m mike
How do we display all groups that a user belongs to?
groups
How do we add a user called michael to the group called linuxacademy?
sudo usermod -a -G linuxacademy michael
What ID is typically reserved for root account?
UID 0
Which IDs are typically reserved for system users, or service accounts?
0-99
Which IDs are typically reserved for standard users?
100+
Which ID is typically reserved for user nobody?
65534
What does chown stand for?
change ownership
What does chmod stand for?
Change mode
How would you change the group to linuxacademy for file called testfile?
chown :linuxacademy testfile
How would you change file ownership to be owner by user usr1 for a file f1
chown usr1 f1
How would you change a file’s user and group ownership to cloud_u for a file called file1?
chown cloud_u:cloud_u file1
How would you change permissions to be read write execute for all?
chmod 777 file1
How would you add execute to current permissions?
chmod +x file1
How would you remove write from current permission?
chmod -w file1
What is the difference between a /tmp/ and /var/tmp
all content in /var/tmp persists through a system boot. this directory is used by programs or scripts that require more persistent temporary storage than /tmp which clears out upon system boot
What does mktemp do?
it creates a temporary file or directory with a randomized file name portion
How can we specify the characters in the directory called michael.something through make temp?
mktemp /tmp/michael.XXX for 3 random chars
How do you make a symbolic link?
ln -s [target] [link name]