17 KiB
17 KiB
Linux essentials source
- Change into the
/tmp
directory using the commandcd /tmp
. - Confirm you are in the
/tmp
directory using the commandpwd
. - Change back into your home directory using the command
cd
. - Confirm you are in your home directory using the command
pwd
. - Print the text
This is file01.
to the file/tmp/file01
using the commandecho "This is file01." > /tmp/file01
. - Confirm the
/tmp/file01
file has the correct content using the commandcat /tmp/file01
. - Append the text
This is appended.
to the file/tmp/file01
using the commandecho "This is appended." >> /tmp/file01
. - Confirm the
/tmp/file01
file has the updated content using the commandcat /tmp/file01
. - Send the output of the
printenv
command to a new file named/tmp/myenv
using the commandprintenv > /tmp/myenv
. - View the first five lines of the
/tmp/myenv
file using the commandhead -n 5 /tmp/myenv
. - Declare and export a new environment variable with the command
export COURSE_NAME="LSA1"
. - Verify your newly exported environment variable exists using the command
printenv | grep COURSE_NAME
. - Practice these and other commands until you feel comfortable with them.
- When finished, use the
exit
command to exit the shell and logout.
Managing files source
- Create a directory for these exercises by using the command
mkdir /tmp/managing-files
. - Change into the newly created directory using the command
cd /tmp/managing-files
. - Create six empty files using the command
touch file{01..06}
. - Run each of the following commands to change the permissions of each file. See if you can guess what the permissions will be before you run each command:
chmod 764 file01
chmod 400 file02
chmod 651 file03
chmod 4744 file04
chmod 4664 file05
chmod 1444 file06
- Run the command
ls -l
. You should see output similar to the following.
$ ls -l
total 0
-rwxrw-r--. 1 vagrant vagrant 0 Aug 23 01:10 file01
-r--------. 1 vagrant vagrant 0 Aug 23 01:10 file02
-rw-r-x--x. 1 vagrant vagrant 0 Aug 23 01:10 file03
-rwsr--r--. 1 vagrant vagrant 0 Aug 23 01:10 file04
-rwSrw-r--. 1 vagrant vagrant 0 Aug 23 01:10 file05
-r--r--r-T. 1 vagrant vagrant 0 Aug 23 01:10 file06
- Run the commmand
tar -zcvf /tmp/managing-files.tgz -C /tmp/managing-files .
to create an archive named/tmp/managing-files.tgz
of all the files in the/tmp/managing-files
directory. - Run the command
rm -f file0*
to remove all six files that were created earlier. Verify the files were removed using the commandls -l
. - Run the command
tar -zxvf /tmp/managing-files.tgz -C /tmp/managing-files
to extract the contents of your archive back into the/tmp/managing-files
directory. - Verify the files were restored correctly using the command
ls -l
. You should see output similar to the following. NOTE:tar
does not restore special permissions (SUID, SGID, sticky bit) so you will only see the read, write, and execute permissions.
$ ls -l
total 0
-rwxrw-r--. 1 vagrant vagrant 0 Aug 23 01:10 file01
-r--------. 1 vagrant vagrant 0 Aug 23 01:10 file02
-rw-r-x--x. 1 vagrant vagrant 0 Aug 23 01:10 file03
-rwxr--r--. 1 vagrant vagrant 0 Aug 23 01:10 file04
-rw-rw-r--. 1 vagrant vagrant 0 Aug 23 01:10 file05
-r--r--r--. 1 vagrant vagrant 0 Aug 23 01:10 file06
- Practice these and other commands until you feel comfortable with them.
- When finished, use the
exit
command to exit the shell and logout.
Managing software source
Apt
- Install the
screen
package using the commandsudo apt install screen
. Press ++y++ if prompted. - Verify the screen package is installed using the command
sudo apt list screen
. You should see the matching output. - Remove the
screen
package using the commandsudo apt remove screen
. - Verify the screen package is removed using the command
sudo apt list screen | grep installed
. You should see no matching output. - Run the command
sudo apt install nginx
to install the nginx webserver. Press ++y++ if prompted. - Run the command
sudo systemctl status nginx
to see the status of the nginx webserver. It should show inactive or dead. - Run the command
sudo systemctl start nginx
to start the nginx webserver. - On your local workstation, open a web browser and navigate to
http://127.0.0.1:8080
. You should see an nginx test page. - Run the command
sudo systemctl stop nginx
to stop the nginx webserver. - Try to reload the web page on your local workstation. It should not load this time.
- Verify the nginx service is not running using the command
sudo systemctl status nginx
. - Practice these and other commands until you feel comfortable with them.
- When finished, use the
exit
command to exit the shell and logout.
Yum
- Install the
screen
package using the commandsudo yum install screen
. Press ++y++ if prompted. - Verify the screen package is installed using the command
sudo yum list installed | grep -i screen
. You should see the matching output. - Remove the
screen
package using the commandsudo yum remove screen
. - Verify the screen package is removed using the command
sudo yum list installed | grep -i screen
. You should see no matching output. - Run the command
sudo yum install epel-release
to install the EPEL repository. - Run the command
sudo yum install nginx
to install the nginx webserver. Press ++y++ if prompted. - Run the command
sudo systemctl status nginx
to see the status of the nginx webserver. It should show inactive or dead. - Run the command
sudo systemctl start nginx
to start the nginx webserver. - On your local workstation, open a web browser and navigate to
http://127.0.0.1:8080
. You should see an nginx test page. - Run the command
sudo systemctl stop nginx
to stop the nginx webserver. - Try to reload the web page on your local workstation. It should not load this time.
- Verify the nginx service is not running using the command
sudo systemctl status nginx
. - Practice these and other commands until you feel comfortable with them.
- When finished, use the
exit
command to exit the shell and logout.
General
- Run the command
ps aux
to view all of the processes currently executing on the system. - Run the command
top
to view all of the processes and their resource usage. Notice how the output refreshed every 2 seconds. Press ++q++ to quit when done looking around. - Run the command
sleep 60
. Press ++ctrl+c++ to quit the command early. - Run the command
sleep 15 &
to runsleep
in the background. Run thejobs
command to verify the background command is still running. Wait for 15 seconds and run thejobs
command again to verify that the job is no longer executing in the background. - Run the command
sleep 600 &
to run thesleep 600
command in the background. You will be shown the PID of the background process. Keep a note of this for the next steps.- Verify the PID exists using the command
ps aux | grep PID
wherePID
is the PID from earlier. - Use the
kill -15 PID
command wherePID
is the PID from earlier to send aSIGTERM
command to that process. - Run the
jobs
command to verify your background process was terminated.
- Verify the PID exists using the command
- Run the command
sleep 444 &
to run thesleep 444
command in the background. You will be shown the PID of the background process. Keep a note of this for the next steps.- Verify the PID exists using the command
ps aux | grep PID
wherePID
is the PID from earlier. - Use the
kill -9 PID
command wherePID
is the PID from earlier to send aSIGKILL
command to that process. - Run the
jobs
command to verify your background process was killed.
- Verify the PID exists using the command
Configuring hardware source
- Drop down to the
root
user using the commandsudo su -
. - Verify the
/dev/sdb
anddev/sdc
devices are attached to your system by running the commandlsblk
. You should see output similar to the following:
[root@lsa-i ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
sdc 8:32 0 1G 0 disk
- Run the command
fdisk /dev/sdb
to begin formatting the devicedev/sdb
. Follow the subtasks below to format the device with 1 partition that takes up all the space:- Type
n
and hit ++enter++ to create a new partition. - Type
p
and hit ++enter++ to make this a primary partition. - Type
1
and hit ++enter++ to make this primary partition the first partition on this device. - Hit ++enter++ to accept the default first sector.
- Hit ++enter++ to accept the default last sector.
- Type
p
and hit ++enter++ to print the proposed partition changes. You should see the partition/dev/sdb1
. - Type
w
and hit ++enter++ to write these changes to the device and exit.
- Type
- Verify the
/dev/sdb1
partition was created successfully by running the commandlsblk
. You should see output similar to the following:
[root@lsa-i ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
└─sdb1 8:17 0 1023M 0 part
sdc 8:32 0 1G 0 disk
- Run the command
mkfs.xfs /dev/sdb1
to create an XFS file system on the/dev/sdb1
partition. - Run the command
lsblk -f
to list the UUID and file system type of the/dev/sdb1
partition. You'll need this information for the/etc/fstab
file. - Run the command
mkdir /mnt/exercise01
to create a directory to use for mounting the/dev/sdb1
partition. - Add an entry to the
/etc/fstab
file to mount your/dev/sdb1
device to the/mnt/exercise01
directory. Your new entry should be similar to the following:
UUID=<DEVICE_UUID> /mnt/exercise01 xfs defaults 0 2
- Run the command
mount -a
to read the/etc/fstab
file and mount all currently unmounted devices. - Verify the
/dev/sdb1
partition was mounted successfully by running thelsblk
command. You should see output simiar to the following:
[root@lsa-i ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
└─sdb1 8:17 0 1023M 0 part /mnt/exercise01
sdc 8:32 0 1G 0 disk
- Run the command
df -h
to see the current disk usage of the system. Take note of the value in the Used column for/dev/sdb1
. My output is below.
[root@lsa-i ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 38G 823M 37G 3% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.5M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda2 1014M 63M 952M 7% /boot
tmpfs 184M 0 184M 0% /run/user/1000
/dev/sdb1 1020M 33M 988M 4% /mnt/exercise01
- Run the command
dd bs=1M count=50 if=/dev/urandom of=/mnt/exercise01/myfile
to create a file /mnt/exercise01/myfile with a size of around 50 MiB. This command may take a few seconds to run. - Run the command
df -h
to see the current disk usage of the system. Take note of the value in the Used column for/dev/sdb1
. Notice how the value has increased by roughly 50 MiB. My output is below.
[root@lsa-i ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 38G 823M 37G 3% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.5M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda2 1014M 63M 952M 7% /boot
tmpfs 184M 0 184M 0% /run/user/1000
/dev/sdb1 1020M 83M 938M 9% /mnt/exercise01
- Run the command
fdisk /dev/sdc
to begin formatting the device/dev/sdc
. Follow the subtasks below to format the device with 2 partitions with 256 MiB and 512 MiB respectively:- Type
n
and hit ++enter++ to create a new partition. - Type
p
and hit ++enter++ to make this a primary partition. - Type
1
and hit ++enter++ to make this primary partition the first partition on this device. - Hit ++enter++ to accept the default first sector.
- Type
+256M
and hit ++enter++ to give the partition a size of 256 MiB. - Type
p
and hit ++enter++ to print the proposed partition changes. You should see the partition/dev/sdc1
. - Type
n
and hit ++enter++ to create another new partition. - Type
p
and hit ++enter++ to make this a primary partition. - Type
2
and hit ++enter++ to make this primary partition the second partition on this device. - Hit ++enter++ to accept the default first sector.
- Type
+512M
and hit ++enter++ to give the partition a size of 512 MiB. - Type
p
and hit ++enter++ to print the proposed partition changes. You should see the partition/dev/sdc2
. - Type
w
and hit ++enter++ to write these changes to the disk and exit.
- Type
- Verify the
/dev/sdc1
and/dev/sdc2
partitions were created successfully by running the commandlsblk
. You should see output similar to the following:
[root@lsa-i ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
└─sdb1 8:17 0 1023M 0 part /mnt/exercise01
sdc 8:32 0 1G 0 disk
├─sdc1 8:33 0 256M 0 part
└─sdc2 8:34 0 512M 0 part
- Run the command
mkfs.ext4 /dev/sdc1
to create an EXT4 file system on the/dev/sdc1
partition. - Run the command
mkfs.xfs /dev/sdc2
to create an XFS file system on the/dev/sdc2
partition. - Run the command
lsblk -f
to list the UUIDs and file system types of the/dev/sdc1
and/dev/sdc2
partitions. You'll need this information for the/etc/fstab
file. - Run the command
mkdir /mnt/small
to create a directory to use for mounting the/dev/sdc1
partition. - Run the command
mkdir /mnt/large
to create a directory to use for mounting the/dev/sdc2
partition. - Add two entries to the
/etc/fstab
file to mount your/dev/sdc1
and/dev/sdc2
devices to the/mnt/small
and/mnt/large
directories respectively. Your new entries should be similar to the following:
UUID=<DEVICE_UUID> /mnt/small ext4 defaults 0 2
UUID=<DEVICE_UUID> /mnt/large xfs defaults 0 2
- Run the command
mount -a
to read the/etc/fstab
file and mount all currently unmounted devices. - Verify the
/dev/sdc1
and/dev/sdc2
partitions were mounted successfully by running thelsblk
command. You should see output simiar to the following:
[root@lsa-i ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 39G 0 part
├─VolGroup00-LogVol00 253:0 0 37.5G 0 lvm /
└─VolGroup00-LogVol01 253:1 0 1.5G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
└─sdb1 8:17 0 1023M 0 part /mnt/exercise01
sdc 8:32 0 1G 0 disk
├─sdc1 8:33 0 256M 0 part /mnt/small
└─sdc2 8:34 0 512M 0 part /mnt/large
- Practice these and other commands until you feel comfortable with them. You'll need to run
vagrant destroy
and thenvagrant up
to reset your virtual machine if you wish to do these exercises over. - When finished, use the exit command to exit the shell and logout.