# Command Line Basics ## Hello Terminal! ```{exercise} :label: hello_terminal 1. Print your name to the terminal. 2. Clear your terminal after completing #1. ``` ````{solution} hello_terminal :class: dropdown ```bash echo Gökçe clear ``` ```` ## Navigating the Command Line ```{exercise} :label: navigating_the_cmd_line 1. Set your working directory to the root directory. 2. Set your working directory to your home directory using three different commands. 3. Find a folder on your computer using your file and folder browser, and then set your working directory to that folder using the terminal. 4. List all of the files and folders in the directory you navigated to in #3. ``` ````{solution} hello_terminal :class: dropdown ```bash cd / # do not confuse `/` with `/root`. The latter is the home folder of the administrator user `root` cd cd ~ cd $HOME # 3. note that some file/folder browsers can *Open Terminal Here*, e.g., Thunar cd /usr ls -a # -a also includes hidden files and folders that start with . ``` ```` ## Creation and Inspection ```{exercise} :label: creation_and_inspection 1. Create a new directory called `workbench` in your home directory. 2. Without changing directories create a file called `readme.txt` inside of `workbench`. 3. Append the numbers 1, 2, and 3 to `readme.txt` so that each number appears on it's own line. 4. Print `readme.txt` to the command line. 5. 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. 6. Find out how many characters are in `list.txt` without opening the file or printing it to the command line. ``` ````{solution} creation_and_inspection :class: dropdown ```bash cd mkdir workbench touch workbench/readme.txt echo -e '1\n2\n3' >> workbench/readme.txt # in bash, echo needs -n to account for backslash escapes cat workbench/readme.txt ls > workbench/list.txt wc --chars workbench/list.txt ``` ```` ## Migration and Destruction ```{exercise} :label: migration_and_destruction 1. Create a file called `message.txt` in your home directory and move it into another directory. 2. Copy the `message.txt` you just moved into your home directory. 3. Delete both copies of `message.txt`. Try to do this without using `rm`. ``` ````{solution} migration_and_destruction :class: dropdown ```bash cd # change directory again, the directory is not preserved between %%sh cells # compared to the bash-kernel echo secret > message.txt mv message.txt workbench cp workbench/message.txt ~ mkdir trash mv message.txt workbench/message.txt trash # or a trash dir may already be available # mv message.txt .local/share/Trash # or if `trash-cli` is installed # trash message.txt rm -r trash workbench ``` For further solutions to 3 see [this posting at Stack Exchange](https://unix.stackexchange.com/q/342598/411786) ````