Command Deck Flashcards
Review command function
ll
list directories/files with permissions details
Similar to ls-l
rm
removes a file/deletes a file
rm -r
removes/deletes a directory or file
Go back to the root directory (“/root” NOT “/”)
cd ~
Make a copy of dir4 to be copied into dir5
cp -r dir4 dir5
Change the name of file good_burger to bad_burger
mv good_burger bad_burger
Move file3 into dir1
mv file3 dir1/
The files and folders have to be in the same directory level to move files into folders
Display the contents of file5 with numbered lines
cat -n file5
Find file study.log in the system
find / -name study.log
Login to the following server remotely using vsc:
Server Name: 198.58.119.40
Username: u5bt
Password: abc
Command:
ssh u5bt@198.58.119.40
Prompt:
user u5bt
enter password: enter abc
Login to a LightSail Centos 7 server remotely with the public ip_address 184.24.68.30 using key access. The key is deVops
- cd into Downloads folder to access the key
- type: ssh -i deVops.pem centos@184.24.68.30
Display the following message in the command line:
Thank you God for this opportunity. I pray for future success.
echo Thank you God for this opportunity. I pray for future success.
whoami
Gives your user id
id -r user2
Print real user ID for user2
id -G user3
Print effective group ID for user3
iostat
Check cpu, os, kernel name and version, hard drive info, server size, cpu percentage, date, ip address
Run an inventory on the server
- Check # hard drives - iostat or lsblk
- Check # of cpus (and data) - iostat or nproc (lscpu)
- Check cpu percentage - iostat
- Check kernel type and name - uname + uname -r
- Check OS type - cat /etc/*release
- Check memory - top or free
lscpu
access system inventory
* brand, model, model name, speed and so on
List commands required to obtain cpu information
- lscpu
- nproc
- iostat
- top
List commands required to obtain hard drive information
- lsblk
- iostat
Obtain OS name, version and associated information on a Ubuntu server
lsb_release -a
Obtain OS name, version and associate information on a Centos server
- cat /etc/os-release
OR - cat /etc/*release
Obtain kernel name
uname or uname -s
Command for kernel release (version)
uname -r
control L
clears the screen; alternative to clear command
Delete directory Dir8
rm -r Dir8
Print output for lscpu into an existing file called fil5 without erasing the existing data within the file
lscpu > > fil5
While editing in vi (insert mode), add numbers to each line
- Press ESC
- :set nu
Obtain the word count for file10
wc -l file10
Print the first 10 lines for file6
head -10 file6
Building a webpage with the message:
This is my first website, and I’m loving it!
- systemctl start httpd
- systemctl enable httpd
- cd /var/www/html/
- touch index.html
- vi index.html
- <h1> This is my first website, and I’m loving it! <h1>
</h1></h1>
Without switching to the root user, install apache on your server w/o having to confirm the installation
sudo yum install httpd -y
As the root user, remove the korn shell on your server
yum remove ksh
Find the inode # of file15
ls -i file15
ls -li Dir4
Displays inode #, link #, permissions, user, group info and date for files in Dir4
Display the following message on the command line:
“We are learning and becoming better!”
echo We are learning and becoming better!
history
display a list of previously executed commands in the current shell session
Within the bash shell
echo $? is to …
display the exit code for the previous command, establishing if the command was successful = 0 or not >0
uptime
displays the length of time the system has been running
uname -m
kernel size/architecture
Alternate commands displaying the same information: arch, uname-i, uname -p
Use this command to assess the system’s RAM
free
lsblk
Checks drives and partitions
nproc
Displays the number of processors (cpus)
This command can help identify zombie processes
top
Create a file called file5
touch file5
Create and enter file10 simultaneously
vi file10
Can also use vim if installed
pwd
Prints the working/current directory
Shows where you are in the system
Exit insert mode of vi and exit and save the documents contents
1) Esc
2) :wq
You are stuck in vi mode and can’t remember how to exit. This command will help you exit, by stopping the process:
CTL Z
Display contents of file7 in a way that gives the contents one page a time while loading the file completely
more file7
Display contents of file16 in a way that gives the contents one page at a time without loading the entire file at once
less file16
grep -i
Used to filter text within a file by eliminating the case sensitivity of grep (by using -i)
Command used in the command line to combine commands into one command
The Pipe (|)
(The Pipe)
Simultaneously create file17 and direct the output from the command iostat into file 17
iostat > file17
Add directed output from the nproc command into an existing file called file24
nproc > > file24
yum repolist
Used to display a list of enabled YUM repositories on your system. It provides information about the repositories configured on your system and their respective status.
yum whatprovides
Used to find which package provides a specific file or command. This is particularly helpful when you need to locate the package that contains a particular file or command you want to use.
How to confirm that your system is connected to the internet?
ping [website address]
Gives the public ip address as verification
sudo su
Switch to root user
git init
Initialize a local repository (turns a folder/directory into a local repository)
git switch feature1
Change from current branch to feature1 branch
Switch from root user to regular user status
exit
git checkout feature2
Switch from current branch to feature2 branch
Rename the master branch to main branch
git branch -M main
Show the state of the files that are to be sent to a cloud based repository
git status
You’ve committed file1, but realized it was supposed to be file2. What steps do you take to correct this error?
1) git log - will give the commit ID
2) git reset [commit ID]
Link local repository (branch1) to GitHub
1) git remote add origin [url to GitHub repository]
2) git remote -v to verify
3) git push -u origin branch1
df
displays disk space used and available
sudo useradd
Add user account
sudo groupdel
Delete group account
Create a hard link from file2 to file24
sudo ln file2 file24
ls -s file8 file28
Soft link or symlink b/w file8 and file28
Filter out the first column of information from /etc/passwd file
awk -F “:” ‘{print$1}’ /etc/passwd
awk -F “/” ‘{print$4}’ /etc/passwd
Filtering out the 4th column information of file /etc/passwd
ll | awk ‘{print$2}’
Filtering out second row of ll output using the pipe command
sed -i ‘[1]i [Message]’ file20
Entering message into file 20 w/o using vi command
Steps to login w/o ssh key
1) vi /etc/ssh/sshd_config
2) :set nu
3) Change PasswordAuthetication no to
PasswordAuthentication to yes
4) systemctl restart sshd
5) Create a user and user password
6) Log in to visual studio code remotely using the
username and password
ls -a
Displays all directories w/in a directory including hidden directories
tail -6 file10
Display the last 6 lines of file 10
man
Gives manual for any given command :)
crontab -u Andre -e
Edit crontab for user Andre
As the current user, view the crontab entries
crontab -l
Execute the sleep command in the background for 60 seconds
sleep 60 &
fg 22
Calls job 22 to the foreground from the background
echo $first_name
Displays the value for the variable first_name
Declare the value, Jason, for the variable, User 1
User1=Jason
Print (or call) environment variables
env or printenv
export Group = Security
Changing the status of the variable Group from a regular variable to an environment variable
What command can you use to check the port on which apache is listening?
sudo netstat -anpl | grep httpd
To create a new database and name a database we run the following MySQL command:
create database [database_name]
What’s the code to build a docker image?
docker build -t [image_name] .
Name 3-5 common commands you may find in a Dockerfile
- FROM [image and tag]
- RUN [commands]
- COPY ./[index_file_name] [path]
- CMD [command] -D FOREGROUND
- EXPOSE [port]
What docker command prints the gateway address and container ip address?
docker inspect [container_ID]
Please give me the docker command to remove all docker images
docker rmi -f $(docker images -q)
What is the docker command required to run a container w/o exiting from that container?
docker run -it [image_id] bash
What is the result of this command:
docker node ls
Provides a list the nodes in a docker swarm cluster
What command is used to declare an environment variable
export [variable_name]=[variable value]
How do you undeclare an environment variable previously declared?
unset [variable_name]