This page should serve as a reference for the many "things Linux" we use in this course. It is by no means complete – Linux is **huge** – but offers introductions to many important topics.
...
- Macs and Linux have a Terminal program built-in
- Windows options:
- Windows 10+
- Command Prompt and PowerShell programs have ssh and scp (may require latest Windows updates)
- Start menu → Search for Command
- Putty – http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- simple Terminal and file copy programs
- download either the Putty installer or just putty.exe (Terminal) and pscp.exe (secure copy client)
- Windows Subsystem for Linux – Windows 10 Professional includes a Ubuntu-like bash shells
- See https://docs.microsoft.com/en-us/windows/wsl/install-win10
- We recommend the Ubuntu Linux distribution, but any Linux distribution will have an SSH client
- Command Prompt and PowerShell programs have ssh and scp (may require latest Windows updates)
- Windows 10+
Use ssh (secure shell) to login to a remote computers.
Code Block | ||||
---|---|---|---|---|
| ||||
# General form: ssh <user_name>@<full_host_name> # For example ssh abattenh@ls6.tacc.utexas.edu |
...
- In the Terminal, type in the command name then the --help long option (e.g. ls --help)
- Works for most Linux commands; 3rd party tools may use -h or -? or even /? instead
- May produce a lot of output, so you may need to scroll up quite a bit, or pipe the output to a pager
- e.g. ls --help | more
- a space advances the output by one screen/"page", and typing Ctrl-C will exit more
- e.g. ls --help | more
- Use the built-in manual system (e.g. type man ls)
- This system uses the less pager described below
- For now, just know that a space advances the output by one screen/"page", and typing q will exit the display.
- Ask the Google, e.g. search for ls man page
- Can be easier to read
About command line input
You know the command line is ready for input when you see the command line prompt. The shell executes command line input when it sees a linefeed character (\n, also called a newline), which happens when you press Enter after entering the command.
Expand | ||
---|---|---|
| ||
Note: The Unix linefeed (\n) line delimiter is different from Windows, where the default line ending is carriage-return + linefeed (\r\n), and some Mac text editors that just use a carriage return (\r). |
More than one command can be entered on a single line – just separate the commands with a semi-colon ( ; ).
Code Block | ||||
---|---|---|---|---|
| ||||
cd; ls -lh |
...
Literal characters and metacharacters
In the bash shell, and in most tools and programming environment, there are two kinds of input:
- literal characters, that just represent (and print as) themselves
- e.g. alphanumeric characters A-Z, a-z, 0-9
- metacharacters- these are special characters that are associated with an operation in the environment
- e.g. the pound sign ( # ) comment character that tells the shell to ignore everything after the #
- e.g. the pound sign ( # ) comment character that tells the shell to ignore everything after the #
There are many metacharacters in bash: # \ $ | ~ [ ] to name a few.
Pay attention to the different metacharacters and their usages – which can depend on the context where they're used.
About command line input
You know the command line is ready for input when you see the command line prompt. The shell executes command line input when it sees a linefeed character (\n, also called a newline), which happens when you press Enter after entering the command.
Expand | ||
---|---|---|
| ||
Note: The Unix linefeed (\n) line delimiter is different from Windows, where the default line ending is carriage-return + linefeed (\r\n), and some Mac text editors that just use a carriage return (\r). |
More than one command can be entered on a single line – just separate the commands with a semi-colon ( ; ).
Code Block | ||||||
---|---|---|---|---|---|---|
| ls6:~$ ls ~
| |||||
cd; ls -lh |
A single command can also be split across multiple lines by adding a backslash ( \ ) at the end of the line you want to continue, before pressing Enter.
Code Block | ||||
---|---|---|---|---|
| ||||
ls6:~$ ls ~/.bashrc \
> ~/.profile |
Notice that the shell indicates that it is not done with command-line input by displaying a greater than sign ( > ). You just enter more text then Enter when done.
Tip | ||
---|---|---|
| ||
At any time during command input, whether on the 1st command line prompt or at a > continuation, you can press Ctrl-c (Control key and the c key at the same time) to get back to the command prompt. |
Literal characters and metacharacters
In the bash shell, and in most tools and programming environment, there are two kinds of input:
...
- e.g. alphanumeric characters A-Z, a-z, 0-9
...
- e.g. the pound sign ( # ) comment character that tells the shell to ignore everything after the #
There are many metacharacters in bash: # \ $ | ~ [ ] to name a few.
...
Text lines and the Terminal
Sometimes a line of text is longer than the width of your Terminal. In this case the text is wrapped. It can appear that the output is multiple lines, but it is not. We can see that by looking at lines of the mobydick.txt file, that has some very long lines:
Code Block | ||
---|---|---|
| ||
tail -1 mobydick.txt
cat -n mobydick.txt | more |
Note that most Terminals let you increase/decrease the width/height of the Terminal window. But there will always be single lines too long for your Terminal width and too many lines of text for its height.
So how long is a line? And how many lines are there in a file? The wc (word count) command can tell us this.
- wc -l reports the number of lines in its input
- wc -c reports the number of characters in its input (including invisible linefeed characters)
- wc -w reports the number of words in its input (groups of space-separated text characters)
Examples:
Code Block | ||
---|---|---|
| ||
wc -l mobydick.txt # Reports the number of lines in the mobydick.txt file
cat mobydick.txt | wc -l # Reports the number of lines of its input
tail -1 mobydick.txt | wc -c # Reports the number of characters of the last mobydick.txt line |
When you give wc -l multiple files, it reports the line count of each, then a total.
Command input errors
You don't always type in commands, options and arguments correctly – you can misspell a command name, forget to type a space, specify an unsupported option or a non-existent file, or make all kinds of other mistakes.
...