Skip to the content.

Shell, etc.

-

What we’ll cover

Your Shell Terminal

Useful commands for navigating and manipulating your file system

-

Useful Commands

**w** - Who's logged on?

**pwd** - "Print Working Directory" prints out your current location (known as your current working directory or 'cwd')

**ls** - lists contents of the cwd.

-

. and ..

Use .. to view the directory above the current working directory. You can use multiple instances of .. to go up multiple levels, i.e. ../../

	$ ls ../

Use . to indicate the current directory.

	$ ls .

-

*

Use * as a wild card that can be placed at either end of a string, ie:

	$ ls *.txt
	$ ls *.*
	$ ls ../mammals/cat.*

-

Useful Commands (contin.)

**cd** - change directory. This is how you move around the file system. You can specify the destination as an absolute or relative path.

**echo** - prints text to the terminal

**cat** - concatenates zero or more files. Often used to print the contents of a file to the terminal. Often misused

-

Useful Commands (contin.)

**less/more** - display contents of a file one page at a time

**grep** - search for the specified text or pattern

**touch** - create or open a file and save it without changing its contents.

**mkdir** - make a directory

**rmdir** - remove directory

**rm** - remove file or directory

**cp** - copy file or directory

(use **-r** to act recursively: ``` $ cp -r ``` or ``` $ rm -r ```

**mv** - move file or directory

-

Other commands worth knowing

**clear** - clear the terminal's display

**[control]-c** - get a new terminal prompt

**[control]-l** - clear screen

**head** - display the first lines of a file

**tail** - display the last lines of a file

-

Other commands worth knowing (continued)

**more grep:**

``grep "^foo.#bar$" file.txt | grep -v "baz"`` (same search as grep, but filter out the lines containing "baz")

if you literally want to search for the string, and not the regex, use fgrep (or grep -F) ``fgrep "foobar" file.txt``

-

Other commands worth knowing (continued)

If a command has an output to the terminal, you can always send the out put of the command to a destination, such as a file. (The output of a cat command, for example.)

$ cat file1.txt file2.txt > file3.txt
$ echo "This is a line of content" > testfile1.txt

- -