In this exercise you will create, organize, copy, and remove files and directories.
Outcomes
You should be able to create, organize, copy, and remove files and directories.
Log in as the student user on workstation using student as the password.
On workstation, run the lab files-manage start command.
This command runs a start script that determines if the servera machine is reachable on the network.
[student@workstation ~]$lab files-manage start
Use the ssh command to log in to servera 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
Continuing in the student user's home directory, use the touch command to create sets of empty practice files to use during this lab.
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
In each set, replace X with the numbers 1 through 6.
[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-rw-r--. 1 student student 0 Feb 4 18:23 film1.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film2.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film3.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film4.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film5.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film6.avi drwxrwxr-x. 2 student student 6 Feb 4 18:23 Music drwxrwxr-x. 2 student student 6 Feb 4 18:23 Pictures -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap1.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap2.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap3.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap4.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap5.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap6.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 song1.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song2.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song3.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song4.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song5.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song6.mp3 drwxrwxr-x. 2 student student 6 Feb 4 18:23 Videos
Continuing in the student user's home directory, move the song files to the Music subdirectory, the snapshot files to the Pictures subdirectory, and the movie files to the Videos subdirectory.
When distributing files from one location to many locations, first change to the directory containing the source files. Use the simplest path syntax, absolute or relative, to reach the destination for each file management task.
[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-rw-r--. 1 student student 0 Feb 4 18:23 song1.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song2.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song3.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song4.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song5.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:23 song6.mp3 Pictures: total 0 -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap1.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap2.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap3.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap4.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap5.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:23 snap6.jpg Videos: total 0 -rw-rw-r--. 1 student student 0 Feb 4 18:23 film1.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film2.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film3.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film4.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film5.avi -rw-rw-r--. 1 student student 0 Feb 4 18:23 film6.avi
Continuing in the student user's home directory, create three subdirectories for organizing your files into projects.
Name the subdirectories friends, family, and work.
Use a single command to create all three subdirectories at the same time.
You will use these directories to rearrange your files into projects.
[student@servera ~]$mkdir friends family work[student@servera ~]$ls -ltotal 0 drwxrwxr-x. 2 student student 6 Feb 4 18:38 family drwxrwxr-x. 2 student student 6 Feb 4 18:38 friends drwxrwxr-x. 2 student student 108 Feb 4 18:36 Music drwxrwxr-x. 2 student student 108 Feb 4 18:36 Pictures drwxrwxr-x. 2 student student 108 Feb 4 18:36 Videos drwxrwxr-x. 2 student student 6 Feb 4 18:38 work
Copy a selection of new files to the project directories family and friends.
Use as many commands as needed.
You do not have to use only one command as in the example.
For each project, first change to the project directory, then copy the source files to this directory.
Keep in mind that you are making copies, therefore the original files will remain in their original locations after the files are copied to the project directories.
Copy files (all types) containing the numbers 1 and 2 in to the friends subdirectory.
Copy files (all types) containing the numbers 3 and 4 in to the family subdirectory.
When copying files from multiple locations into a single location, Red Hat recommends that you change to the destination directory prior to copying the files. Use the simplest path syntax, absolute or relative, to reach the source for each file management task.
[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-rw-r--. 1 student student 0 Feb 4 18:42 film1.avi -rw-rw-r--. 1 student student 0 Feb 4 18:42 film2.avi -rw-rw-r--. 1 student student 0 Feb 4 18:42 snap1.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:42 snap2.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:42 song1.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:42 song2.mp3[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 -rw-rw-r--. 1 student student 0 Feb 4 18:44 film3.avi -rw-rw-r--. 1 student student 0 Feb 4 18:44 film4.avi -rw-rw-r--. 1 student student 0 Feb 4 18:44 snap3.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:44 snap4.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:44 song3.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:44 song4.mp3
For your work project, create additional copies.
[student@servera family]$cd ../work[student@servera work]$cp ~/Music/song5.mp3 ~/Music/song6.mp3 \~/Pictures/snap5.jpg ~/Pictures/snap6.jpg \~/Videos/film5.avi ~/Videos/film6.avi .[student@servera work]$ls -ltotal 0 -rw-rw-r--. 1 student student 0 Feb 4 18:48 film5.avi -rw-rw-r--. 1 student student 0 Feb 4 18:48 film6.avi -rw-rw-r--. 1 student student 0 Feb 4 18:48 snap5.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:48 snap6.jpg -rw-rw-r--. 1 student student 0 Feb 4 18:48 song5.mp3 -rw-rw-r--. 1 student student 0 Feb 4 18:48 song6.mp3
Your project tasks are now complete, and it is time to clean up the projects.
Change to the student user's home directory.
Attempt to delete both the family and friends project directories with a single rmdir command.
[student@servera work]$cd[student@servera ~]$rmdir family friendsrmdir: failed to remove 'family': Directory not empty rmdir: failed to remove 'friends': Directory not empty
Using the rmdir command should fail because both subdirectories contain files.
Use the rm -r command to recursively delete both the family and friends subdirectories and their contents.
[student@servera ~]$rm -r family friends[student@servera ~]$ls -ltotal 0 drwxrwxr-x. 2 student student 108 Feb 4 18:36 Music drwxrwxr-x. 2 student student 108 Feb 4 18:36 Pictures drwxrwxr-x. 2 student student 108 Feb 4 18:36 Videos drwxrwxr-x. 2 student student 108 Feb 4 18:48 work
Delete all the files in the work project, but do not delete the work directory.
[student@servera ~]$cd work[student@servera work]$rm song5.mp3 song6.mp3 snap5.jpg snap6.jpg \film5.avi film6.avi[student@servera work]$ls -ltotal 0
Finally, from the student user's home directory, use the rmdir command to delete the work directory.
The command should succeed now that it is empty.
[student@servera work]$cd[student@servera ~]$rmdir work[student@servera ~]$ls -ltotal 0 drwxrwxr-x. 2 student student 108 Feb 4 18:36 Music drwxrwxr-x. 2 student student 108 Feb 4 18:36 Pictures drwxrwxr-x. 2 student student 108 Feb 4 18:36 Videos
Exit from servera.
[student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$