Optional Exercise (Linux Terminal Commands)
Optional Exercise (Linux Terminal Commands)
Gaurav Ojha
b) Inside the "MyFiles" directory, create three subdirectories: "Documents", "Pictures", and
"Music".
mkdir ~/MyFiles
mkdir ~/MyFiles/Documents
mkdir ~/MyFiles/Pictures
mkdir ~/MyFiles/Music
2. Navigate through directories:
b) Print the absolute path of your current working directory using the "pwd" command.
cd ~/MyFiles/Documents
pwd
3. List directory contents:
b) List all the files (including hidden files) and directories in "MyFiles/Pictures" using
appropriate options with the "ls" command.
ls ~/MyFiles
ls -a ~/MyFiles/Pictures
4. Create and remove directories:
mkdir ~/MyFiles/Documents/Notes
rm -r ~/MyFiles/Music
5. Create and copy files:
a) Create a new empty file named "todo.txt" inside the "Documents" directory using the "touch"
command.
b) Copy the "todo.txt" file to the "Notes" directory.
touch ~/MyFiles/Documents/todo.txt
cp ~/MyFiles/Documents/todo.txt ~/MyFiles/Documents/Notes/todo.txt
6. View file contents:
a) View the first 5 lines of the "todo.txt" file using the "head" command.
b) View the last 10 lines of the "todo.txt" file using the "tail" command.
nano ~/MyFiles/Documents/todo.txt
head -n 5 ~/MyFiles/Documents/todo.txt
tail -n 10 ~/MyFiles/Documents/todo.txt
7. Append content to a file:
a) Add a new task to the "todo.txt" file using the "echo" command and redirect the output to
append
to the file.
a) Use the "grep" command to search for the word "Gatsby" in the "todo.txt" file.
a) Move the "todo.txt" file from the "Documents" directory to the "Notes" directory using the
"mv"
command.
b) Rename the "todo.txt" file in the "Notes" directory to "tasks.txt" using the "mv" command.
mv ~/MyFiles/Documents/todo.txt ~/MyFiles/Documents/Notes/todo.txt
mv ~/MyFiles/Documents/Notes/todo.txt ~/MyFiles/Documents/Notes/tasks.txt
10. Clean up:
a) Remove the "MyFiles" directory and all its contents using the appropriate command.
rm -r ~/MyFiles