View file organization in a Linux file system and manipulate directories and files.
Outcomes
View directory and file structure.
Create, organize, copy, and remove files and directories.
Search for files.
Filter text in text files.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start filesystem-review
Instructions
List the files and directories in the student home directory.
Create the utilities, scripts, and backups subdirectories in the Documents directory.
Review the directory structure.
View a list of entries in the home directory.
[student@workstation ~]$ ls -l
total 0
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Desktop
drwxr-xr-x. 5 student student 53 Nov 9 21:35 Documents
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Downloads
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Music
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Pictures
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Public
drwxr-xr-x. 2 student student 6 Nov 9 21:09 Templates
drwxr-xr-x. 2 student student 6 Nov 9 21:09 VideosCreate the utilities, scripts, and backups directories in the Documents directory.
[student@workstation ~]$mkdir Documents/utilities[student@workstation ~]$mkdir Documents/scripts[student@workstation ~]$mkdir Documents/backups[student@workstation ~]$ls Documentsbackups scripts utilities
View the /home/student directory structure.
[student@workstation ~]$ tree
.
├── Desktop
├── Documents
│ ├── backups
│ ├── scripts
│ └── utilities
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
└── Videos
11 directories, 0 filesCreate servicedump.log, daily-task.sh, to-do.txt, and my-exec as empty files in the utilities directory.
Change to the ~/Documents/utilities directory.
[student@workstation ~]$ cd ~/Documents/utilitiesCreate the servicedump.log, daily-task.sh, to-do.txt, and my-exec files.
[student@workstation utilities]$touch servicedump.log daily-task.sh \to-do.txt my-exec[student@workstation utilities]$ls -ltotal 0 -rw-r--r--. 1 student student 0 Nov 9 21:38 daily-task.sh -rw-r--r--. 1 student student 0 Nov 9 21:38 my-exec -rw-r--r--. 1 student student 0 Nov 9 21:38 servicedump.log -rw-r--r--. 1 student student 0 Nov 9 21:38 to-do.txt
In the utilities directory, copy the daily-task.sh file to the scripts directory, and move the to-do.txt file to the backups directory.
Copy the daily-task.sh file from the utilities directory to the scripts directory.
[student@workstation utilities]$cp daily-task.sh ../scripts/[student@workstation utilities]$ls -l ../scripts/total 0 -rw-r--r--. 1 student student 0 Nov 9 21:39 daily-task.sh
Move the to-do.txt file to the backups directory.
[student@workstation utilities]$mv to-do.txt ../backups/[student@workstation utilities]$ls -l ../backups/total 0 -rw-r--r--. 1 student student 0 Nov 9 21:38 to-do.txt
Navigate to the student home directory.
Search in the Documents directory to find all the files that contain the string daily in the file name.
Use the Documents directory's full path to perform the search.
Save the output to the ~/results file.
Change to the student user's home directory.
[student@workstation utilities]$ cd
[student@workstation ~]$Search in the /home/student/Documents directory to find all files with the string daily in their name.
Use the Documents directory's full path to perform the search.
Save the output to the ~/results file.
[student@workstation ~]$ find /home/student/Documents -name "*daily*" > ~/resultsVerify that the results file has the expected content.
[student@workstation ~]$ cat results
/home/student/Documents/utilities/daily-task.sh
/home/student/Documents/scripts/daily-task.shSearch the entire file system for the system dictionary file called words.
The expected words file is stored in the dict parent directory.
If the command produces errors, then run the command again and use output redirection to save any errors to the ~/error-results file.
After you locate the words file, use redirection to append the first 15 lines of the words file to the ~/results file.
Start the search for the words file in the / directory.
The expected words file is stored in the dict parent directory.
[student@workstation ~]$ find / -name "words"
find: '/proc/34297/map_files': Permission denied
find: '/proc/34297/ns': Permission denied
find: '/proc/34299/task/34299/fd': Permission denied
find: '/proc/34299/task/34299/ns': Permission denied
find: '/proc/34299/fd': Permission denied
...output omitted...The find command returns many errors.
Repeat the search, and use output redirection to save any errors to the ~/error-results file.
[student@workstation ~]$find / -name "words" 2> ~/error-results/usr/share/dict/words/usr/share/doc/words
The /usr/share/dict/words file matches the requirements.
Append the first 15 entries of the /usr/share/dict/words file to the ~/results file.
Use redirection to save the results to the ~/results file.
[student@workstation ~]$ head -15 /usr/share/dict/words >> ~/resultsVerify that the ~/results file has the expected content.
[student@workstation ~]$ cat results
/home/student/Documents/utilities/daily-task.sh
/home/student/Documents/scripts/daily-task.sh
1080
10-point
10th
11-point
12-point
16-point
18-point
1st
2
20-point
2,4,5-t
2,4-d
2D
2nd
30-30