Chapter 5


1.

Calculate the size of all files under the /etc directory.

the du -ah /etc command prints the size of all files under the /etc directory. the -a option to the du command prints the sizes for all files in the subdirectories, rather than just the size of the directory and subdirectories. the -h option prints the output in a human-readable form, indicating the size of the files in bytes, kilobytes, or megabytes. refer to the du man page for more options.

2.

Create a file called story.txt containing the following line of text:

 The quick brown fox jumps over the lazy dog 

Use the sed command to change the contents of the file to the following:

 The quick brown dog jumps over the lazy fox 

the following commands will modify the content of the file as desired: $ sed e 's;dog;fox;' simple.txt - temporary.txt$ sed e 's;brown fox;brown dog;' temporary.txt - simple.txt the first sed command substitutes the word dog for the word fox. this is redirected to a file called temporary.txt . this file will now contain the text the quick brown fox jumps over the lazy fox . the second sed command needs to convert only the first occurrence of fox into dog. therefore it replaces the two words brown fox with the words brown dog, resulting in the text the quick brown dog jumps over the lazy fox .

3.

Use the find command to list files that are greater than 500KB in size created by users of the system.

users files are typically stored under the /home directory. because you need to search files belonging to other users, you will need to assume root privileges either by using the su command or by logging in as root before executing the find command. the find command line for obtaining the list of files greater than 500kb created by users is as follows: # find /home type f size +500k the -type f option indicates that we are looking for files (not directories or other filesystem objects). the -size option indicates that our search criterion is the size of files, and +500k indicates that we are searching for files larger than 500kb.

Answers

1.

The du -ah /etc command prints the size of all files under the /etc directory. The -a option to the du command prints the sizes for all files in the subdirectories, rather than just the size of the directory and subdirectories. The -h option prints the output in a human-readable form, indicating the size of the files in bytes, kilobytes, or megabytes. Refer to the du man page for more options.

2.

The following commands will modify the content of the file as desired:

 $ sed e 's;dog;fox;' simple.txt > temporary.txt      $ sed e 's;brown fox;brown dog;' temporary.txt > simple.txt 

The first sed command substitutes the word dog for the word fox. This is redirected to a file called temporary.txt . This file will now contain the text The quick brown fox jumps over the lazy fox . The second sed command needs to convert only the first occurrence of fox into dog. Therefore it replaces the two words brown fox with the words brown dog, resulting in the text The quick brown dog jumps over the lazy fox .

3.

Users files are typically stored under the /home directory. Because you need to search files belonging to other users, you will need to assume root privileges either by using the su command or by logging in as root before executing the find command. The find command line for obtaining the list of files greater than 500KB created by users is as follows :

 # find /home type f size +500k 

The -type f option indicates that we are looking for files (not directories or other filesystem objects). The -size option indicates that our search criterion is the size of files, and +500k indicates that we are searching for files larger than 500KB.




Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net