Managing Files from the Command Line
The objective of this lab was to perform various tasks on files from the command line on a workstation and server machine. The tasks included creating directories and files, copying and editing text files, creating hard and symbolic links, and saving the output of a command to a file.
Outcomes
The lab allowed me to:
- Manage files from the command line.
- Display a specific number of lines from text files and redirect the output to another file.
- Edit text files.
- Create the /home/student/grading directory.
- Create three empty files in the /home/student/grading directory called grade1, grade2, and grade3.
- Capture the first five lines of the /home/student/bin/manage file in the /home/student/grading/review.txt file.
- Append the last three lines of the /home/student/bin/manage file to the /home/student/grading/review.txt file. Do not overwrite any existing text in the /home/student/grading/review.txt file.
- Copy the /home/student/grading/review.txt file to the /home/student/grading/review-copy.txt file.
- Edit the /home/student/grading/review-copy.txt file so that the Test JJ line appears twice.
- Edit the /home/student/grading/review-copy.txt file to remove the Test HH line.
- Edit the /home/student/grading/review-copy.txt file so that a A new line line exists between the Test BB line and the Test CC line.
- Create the /home/student/hardcopy hard link to the /home/student/grading/grade1 file. You must do this after completing the earlier step to create the /home/student/grading/grade1 file.
- Create the /home/student/softcopy symbolic link to the /home/student/grading/grade2 file.
- Save the output of a command that lists the contents of the /boot directory to the /home/student/grading/longlisting.txt file. The output should be a "long listing" that includes file permissions, owner and group owner, size, and modification date of each file.
Tasks
Specifications
Creating Directories and Files: First, I created the /home/student/grading directory on the server machine using the mkdir command. Next, I used the touch command and brace expansion shell feature to create the grade1, grade2, and grade3 files in the grading directory.
Editing and Copying Files: I used the head command to capture the first five lines of the /home/student/bin/manage file and redirected the output to the review.txt file.
Then, I used the tail command to append the last three lines of the same file to review.txt without overwriting the existing text.
After this, I copied review.txt to /home/student/grading/review-copy.txt file using the cp command.
I edited thereview-copy.txt file using the vim editor to add a second Test JJ line, remove the Test HH line, and insert a new line between Test BB and Test CC.
Creating Links:
I created a hard link to the /home/student/grading/grade1 file using the ln command.
Next, I created a symbolic link to the /home/student/grading/grade2 file using the ln -s command.
Saving Output to a File: I used the ls -l command to list the contents of the /boot directory and saved the output to the /home/student/grading/longlisting.txt file using the > symbol to overwrite any existing content.
Conclusion
The lab allowed me to learn various commands and techniques to manage files from the command line. I was able to create directories and files, copy and edit text files, create hard and symbolic links, and save the output of a command to a file.
0 Comments Add a Comment?