In: Computer Science
PART 5: Learn about commands used to view contents of files:
type: cat passwd.bak
2. now add the |more to the last command (see what happens when you push the up arrow curser key-it recalls the last command)
3. now try to cat the passwd.bak file but look at the first few lines and then the last few lines using the head and tail commands
type: head passwd.bak and tail passwd.bak
4. let’s now add the n2 option to the head and tail commands and see what happens
5. let’s look more at the cat command and redirection of output to a file:
type: cat > file1 and enter a paragraph about how you feel about Unix. Hit the ctrl and d to exit
6. create another file: ls -ali > file50
7. add to that file: cat /passwd.bak >> file50
8. review your work using the cat command
9. try to pull out any lines from the file50 with root: grep root file50
10. HAND-IN: Screen Capture #4 of of the above activities
PART 6: Let’s practice utilizing files and directories in our file systems structure:
test
|
dir1 dir2 dir3 dir4
|
dir5 dir6
2. create some files in all of these directories using the cat or touch command
3. try a new command: move or mv. Use the mv command to move a file from one directory to another but notice that the inode number stays the same
4. use rm and rmdir to remove two files and dir4
5. HAND-IN: Screen Capture #5 of of the above activities
All the activities are shown in the form of screen shots. Please note i have created a file with the same name under the same path what is been mentioned in the problem statement ie. /home/test/passwd.bak.
Screen 1 : It shows only the command used to display the file /home/test/passwd.bak content
Screen 2: It shows when i open the file passwd.bak
Screen 3: As the entire file does not fit in a screen, we have to use more command to display the content of the file page wise. Hence we go for the following command :
cat /home/test/passwd.bak | more ( This command uses the pipe feature of the shell indicated as "|" , which takes the output of previous command as input and produces the results. You will see the keywor More at the end of the screen. )
Screen 4: When you view the file using the following command it displays the top 10 lines from the beginning of the file. (The head command, by default it displays top 10 lines if the number of lines option is not specified.)
head /home/test/passwd.bak
Note : The 10th line is a blank line. Ok.
Screen 5: Similarly, to display the bottom 10 lines of the file, we use the tail command. This command also prints 10 lines by default if we dont mention how many lines from the bottom is not specified. the command is as follows:
tail /home/test/passwd.bak
Screen 6: Now , lets see the change, by providing the number lines to be displayed from the begining with an option:
head -n 2 /home/test/passwd.bak
This command displays only the two lines from the begining of the file. Here the option -n is used to specify the number of lines from the begining.
Screen 7 : Lets see the same option with the tail command. To display the required number of ending lines of a file the command is :
tail -n 2 /home/test/passwd.bak
The above command displayed las two lines of the file.