RHCSA voor friends
  • 0.0 Itinerary
  • 0.1 Environment
  • 1.0 Access
  • 1.1 SSH-keys
  • 1.2 Console Access
  • 2.0 File System Navigation
  • 2.1 Navigation and File Management
  • 2.2 Running Command as Root
  • 2.3 Checking Filesystems
  • 2.4 Symlinks
  • 2.5 Secure Copy
  • 3.0 Bash Scripting
  • 3.1 Find, Grep and IO
  • 3.2 Bash Completion
  • 3.3 Man Pages
  • 3.4 Environments
  • 4.0 Text Files
  • 4.1 Reading Text Files
  • 4.2 Text Editor: VIM
  • 5.0 Users, Groups and Passwords
  • 5.1 Create Users using CLI
  • 5.2 Managing Groups Using CLI
  • 5.3 Managing User Password Aging
  • 6.0 File PErmissions and ACL’s
  • 6.1 Managing File Security from the CLI
  • 6.2 Controlling New File Permissions and Ownerships
  • 6.3 Using ACL’s to Grant and Limit Access
  • 7.0 SELinux
  • 7.1 SEManage
  • 7.2 SEContext
  • 7.3 SEAlert
  • 7.4 SEBoolean
  • 8.0 DNF
  • 8.1 Repositories
  • 8.2 Install and Update Software
  • 9.0 System Processes and Systemd
  • 9.1 Killing Processes
  • 9.2 Process Priorities
  • 9.3 Systemd
  • 10.0 Networking
  • 10.1 Network Configuration
  • 10.2 Host names
  • 10.3 IPv6
  • 11.0 Time Settings
  • 11.1 Adjust System Time
  • 12.0 Logging
  • 12.1 Logging and Rsyslog
  • 13.0 Disk Management
  • 13.1 Mounting and Creating filesystems
  • 13.2 Swap Space
  • 14.0 Boot Process and the Kernel
  • 14.1 Boot Issues
  • 14.2 Resetting Passwords
  • 15 Advanced Disk Management
  • 15.1 LVM
  • 15.2 Resize LVM
  • 16.0 Cron
  • 16.2 Adding Cron Jobs
  • 17.0 Website and FirewallD
  • 17.1 Website and FirewallD
  • 18.0 Tuned
  • 18.1 Configuring Tuned
  • 19.0 Networks: Users and Filesystems
  • 19.1 Networks: Mounting Network Filesystems
  • 19.2 FTP
  • 20.0 Archiving with TAR
  • 20.0 File Compression
  • 21.0 Podman
  • 21.0 How to Podman
  • Module 22.0 Lab
RHCSA voor friends
  • »
  • 2.1 Navigation and File Management
  • Bekijk paginabron

2.1 Navigation and File Management

Make sure you are logged into your machine! You will practice how to organize files and use directories.

Start from your home directory on your machine

Create 6 of the each of the following files:

  • song[X].mp3

  • snap[X].jpg

  • film[X].avi

You could do this one by one:

touch song1.mp3
touch song2.mp3
touch song3.mp3
touch song4.mp3
touch song5.mp3
touch song6.mp3

Or make multiple at the same time with the same command:

touch snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg

Or make them all at the same time using some very basic scripting:

touch film{1..6}.avi

In the end, when listing all files your output should look like this:

[greater@rhcsa ~]$ ls -l
total 0
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film1.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film2.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film3.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film4.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film5.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 film6.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap1.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap2.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap3.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap4.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap5.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:05 snap6.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song1.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song2.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song3.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song4.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song5.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 16:04 song6.mp3

Now lets make sure that we are in our home directory, we do this by using the pwd (print working directory) command.

The result should be something like below:

[greater@rhcsa ~]$ pwd
/home/greater

We can move to a different directory with using cd (change directory). And the ~ sign correlates to our home directory. So to make sure we change to our home directory we can use below command:

[greater@rhcsa ~]$ cd ~

Next we’re going to create some directories for the files in your home directory. This is done with the mkdir (make directory) command. Using this command, create the following directories:

  • music

  • pictures

  • movies

For example:

mkdir music pictures movies

Lets move the files to their corresponding directories with the mv (move) command:

  • Move the song files to music

  • Move the snap files to pictures

  • Move the film files to movies

We can do it all in the same command:

mv song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3 music

Alternatively we can use a wildcard *, which will select every file that starts with the text before the wildcard symbol:

mv snap* pictures

Finally we can again use basic scripting to select all files:

mv film{1..6}.avi movies

Now lets organize the files according to project create the directories:

  • friends

  • family

  • work

mkdir friends family work

You will collect some of the new files into the project directories for 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 into this directory. You are making copies, since you will keep the originals after giving these projects to family and friends.

Copy files (all types) containing numbers 1 and 2 to the friends folder. Copy files (all types) containing numbers 3 and 4 to the family folder. When collecting files from multiple locations into one location, change to the directory that will contain the destination files. Use the simplest path syntax, absolute or relative, to reach the source for each file management task.

note the . at the end of the copy command: this instructs the computer to copy the files to the location you are in and keep the name.

cd friends
cp ../music/song1.mp3 ../music/song2.mp3 ../pictures/snap1.jpg ../pictures/snap2.jpg ../movies/film1.avi ../movies/film2.avi .

It should look like this:

[greater@rhcsa friends]$ ll
total 0
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 film1.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 film2.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 snap1.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 snap2.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 song1.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 20:13 song2.mp3
cd ../family
cp ../music/song3.mp3 ../music/song4.mp3 ../pictures/snap3.jpg ../pictures/snap4.jpg ../movies/film3.avi ../movies/film4.avi .

It should look like this:

[greater@rhcsa family]$ ll
total 0
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 film3.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 film4.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 snap3.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 snap4.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 song3.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 song4.mp3
cd ../work
cp ../music/song5.mp3 ../music/song6.mp3 ../pictures/snap5.jpg ../pictures/snap6.jpg ../movies/film5.avi ../movies/film6.avi .

It should look like this:

[greater@rhcsa work]$ ll
total 0
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 film5.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 film6.avi
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 snap5.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 snap6.jpg
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 song5.mp3
-rw-rw-r-- 1 greater greater 0 Nov 23 20:14 song6.mp3

Now that you are done playing around with files, lets clean up the files we no longer need.

Change to your home directory. Attempt to delete both the family and friends project with a singe rmdir command.

cd ~

Now let’s try to remove family and friends, who needs those anyways!

rmdir family friends

You should get an error like this:

greater@rhcsa ~]$ rmdir family friends
rmdir: failed to remove 'family': Directory not empty
rmdir: failed to remove 'friends': Directory not empty

The above command failed because there are still files in the directories. The below command will use the addition -r for recursive. This will succeed in removing your friends and family directories and the files in inside. This will require confirmation for each file you are removing, if you do not wish to provide confirmation for each file then you can choose to use the -f (force) option as well.

rm -r family friends

Check with ls -l if the directories were removed and finish up by removing each file within the work folder.

cd work
rm song5.mp3 song6.mp3 snap5.jpg snap6.jpg film5.avi film6.avi 

or

rm *

change the directory back with the cd command and remove the directory.

cd
rmdir work

This should delete the work directory. Clean up the remaining directories yourself.

Vorige Volgende

© Copyright MIT License.

Gebouwd met Sphinx met een thema geleverd door Read the Docs.