Before beginning, a quick review of some fundamental Linux aspects is useful.
Remember these commands:
- man [command]: it shows the guide/help for a specific command. Really useful if you forgot something.
- ls: it shows the content of a directory.
- mv [source] [destination]: If destination is a directory, moves the source (file or directory) to the destination directory. If source and destination are the same file, it renames the file.
- mkdir [name_dir]: it creates a directory.
- rm: it deletes a file.
- rmdir: it deletes a directory if it's empty.
- ps: it shows the processes being executed.
- find [name]: it searches for a file or a directory.
- sort [source]: it orders a source list (coming for example from a file) according to a criterion.
- grep [search] [source]: it shows on the monitor only the rows of the source containing the search word.
- head/tail [source]: the two commands show respectively the first 10 or last 10 rows of a file.
- chgrp / chown / chmod: the commands change the file attributes relative to group, owner and permissions respectively.
In the Linux shell, as in almost every textual interfaces, the commands have a standard source and destination. For example the "sort" command visualizes the result of a sorting in the screen.
Anyway, it can happen that you want to send the command output in another direction, for example to a file to save it. In this case you can use the redirection operators:
- Characters < and > (major and minor): they're used to take or send data from/to a file.
- Character | (pipe): used for chaining two or more commands; that is, it takes the output of one command and uses it as input for the next one.
Here there are two examples. If you want to save the result of the sort command to a file, you can write:
sort my_file.txt > my_file_sorted.txt
while if you want to sort the file my_file.txt
and then visualize only the rows containing the word "er", you can write:
grep er my_file.txt | sort