The command line, also called the shell, is used via a terminal window. Windows users need to install additional software as Windows is not based on UNIX or LINUX. Mac and Linux users have terminal programs already installed.
Command line means exactly that: You need to enter commands via a command line, there is no graohical user interface or a menu that you can use. There is a learning curve, but as soon as you have learned a minimum set of commands and options, you can work much faster than with any other program.
By entering man <command>, the manual of a command will be displayed; e.g., if you enter man grep, you will get the manual for grep (if you need to get out of the manual, enter “q” to leave it; no need to close the complete terminal window).
UNIX commands usually have the format command options file, for example sort -r file.txt. Additional commands with examples:
- pwd: Print Working Directory, tells you were you are in the directory of the file system. After starting a terminal, you will usually get into /Users/<BENUTZERNAME>
- cd: Wth cd for change directory, you can navigate through the directory tree.
- cd Desktop brings you to the subdirectory Desktop
- cd .. gets you to the next level up in the directory, with cd ../.. you can get two levels up and so on.
- grep: Search for patterns in files.
- grep -i ‘bowie’ enwiki-latest-pages-articles.xml – Search for the term ‘bowie’ in a Wikipedia dump, the option -i makes the search non case sensitive so that also parts are found where the term is written in capital letters.
- grep -iv ‘bowie’ enwiki-latest-pages-articles.xml – The option v prevents lines from being printed that do not contain the term ‘bowie’
- sort: Sorts a list
- sort -r: sorts a list in reverse order
- uniq: removes all duplicates of elements in a list
A huge example of the command line is the use of pipes. commands can be combined in a line so that the output of one command can be used as the input of another command:
sort keywords.txt | uniq -c | sort -r | less
The symbol | (alt-7 on a Mac) is the pipe symbol. In this example, the file keywords.txt is first sorted, then deduplicated while counting the unique elements, and the results are sorted by reverse order so that we see the terms with the highest frequency first. Using less the results are not printed completely but pagy by page. If you want to redirect the output into a file instead of the terminal window, this could be done by entering:
sort keywords.txt | uniq -c | sort -r > keywords.uniq.txt
A last recommendation: You can save lots of time if you get used to not writing everything but auto-completing by using the tab key on the keyboard. Example: I am in my home directory (/Users/tomalby) and need to go into the subdirectory Desktop; I just enter cd De and enter the tab key so that the command is auto-completed to cd Desktop.