The second file named file2 should contain This is file2 List the files in this

The second file named file2 should contain this is

This preview shows page 14 - 16 out of 25 pages.

The second file named “file2” should contain: This is file2. List the files in this directory in the way you did above. You should see file1 and file2 there now. 6.7 Displaying files’ contents The cat command displays the entire contents of a file, so you can see file2’s contents by typing: baby:~: cat file2 If the file being displayed contains more than a screenful of text, the more command is preferable, since it displays the file’s contents one page at a time, pausing after each page. baby:~: more file2 After each page is displayed pressing the space bar (when the “ --More-- ” prompt is seen) causes the next page to be displayed, while pressing return or enter causes only the next one line to be shown. Pressing the ’ q ’ key quits displaying the file’s contents. The less command does the same thing as the more command, but has additional capabilities (less is more in this case); you’re encouraged to just use less in place of more in commands like that above. 6.8 Copying a file Now copy the contents of file1 to a new file that will be called file3. baby:~: cp file1 file3 List the files in the directory. file3 should have been added to file1 and file2 in the listing. Look at file3 to see what it has in it, using the cat command: baby:~: cat file3 Since you’re still located in the subdirectory you created of your home directory, to make a copy of file1 in your home directory with the same name you can use any one of the following: baby:~: cp file1 .. baby:~: cp file1 ~ baby:~: cp file1 ~ loginID If the second word after the cp command is a directory name (not a filename) then the file will be copied to that directory, using the same name as it presently has. To make a copy of file1 in your home directory with a different name, such as “testfile”, you can use any of the following: baby:~: cp file1 ../testfile baby:~: cp file1 ~/testfile baby:~: cp file1 ~ loginID /testfile 14
Image of page 14
If the second word after the cp command is a filename with another directory’s name in front of it, then the file will be copied to that directory, with that name. The first of these commands shows where you want testfile to be located relative to the current directory (i.e., one directory above the current one). The second and third show where you want testfile to be located relative to your home directory. If your login ID (home directory) was named student123 and you knew that it was located, for example, in the directory /homes, you could also make a copy of file1 from the current directory to your home directory with the name testfile using the command “ cp file1 /homes/student123/testfile ”, but since the full path name is extra work to type there isn’t much advantage to doing so. 6.9 Renaming (moving) a file “Move” file1 by giving it the new name file4: baby:~: mv file1 file4 Look at file4 to see what it has in it: baby:~: cat file4 List using ls. Now the directory should show file2, file3, and file4. Obviously, the difference between a copy and a move is that copy makes an additional copy of the file while move “moves” the file’s contents to another file. It should be noted that there is not actually a move, but a renaming of the file. Since
Image of page 15
Image of page 16

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture