3. File manipulation
Exercise: Reading text files
Using the commands you just learned, explore the .gff3 file in the Home directory.
- Is the file a text file?
Solution
Yes. You can useless, cat, head, or tail and get human-readable info. Note that this doesn’t have anything to do with its file extension.
- How many lines does the file have?
Solution
There are 67 lines in this file.
- Can you read the content of the file using less?
Exercise: Editing text files
Using the commands you just learned, create a file called helloworld.txt and edit it using nano.
- Write “Hello world” into the file. Save the file and exit nano.
- Create a subdirectory called “test”; move the helloworld.txt file into test.
- Create a copy of the helloworld.txt file called helloworld2.txt
Solution
- First, use the
nanocommand to open a file calledhelloworld.txt
Inside the nano editor, write “Hello world”, then use the ^O option to write the changes and ^X to exit.
- Create a subdirectory called “test”; move the helloworld.txt file into test.
Use the command mkdir to create this new directory. Then, use mv to move helloworld.txt into this directory.
- Create a copy of the
helloworld.txtfile calledhelloworld2.txt.
Change the working directory using cd, then use the cp command to create the copy.