RHCE Certification: RedHatLinux033 lab section

Source: Internet
Author: User
-1-RedHatLinux033 Experiment Part 3 file and directory Operation estimated time: 1 hour 30 minutes objective: familiar with functions

-1-

Red Hat Linux 033 lab section


Test 3 Estimated time for file and directory operations: 1 hour and 30 minutes
Objective: To be familiar with functions, syntax, and some basic file and directory control operations. Exercise effectively combining these commands to complete Common User Tasks
Start Point of the experiment: The Red Hat Linux runable system is installed, and a unprivileged user, student, password: student


Step 1: Directory and file organization scenarios/plots
There are a series of files in your home directory. You have decided to sort them out. you plan to generate new subdirectories, and copy and move these files to the appropriate directory according to your plan. In addition, these files are not all useful, some are to be deleted.


Task:
1. log on to tty1.


2. After you log on to the system, you will enter your home directory. You can use "Print working directory" to check this situation
$ Pwd
/Home/student


3. Use each of the following commands to check if you have any files in your home directory:
$ Ls
$ Ls-
$ Ls-al why does the first and second commands return different files? What is the maximum file returned by the third command in your current home directory? Is there a subdirectory in your home directory?


4. Now you use touch to create a file for subsequent steps. How this extension works in the following commands will be discussed in later chapters. Now, just enter the following line (use the characters including curly braces {} and underline between the set and the Set)
$ Touch {report, memo, graph }_{ sep, oct, nov, dec }_{ a, B, c} {1, 2, 3}


5. Run the ls command to check the result of the last command. You will find that it has generated 108 new Empty files in your home directory (you do not need to count ). These files represent the data files that you will use in this step. If you do not see these files, ask the instructor for help. Without these files, the subsequent steps of the test will not work.


6. To organize your files, you must first create some new directories and use mkdir to directly create subdirectories in your home directory:
$ Mkdir a_reports
$ Mkdir September October November December
Then use ls to check your work.
-2-


7. Use the following command to generate some additional subdirectories in your new directory.
$ Cd a_reports
To switch to the directory, follow these steps:
$ Mkdir 1 2 3
Use ls to check the three new subdirectories named 1, 2, and 3 under your subdirectory a_reports.


8. First, remove all reports with "B" from the home directory and group them by month. It is a good method to verify the complex wildcard mode to be used. This
Sample to ensure that it operates on the correct file. If you want to use this wildcard mode, you can use a harmless command to replace your command.
$ Cd
$ Ls-l * dec? B?
You will see nine "December" and "B" files listed, and move one of them to the December directory:
$ Mv graph_dec_b1 December
Use the following statement to move the rest:
$ Mv * dec? B? December
List the contents of the December directory to verify whether the mobile operation is successful:
$ Ls-l December total 0
-Rw-r -- 1 student 0 Sep 18 17:45 graph_dec_b1
-Rw-r -- 1 student 0 Sep 18 17:45 graph_dec_b2
-Rw-r -- 1 student 0 Sep 18 17:45 graph_dec_b3
-Rw-r -- 1 student 0 Sep 18 17:45 memo_dec_b1
-Rw-r -- 1 student 0 Sep 18 17:45 memo_dec_b2
-Rw-r -- 1 student 0 Sep 18 17:45 memo_dec_b3
-Rw-r -- 1 student 0 Sep 18 17:45 report_dec_b1
-Rw-r -- 1 student 0 Sep 18 17:45 report_dec_b2
-Rw-r -- 1 student 0 Sep 18 17:45 report_dec_b3


9. Move all other reports with "B" to their respective directories:
$ Mv * oct? B? October
$ Mv * sep? B? September


10. Now you will collect the "a" report to their respective directories. Note ~ Replace "your home
Directory ". The combination of wildcards and modes specifies all the files ending with _ a1 in your home directory.
$ Cd a_reports
$ Mv ~ /* _ A1 1/
"September" a1 "files are outdated and no longer needed. Use echo to confirm that you have created a pattern that only matches these files, and then delete them,
And check whether the remaining "a1" files are correctly moved:
$ Cd 1
$ Echo * sep *
$ Rm * sep *
$ Ls
Graph_dec_a1 graph_oct_a1 memo_nov_a1 report_dec_a1 report_oct_a1 graph_nov_a1 memo_dec_a1 memo_oct_a1 report_nov_a1
-3-


11. Finally, move the "a2" and "a3" reports to their respective directories. To make the process interesting, we will
They are removed from the current directory and use relative and absolute path names. Step 1: Use pwd to determine the current directory:


$ Pwd
/Home/student/a_reports/1


Use echo to check the mode involving the "a2" file, and then use the absolute path name:
$ Echo/home/student/* a2 *
$ Mv/home/student/* a2 */home/student/a_reports/2 even if you are in the/home/student/a_reports/1 directory, you can also move the file from the/home/student to the/home/student/a_reports/2 Directory because you have specified the file path name (in this example, the absolute path name)


Now, move the "a3" file in the relative path. Again, make sure that the mode specifies the correct file name.


$ Echo.../* a3 *
$ Mv.../* a3 * ../3


12. Return to your home directory, and use ls to verify that only files in this directory are "c" files (for example: graph_dec_c1, graph_dec_c2 ,...)


13. The "c1" and "c2" report files are important each month and you plan to back up them to another directory:


$ Mkdir/tmp/archive
$ Cp report * [12]/tmp/archive/


In addition, all report files for April December should be backed up to the/tmp/archice directory. Note that the-I option prompts the cp program to overwrite any file:


$ Cp-I report_dec */tmp/archive/
Cp: overwrite '/tmp/archive/report_dec_c1 '? N cp: overwrite '/tmp/archive/report_dec_c2 '? N


14. Now you have backed up some important "c" files for you. Now you want to delete all the files under your home directory. Use the wildcard "* c *" to check
The remaining files contain c. Why don't you want to execute the command rm * c *?
(As a prompt: Try: ls * c *)
15. Delete the remaining ** files in your home directory. We use the echo command again before issuing a destructive command.
$ Echo * c [1-3]
$ Rm * c [1-3]
$ Ls
A_reports December November October September


Test Results
A well-organized home directory where the files are placed in a reasonable location, and some files are backed up to the/tmp/archive directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.