1.
Which command returns to your current home directory, assuming that the current working directory is /tmp and your home directory is /home/user?
A
cd
B
cd ..
C
cd .
D
cd *
E
cd /home
2.
Which command displays the absolute path name of the current location?
A
cd
B
pwd
C
ls ~
D
ls -d
3.
Which command returns you to the working directory before the current working directory?
A
cd -
B
cd -p
C
cd ~
D
cd ..
4.
Which command changes the working directory up two levels from the current location?
A
cd ~/..
B
cd ../ ..
C
cd ../..
D
cd ~/
5.
Which command lists files in the current location, with a long format, and including hidden files?
A
llong ~
B
ls -a
C
ls -l
D
ls -al
6.
Which command creates an empty file called helloworld.py in the user home directory, assuming that your current directory is /home?
A
touch ./helloworld.py
B
touch ~/helloworld.py
C
touch helloworld.py
D
touch ../helloworld.py
7.
Which command changes the working directory to the parent of the current location?
A
cd ~
B
cd ..
C
cd ../..
D
cd -u1
8.
Which command changes the working directory to /tmp if the current working directory is /home/student?
A
cd tmp
B
cd ..
C
cd ../../tmp
D
cd ~tmp
Assistant
Let's address each sub-question one by one:
Return to your current home directory from /tmp:
A cd: This command without any arguments changes the directory to the home directory.
Correct Answer: A
Display the absolute path name of the current location:
B pwd: This command prints the current working directory, showing its absolute path.
Correct Answer: B
User
Assistant
You can create a script to automate these tasks. Here is a single command-line string that chains all necessary commands using semicolons and employs SSH to connect to the remote server:
bash
User
Do it for this too, but more dynamic and advanced:
code
Assistant
You can automate these steps with a single script that you execute from the workstation. This script will handle everything: logging into the server, creating the necessary links, verifying them, and then logging out. Here’s a single command that accomplishes the task:
bash
Return to the working directory before the current working directory:
A cd -: This command changes to the previous working directory.
Correct Answer: A
Change the working directory up two levels from the current location:
C cd ../..: This command moves up two directory levels from the current location.
Correct Answer: C
List files in the current location, with a long format, and including hidden files:
D ls -al: This command lists all files, including hidden ones, in a long format.
Correct Answer: D
Create an empty file called helloworld.py in the user home directory from /home:
B touch ~/helloworld.py: This command creates a new file named helloworld.py in the user's home directory.
Correct Answer: B
Change the working directory to the parent of the current location:
B cd ..: This command moves up to the parent directory of the current location.
Correct Answer: B
Change the working directory to /tmp from /home/student:
A cd tmp: This changes the directory to /tmp if specified with a leading slash / as in cd /tmp.
Correct Answer: A
These answers are based on the standard behavior of common Unix-like operating systems' command-line interfaces.
Create a single command-line command that can automate all of this:
code
[student@workstation ~]$ lab start files-manage
Instructions
Log in to the servera machine as the student user. In the student user's home directory, create three subdirectories: Music, Pictures, and Videos.
Use the ssh command to log in to the servera machine as the student user. The systems are configured to use SSH keys for authentication; therefore, a password is not required.
[student@workstation ~]$ ssh student@servera
...output omitted...
[student@servera ~]$
In the student user's home directory, use the mkdir command to create three subdirectories: Music, Pictures, and Videos.
[student@servera ~]$ mkdir Music Pictures Videos
Use the touch command to create sets of empty practice files to use during this lab. In each set, replace X with the numbers 1 through 6.
Create six files with names of the form songX.mp3.
Create six files with names of the form snapX.jpg.
Create six files with names of the form filmX.avi.
[student@servera ~]$ touch song1.mp3 song2.mp3 song3.mp3 \
song4.mp3 song5.mp3 song6.mp3
[student@servera ~]$ touch snap1.jpg snap2.jpg snap3.jpg \
snap4.jpg snap5.jpg snap6.jpg
[student@servera ~]$ touch film1.avi film2.avi film3.avi \
film4.avi film5.avi film6.avi
[student@servera ~]$ ls -l
total 0
-rw-r--r--. 1 student student 0 Mar 7 20:58 film1.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film2.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film3.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film4.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film5.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film6.avi
drwxr-xr-x. 2 student student 6 Mar 7 20:58 Music
drwxr-xr-x. 2 student student 6 Mar 7 20:58 Pictures
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap1.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap2.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap3.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap4.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap5.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap6.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 song1.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song2.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song3.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song4.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song5.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song6.mp3
drwxr-xr-x. 2 student student 6 Mar 7 20:58 Videos
Move the song files (.mp3 extension) to the Music directory, the snapshot files (.jpg extension) to the Pictures directory, and the movie files (.avi extension) to the Videos directory.
[student@servera ~]$ mv song1.mp3 song2.mp3 song3.mp3 \
song4.mp3 song5.mp3 song6.mp3 Music
[student@servera ~]$ mv snap1.jpg snap2.jpg snap3.jpg \
snap4.jpg snap5.jpg snap6.jpg Pictures
[student@servera ~]$ mv film1.avi film2.avi film3.avi \
film4.avi film5.avi film6.avi Videos
[student@servera ~]$ ls -l Music Pictures Videos
Music:
total 0
-rw-r--r--. 1 student student 0 Mar 7 20:58 song1.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song2.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song3.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song4.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song5.mp3
-rw-r--r--. 1 student student 0 Mar 7 20:58 song6.mp3
Pictures:
total 0
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap1.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap2.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap3.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap4.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap5.jpg
-rw-r--r--. 1 student student 0 Mar 7 20:58 snap6.jpg
Videos:
total 0
-rw-r--r--. 1 student student 0 Mar 7 20:58 film1.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film2.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film3.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film4.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film5.avi
-rw-r--r--. 1 student student 0 Mar 7 20:58 film6.avi
Create three subdirectories for organizing your files, and name the subdirectories friends, family, and work. Use a single command to create all three subdirectories at the same time.
[student@servera ~]$ mkdir friends family work
[student@servera ~]$ ls -l
total 0
drwxr-xr-x. 2 student student 6 Mar 7 21:01 family
drwxr-xr-x. 2 student student 6 Mar 7 21:01 friends
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Music
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Pictures
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Videos
drwxr-xr-x. 2 student student 6 Mar 7 21:01 work
Copy files that contain numbers 1 and 2 to the friends directory, and files that contain numbers 3 and 4 to the family directory. Keep in mind that you are making copies; therefore, the original files must remain in their original locations after you complete the step.
When you copy files from multiple locations into a single location, Red Hat recommends that you change to the destination directory before you copy the files. Use the simplest path syntax, whether absolute or relative, to reach the source for each file management task.
Copy files that contain numbers 1 and 2 to the friends directory.
[student@servera ~]$ cd friends
[student@servera friends]$ cp ~/Music/song1.mp3 ~/Music/song2.mp3 \
~/Pictures/snap1.jpg ~/Pictures/snap2.jpg ~/Videos/film1.avi \
~/Videos/film2.avi .
[student@servera friends]$ ls -l
total 0
-rw-r--r--. 1 student student 0 Mar 7 21:02 film1.avi
-rw-r--r--. 1 student student 0 Mar 7 21:02 film2.avi
-rw-r--r--. 1 student student 0 Mar 7 21:02 snap1.jpg
-rw-r--r--. 1 student student 0 Mar 7 21:02 snap2.jpg
-rw-r--r--. 1 student student 0 Mar 7 21:02 song1.mp3
-rw-r--r--. 1 student student 0 Mar 7 21:02 song2.mp3
Copy files that contain numbers 3 and 4 to the family directory.
[student@servera friends]$ cd ../family
[student@servera family]$ cp ~/Music/song3.mp3 ~/Music/song4.mp3 \
~/Pictures/snap3.jpg ~/Pictures/snap4.jpg ~/Videos/film3.avi \
~/Videos/film4.avi .
[student@servera family]$ ls -l
total 0
total 0
-rw-r--r--. 1 student student 0 Mar 7 21:04 film3.avi
-rw-r--r--. 1 student student 0 Mar 7 21:04 film4.avi
-rw-r--r--. 1 student student 0 Mar 7 21:04 snap3.jpg
-rw-r--r--. 1 student student 0 Mar 7 21:04 snap4.jpg
-rw-r--r--. 1 student student 0 Mar 7 21:04 song3.mp3
-rw-r--r--. 1 student student 0 Mar 7 21:04 song4.mp3
Copy the family and friends directories and their contents to the work directory.
[student@servera family]$ cd ../work
[student@servera work]$ cp -r ~/family ~/friends .
[student@servera work]$ ls -l
total 0
drwxr-xr-x. 2 student student 108 Mar 7 21:05 family
drwxr-xr-x. 2 student student 108 Mar 7 21:05 friends
Your project tasks are now complete, and it is time to clean up the directories. Use the rm -r command to recursively delete the family, friends, and work directories and their contents.
[student@servera work]$ cd ..
[student@servera ~]$ rm -r family friends work
[student@servera ~]$ ls -l
total 0
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Music
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Pictures
drwxr-xr-x. 2 student student 108 Mar 7 21:00 Videos
Return to the workstation system as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$
Finish
On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.
[student@workstation ~]$ lab finish files-manage
ssh student@servera: Connects to the servera machine.
cd ~: Navigates to the home directory of the student user.
mkdir Music Pictures Videos: Creates the three directories.
touch Music/song{1..6}.mp3 Pictures/snap{1..6}.jpg Videos/film{1..6}.avi: Uses brace expansion to create the sets of files.
mv [files] [directory]: Moves the created files into their respective directories.
mkdir friends family work: Creates the directories for organization.
cp [files] friends and cp [files] family: Copies necessary files into the "friends" and "family" directories respectively.
cp -r family friends work: Copies directories into work.
rm -r family friends work: Removes the directories as a cleanup step.
exit: Ends the SSH session.
lab finish files-manage: Completes the lab by executing the lab finish command on the local workstation.
This command assumes that all steps need to be executed in one go within a single SSH session. Ensure that SSH keys are properly set up, as the command expects passwordless login.
Guided Exercise: Make Links Between Files
Create hard links and symbolic links and compare the results.
Outcomes
Create hard links and symbolic links between files.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start files-make
Instructions
Use the ssh command to log in to the servera machine as the student user. The system's configuration supports the use SSH keys for authentication; therefore, you do not require a password.
[student@workstation ~]$ ssh student@servera
...output omitted...
[student@servera ~]$
Create a hard link called /home/student/links/file.hardlink for the file /home/student/files/target.file. Verify the link count for the original file and the new linked file.
View the link count for the file /home/student/files/target.file.
[student@servera ~]$ ls -l files/target.file
total 4
-rw-r--r--. 1 student student 11 Mar 3 06:51 files/target.file
Create a hard link called /home/student/links/file.hardlink. Link it to the file /home/student/files/target.file.
[student@servera ~]$ ln /home/student/files/target.file \
/home/student/links/file.hardlink
Verify the link count for the original file /home/student/files/target.file and the new linked file, /home/student/files/file.hardlink. The link count should be 2 for both files.
[student@servera ~]$ ls -l files/target.file links/file.hardlink
-rw-r--r--. 2 student student 11 Mar 3 06:51 files/target.file
-rw-r--r--. 2 student student 11 Mar 3 06:51 links/file.hardlink
Create a symbolic link called /home/student/tempdir that points to the /tmp directory on the servera machine. Verify the newly created symbolic link.
Create a symbolic link called /home/student/tempdir and link it to the /tmp directory.
[student@servera ~]$ ln -s /tmp /home/student/tempdir
Use the ls -l command to verify the newly created symbolic link.
[student@servera ~]$ ls -l /home/student/tempdir
lrwxrwxrwx. 1 student student 4 Mar 3 06:55 /home/student/tempdir -> /tmp
Return to the workstation system as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$
Finish
On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.
[student@workstation ~]$ lab finish files-make
ssh student@servera: Connects to servera using SSH.
Hard Link Creation:
mkdir -p ~/links: Ensures the links directory exists.
ln ~/files/target.file ~/links/file.hardlink: Creates a hard link in the links directory.
Verification of Hard Link:
echo "Verify hard link:"; ls -l ~/files/target.file ~/links/file.hardlink: Lists the link count for both the original and the hard-linked files to verify their counts are correct.
Symbolic Link Creation:
ln -s /tmp ~/tempdir: Creates a symbolic link called tempdir pointing to /tmp.
Verification of Symbolic Link:
echo "Verify symbolic link:"; ls -l ~/tempdir: Outputs the details of the symbolic link to verify it points to /tmp.
Exit SSH Session:
exit: Immediately terminates the SSH session, bringing you back to the local machine.
Finishing with Lab Command:
lab finish files-make: Ensures that the resources are reset, completing the exercise.
This command does not require any manual intervention if you have SSH keys set up for passwordless login. The script is written to be idempotent regarding directory creation and verification, only requiring the specified files to exist on the remote server at the paths specified. Adjust paths as necessary if they differ in your environment.
“Solve each sub-problems: ` 1. Which command returns to your current home directory,….” Conversation with gpt-4o-2024-08-06, from the WildChat-4.8M (AI2) dataset. The Chat Archive, 2024. https://thechatarchive.com/c/01m7h41vyda2vpf9yk31xyjnth