Skip to content
Felipe Simionato Salles edited this page Jan 5, 2025 · 1 revision

This is basic commands lines in BASH for bioinformatics

Welcome to the Linux-and-Bioinformatic wiki!

My name is Felipe Simionato Salles

Lets start for begginer.

Interface, logical and language

GNU have a interface with

green is the terminal ~ is the way to your user terminal

Standard input (stdin), Standard output (stdout), Standard error (stderr)

  1. stdin is represented by number 0, where data comes from to enter the program

  2. stdout is represented by number 1, where data goes when it gets out of the program

  3. stderr is represented by number 2, where program errors (or warnings or diagnostic messages) go to when issued

List of commands accept only stdin :

  • less
  • more
  • tail
  • head

List of commands accept only stdout :

  • rev
  • colrm

List of commands use to redirect the stdin :

List of commands use to redirect the stdout :

List of commands dont accept EITHER:

  • mkdir
  • cd
  • wget

Special caracters to redirect and concatenate the stdin, stdout, stderr

> redirect stdout to the file named after the sign

can create new files OR OVERWRITE AN EXIST FILE, so be carefull

$ file > other_file

2> redirect STDERR to the file / only the erro will and redirect to the file / can create new files OR OVERWRITE AN EXIST FILE >> redirect, appending stdout to a file. 2>> redirect, appending stderr to a file.

redirect JUST A STARDAR ERROR (stderr) AND appending to a existing file

$ file 2>> appending_staerr

< redirect stdin from a file to a programm

$ script_of_programm < file

<< redirect stdin as a here-document,

<<< redirect stdin as a here-string to a program

&&

&

It's possible to merge thoose caracters:
  • Merge stdout and stderr and send them to the same file

send the two streams to the same file

$ command_line > file 2>&1
### OR
$ command_line &> file
  • Appending, without overwrite, the stdout and stderr in the previous exist file
$ command_line >> file 2>&1
### OR
command_line &>> file

command && command =

command & command = . = currently directory

.. = directory above currently directory

MetaCharacters 🧭

. is considerer any character. Represent a caracther with dot.

^ and $ anchor the beggin and the end of line, respectavely

  1. line couting how many lines start with ATG
  1. substitute the end of the sequencies fasta with TAA for a blank space
$ grep -c '^ATG' file.fasta 
$ sed 's/TAA$//' file.fasta 

[ ] enclose a character list, so its something OR other thing. Can be used as a range also

  1. list-show just file.a, file.b, file.c, file.d
  1. print numbers 1 to 10
$ ls file.[abcd]
$ echo [1..10]

[^ ] is the same as [ ] but negation the content among the brackets

show list files with don't started X OR Y OR Z

$ ls [^XYZ]*

* quantifier zero or more occurrences

\ remove the metacharacter "special power" and belong a normal characher, therefore is the literal value of the character

in some programms make the normal character change the mean and gives new power for them

| concatenate 2 or more commands in one line (its a pipe), redirect stdout of one program to stdin of the next program.

STDERR does not get in the pipe, by default, so use |& to have the STDERR go along with STDOUT

$ command1 | <command2> | <command3>
  • = match the preceding element one or more times ? = match the preceding element zero or one time ( ) = group some parts of the regex, and save the match in a special variable