Translate

Sunday, March 2, 2014

Navigating and Manipulating files on the Command Line

Hello, today we will be working with some file command and interactions that will help you understand how to work with moving data between files. First, navigate to your main hard drive, and from there use the mkdir command to create a folder. This folder will be used for the demonstration purposes in this tutorial to contain all the text files. You can also use the directory and files from the last tutorial, but it isn’t necessary unless you want to save some typing.
Now either create a new .txt file with the notepad command or use an existing one, but keep the name simple, like one.txt. Add the text:

a
“This is one line in the folder!”

Now use the command more to output the text inside of the file to the screen: more one.txt (if the data in the file is more than a single page can display, simply use the space bar to display more of the text in a file, all the way to the end.) The extra letter a will illustrate another command.
Now that we can have the console display text files directly, let’s utilize a command to create a new file from the one we have. Copy a file with the copy command, using : copy one.txt two.txt. The two.txt file will be created since it likely doesn’t exist. Use more two.txt to output the contents of two.txt and see the results.
Now we can combine the contents of the files in these two text file into into one with the type command! And we do this by using a redirect command “<”, which works with a commands, paths and multiple files to redirect input and output between the two operators. In this case, the data inside the two text files will be input into the newer .txt file to create a new file.
Type the following: type one.txt two.txt > three.txt. This will write the output of both files into a new file, three.txt. Now use type one.txt two.txt three.txt | more . ‘|’ is a key found under your backspace key with shift, and represents the “pipe” command. This command will combine the output from the type command and send it to the more command to output the contents of all the files at once.

Keywords:
More: This command will output the contents to the screen in pages that can be parsed through with the space bar.
Copy: his will copy the contents of one file into a new file, overwriting the file if it exist upon confirmation, or creating a new file if the name isn’t present.
Type: Equivalent of ‘cat’ in Unix, this command enables files to be concatenated into new files
| : “Pipes” or redirects the output from a command on right side of the operator to another command on the left side fo the operator.
< : writes the output from the left side to the right side of the command.
> : Writes

>> : Use to append, or attach the contents of the right side to the left side of the operator to the right side.

No comments:

Post a Comment