![]() First clear the screen, then type % grep science science.txtĪs you can see, grep has printed out each line containg the word science… or has it? Try typing % grep Science science.txt It searches files for specified words or patterns. Grep is one of many standard Unix utilities. Type to search for the next occurrence of the word. The more command finds and highlights the keyword. don’t press to quit), type a forward slash followed by the word to search /science For example, to search through science.txt for the word ‘science’, type % more science.txt Using more, you can search through a text file for a keyword (pattern). How can you view the last 15 lines of the file? Searching the Contents of a File Simple Searching Using more Clear the screen and type % tail science.txt The tail command writes the last ten lines of a file to the screen. What difference did the -5 make to the head command? tail The head command writes the first ten lines of a file to the screen. The more command is an example of a pager, a program that “pages” through a text file. Press the if you want to see another page. The command more prints the contents of a file onto the screen a page at a time. THe > sign is a redirection, which we will discuss later. Cat can also join two text files, hence its name. ![]() The cat command can show a text file’s contents % cat science.txtīe sure to use the correct path to the file. Displaying the Contents of a File on the Screen cat (concatenate) The -i option (inquire) also works for rm % rm -i myfileĬreate a directory called tempstuff using mkdir, then remove it using the rmdir command. You can request confirmation with % rm -if directory The above command will remove the directory without confirming anything! Be extremely careful with it! To remove a non-empty directory use rm -rf directory You will not be able to since Unix will not let you remove a non-empty directory. You can use the rmdir command to remove a directory, but only if it is empty. Inside your unixstuff directory, type % cp science.txt tempfile.txt As an example, we are going to create a copy of the science.txt file then delete it. To delete (remove) a file, use the rm command. Removing Files and Directories rm (remove), rmdir (remove directory) Type ls and ls backups to see if it has worked. Then, inside the unixstuff directory, type % mv science.bak backups/. First, change directories to your unixstuff directory (can you remember how?). We are now going to move the file science.bak to your backup directory. It can also be used to rename a file, by moving the file to the same directory, but giving it a different name. This has the effect of moving rather than copying the file, so you end up with only one file rather than two. To move a file from one place to another, use the mv command. Mv file1 file2 moves (or renames) file1 to file2. newnameĬreate a backup of your science.txt file by copying it to a file called science.bak. The above command means copy the file science.txt from the parent directory to the current directory, keeping the name the same. Remember, in UNIX, the dot means the current directory. Note: Don’t forget the dot (.) at the end. One gets such wholesale returns of conjecture out of such a trifling investment of fact. There is something fascinating about science. And by the same token any person can see that seven hundred and forty-two years from now the Lower Mississippi will be only a mile and three-quarters long, and Cairo and New Orleans will have joined their streets together, and be plodding comfortably along under a single mayor and a mutual board of aldermen. Therefore, any calm person, who is not blind or idiotic, can see that in the Old Oolitic Silurian Period, just a million years ago next November, the Lower Mississippi River was upwards of one million three hundred thousand miles long, and stuck out over the Gulf of Mexico like a fishing-rod. That is an average of a trifle over one mile and a third per year. In the space of one hundred and seventy-six years the Lower Mississippi has shortened itself two hundred and forty-two miles. Use whatever method you know to place this file into your home directory. ![]() Click the down-arrow icon to download the file. ![]() Cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2.įor our example we will create a file science.txt.
0 Comments
Leave a Reply. |