Lecture 1
Linux Shell
Shell: Interface to the OS
gets OS to do stuff - run programs, manage files
graphical shell (Windows, Mac OS, Ubuntu)
command line (type commands - terminal)
In this course, we use Bash.
# type this to ensure you are in bash
$ echo $0
>> -bashFiles, Input/Output
$ cat
$ catDisplays contents of root directory
First slash denotes root directory (top of directory hierarchy)
$ cat /path/to/fileWhat if I just run :
Copies output
Is this useful?
Can capture output and put in a file -
cat > output.txt
# Example
$ cat
hello
>> hello
hi
>> hiStopping cat from running: Ctrl+D
Text in Linux
In linux, every line in valid txt file must end with a newline character.
Marmoset checks that last line ends in
When printing output, should end in
Terminating program
For infinite loop or crash, to terminate program:
Ctrl+C
$ ls
$ lsDisplays file in current dir
$ ls -a
$ ls -aDisplays hidden files + files in current dir
$ pwd
$ pwdprints the current dir
stands for present working directory
Redirecting Output
output redirection symbol:
>what would be printed to output, send to file
# Example:
$ cat args > fileRedirecting Input
input redirection symbol:
<
# Example:
$ cat < inputfilereads intput from file instead of keyboard
in the case of
$ cat, the output is the same
Difference in Behaviour
$ cat /file -> pass "file" as an argument to cat which opens the file and prints it
$ cat < file -> the shell opens the file and passes its content in place of keyboard input
$ wc
$ wcline count, word count, character count
Asterisk in Linux (*)
*.txt is a globbing pattern
asterisk means match anything
when shell sees globbing pattern, the shell expands globbing pattern to match non-hidden files
More globbing patterns on reference sheet
Many commands can accept arguments or input with the exception of
$ echo
# Example:
## Copies input.txt into output.txt
$ cat < input.txt > output.txt# Example:
## Prints output preceeded by line numbers
$ cat -n < input.txt > output.txtLast updated
Was this helpful?