less, more, head, tail, cat and nano
Unix basics
Commands
Text
Reading and writing text files
Open and read files : less or more
Softwares to open text files as read-only.
- Use
less --helporman lessto see a manual on how to uselessandmore --helporman moreto see how to usemore less file1- Will open file1 to read. If you want to look for a word, type
/then type the word.
- Will open file1 to read. If you want to look for a word, type
less file1 file2 file3- Will open the three files to read. You can move between the files by typing
:followed bypto look at the previous file ornto look at the next one.
- Will open the three files to read. You can move between the files by typing
less can read fastq.gz files (compressed files)
Print text to the screen : cat
Prints file to the screen
cat file1: will print the content of file1 to the screen. If the file is a binary file (.bam), or if it is compressed (.zip, .tar, .gz), the printed text will be all gibberishcat file1 file2: will print the content of file1 followed by the content of file 2cat file1 > file2; cat file3 >> file2: is the same ascat file1 file3 > file2.
In the case of compressed text files, like fastq.gz, we can read it with zcat
View beginning or end of a file : head and tail
Prints the first (head) or last (tail) 10 lines of a file to the screen. If you have a big file and you just want to see if it looks fine or what it contains, use this
head file1: will print the first 10 lines of file1head -n 20 file1: the option-nallows you to specify the number of lines you want to be printed
The behavior of tail is similar to head.
Edit text file : nano
Software to edit text in the server. Used alone will open an empty file. When you try to close the file (Ctrl + x) will ask if you want to save it and ask for a name for the path where to save it.
nano file1- Will open file1 for edition. If file1 does not exist, will create it.
nano *- Will open all text files in the working directory for edition in alphabetic order. Once you close one, the next one is opened.