In this exercise, you create, organize, copy, and remove files and directories.
Outcomes
Create, organize, copy, and remove files and directories.
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-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 VideosUse 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 song.X.mp3
Create six files with names of the form snap.X.jpg
Create six files with names of the form film.X.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 -ltotal 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 VideosMusic: 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 -ltotal 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 -ltotal 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 -ltotal 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 -ltotal 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 -ltotal 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 ~]$This concludes the section.