file and directory operations Flashcards
Assuming you are currently in a directory containing a directory named templates. What is the command to delete templates?
rm -R templates
What is the command to delete recursively a directory and all its content? Give an example for a directory named files.
rm -R files
What is the command to list the last 250 lines from a file called myfile.txt ?
(assuming you are currently in the directory of the file)
tail -n myfile.txt
What is the command to keep listing the last 250 lines from a file called myfile.txt as it changes?
(assuming you are currently in the directory of the file)
tail -f -n 250 myfile.txt
What is the command to restart a Linux server immediately?
reboot now
What is the command to get all the IP addresses associated with a Linux installation?
ip addr show
What is the nginx command to tell nginx to reload its config?
nginx -s reload
What is the command to remove the user deploy from the wheel group on rhel?
gpasswd -d deploy wheel
What is the command to see all the groups a user called deploy belongs to?
groups deploy
What is the command to tell Linux to start a service at boot time? Give an example for a service called HelloWorld.
sudo systemctl enable HelloWorld
If you have a service with the logical name HelloWorld what is the command to get the log entries only for that service?
sudo journalctl -u HelloWorld
What is the command to get the status of a service called HelloWorld?
sudo systemctl status HelloWorld
What is the command to start a service called HelloWorld?
sudo systemctl start HelloWord
Are directory and filename case sensitive in Linux?
yes
How do you stop a service called HelloWorld?
sudo systemctl stop HelloWorld
How do you reload the services config in linux?
sudo systemctl daemon-reload
What is the command to set the timezone to EST?
sudo timedatectl set-timezone America/Toronto
On a rhel linux system where are the .service files located?
/etc/systemd/system/
For example:
/etc/systemd/system/HelloWorld.service
What is the command to ssh in a remote server at 146.190.242.245 with the root user if you are in your home directory and your key is at .ssh/id_rsa
ssh -i .ssh/id_rsa root@146.190.242.245
to confirm: where are the nginx config files located on a rhel system?
/etc/nginx/conf.d/
For example:
/etc/nginx/conf.d/hello.conf
What is the curl flag to ignore a self-signed certificate?
curl -k http://142.112.48.65:80
Commands to shutdown a server
shutdown now
or
poweroff
How can you check if 2 files have the same content?
cmp -s /tmp/file1 /tmp/file2
What is the ls command flag to ignore directory?
ls -d
What is the ls command to seach for files (not directories) that starts with a?
ls -d a*
What is the ls command to seach for files (not directories) that starts with a or c?
ls -d [ac]*
What is the command to install firewalld in rhel?
dnf install firewalld
Once you install firewalld what do you need to do first?
To make sure it start at boot:
systemctl enable firewalld
To start it now without rebooting:
systemctl start firewalld
In firewalld how do you authorize your IP for everything if your IP is 142.112.48.65?
firewall-cmd –permanent –add-rich-rule=’rule family=”ipv4” source address=”142.112.48.65” accept’
How do you reload firewalld after you made changes?
firewall-cmd –reload
How can you see the current rules in firewalld?
firewall-cmd –list-all
How can you permanently remove a service called cockpit?
firewall-cmd –permanent –remove-service=cockpit
To complete: How can you test a rule to let’s say remove ssh from firewalld?
firewall-cmd –remove-service=ssh
(We omit the firewalld –permanent flag
How can we reload systemctl?
systemctl daemon-reload
Where do you need to put your .service file when you deploy a .net app on a rhel server?
/etc/systemd/system/
Where do you put the nginx config for a .net app you deploy? Let’s say for a project called hello ? Provide the full path including the name of the file.
/etc/nginx/conf.d/hello.conf
For the following command:
firewall-cmd –remove-service=cockpit
What will be the lifetime of this command?
The rule will be in effect immediately and until your reboot the server or do:
firewall-cmd –reload
or the following command:
firewall-cmd –permanent –remove-service=cockpit
What will be the lifetime of this command?
The rule won’t be in effect immediately. It will be in effect once you run:
firewall-cmd –reload
or:
reboot the server
How can you get the status of selinux?
run:
sestatus
How can you verify a certificate with curl?
curl –verbose https://www.google.com
If we see the line:
* SSL certificate verify ok.
It means it’s good.
How can you check the time from the command line in linux?
type:
date
How do you chain commands?
Using &&
In a rhel system how can you get the list of the last updates installed?
sudo dnf history list last
or
sudo dnf history list
The last flag restrict the list to the most recent updates
In a rhel system how can you check if updates are available without upgrading the system?
dnf check-upgrade
In a rhel system how do you perform an update?
dng upgrade