Chapter 3: Command Line Basics
3.1.2 Exercises
-
Print your name to the terminal.
$ echo SuperMoudy
-
Clear your terminal after completing #1.
$ clear
3.2.2 Exercises
-
Set your working directory to the root directory.
$ cd /
-
Set your working directory to your home directory using three different commands.
- Method 1:
$ cd
- Method 2:
$ cd ~
- Method 3: Absolute Path
$ cd /path/to/your/home/directory
- Method 1:
-
Find a folder on your computer using your file and folder browser, and then set your working directory to that folder using the terminal.
$ cd path/to/the/folder
-
List all of the files and folders in the directory you navigated to in #3.
$ ls folder
3.3.2 Exercises
-
Create a new directory called workbench in your home directory.
$ cd $ mkdir workbench
-
Without changing directories create a file called readme.txt inside of workbench.
$ touch workbench/readme.txt
-
Append the numbers 1, 2, and 3 to readme.txt so that each number appears on it’s own line.
$ echo 1 > workbench/readme.txt $ echo 2 >> workbench/readme.txt $ echo 3 >> workbench/readme.txt
-
Print readme.txt to the command line.
$ cat workbench/readme.txt
-
Use output redirection to create a new file in the workbench directory called list.txt which lists the files and folders in your home directory.
$ ls > workbench/list.txt
-
Find out how many characters are in list.txt without opening the file or printing it to the command line.
$ wc -c workbench/list.txt
3.4.2 Exercises
-
Create a file called message.txt in your home directory and move it into another directory.
$ cd $ touch message.txt $ mv message.txt path/to/another/directory
-
Copy the message.txt you just moved into your home directory.
$ cd $ cp path/to/another/directory/message.txt message.txt
-
Delete both copies of message.txt. Try to do this without using rm.
We firstly want to find an alternative to rm:
$ apropos remove
Found a command called unlink
$ unlink message.txt path/to/another/directory/message.txt