Red Hat System Administration I
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
serveramachine as thestudentuser. In thestudentuser's home directory, create three subdirectories:Music,Pictures, andVideos.Use the
sshcommand to log in to theserveramachine as thestudentuser. 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
studentuser's home directory, use themkdircommand to create three subdirectories:Music,Pictures, andVideos.[student@servera ~]$
mkdir Music Pictures Videos
Use the
touchcommand to create sets of empty practice files to use during this lab. In each set, replaceXwith the numbers 1 through 6.Create six files with names of the form
song.X.mp3Create six files with names of the form
snap.X.jpgCreate 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 VideosMove the song files (
.mp3extension) to theMusicdirectory, the snapshot files (.jpgextension) to thePicturesdirectory, and the movie files (.aviextension) to theVideosdirectory.[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.aviCreate three subdirectories for organizing your files, and name the subdirectories
friends,family, andwork. 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 workCopy files that contain numbers
1and2to thefriendsdirectory, and files that contain numbers3and4to thefamilydirectory. 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
1and2to thefriendsdirectory.[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.mp3Copy files that contain numbers
3and4to thefamilydirectory.[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
familyandfriendsdirectories and their contents to theworkdirectory.[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 friendsYour project tasks are now complete, and it is time to clean up the directories. Use the
rm -rcommand to recursively delete thefamily,friends, andworkdirectories 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 VideosReturn to the
workstationsystem as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation ~]$