Here are the details on how to perform each activity for practicing basic Linux commands:
1. List all files and directories in the current directory:
Command: `ls`
Details: Open the terminal and navigate to the directory you want to list the files and directories. Then, enter the command "ls" and press enter. The output will display the names of all files and directories present in the current directory.
2. Change to the root directory:
Command: `cd /`
Details: Open the terminal and enter the command "cd /" to navigate to the root directory. The root directory is the top-level directory in the file system.
3. Display the present working directory:
Command: `pwd`
Details: Open the terminal and simply enter the command "pwd" to display the current working directory. The output will show the full path of the current directory.
4. Create a new directory called "test":
Command: `mkdir test`
Details: Open the terminal and enter the command "mkdir test". This will create a new directory named "test" in the current directory.
5. Navigate into the "test" directory:
Command: `cd test`
Details: Open the terminal and enter the command "cd test" to navigate into the "test" directory. This will change the current directory to "test".
6. Create a new empty file called "file1.txt" inside the "test" directory:
Command: `touch file1.txt`
Details: Open the terminal and enter the command "touch file1.txt" while inside the "test" directory. This will create a new empty file named "file1.txt".
7. Display the contents of "file1.txt" using a command:
Command: `cat file1.txt`
Details: Open the terminal and enter the command "cat file1.txt" while inside the "test" directory. This will display the contents of the "file1.txt" file, if any.
8. Rename "file1.txt" to "file2.txt":
Command: `mv file1.txt file2.txt`
Details: Open the terminal and enter the command "mv file1.txt file2.txt" while inside the "test" directory. This will rename the "file1.txt" file to "file2.txt".
9. Move "file2.txt" to the parent directory:
Command: `mv file2.txt ..`
Details: Open the terminal and enter the command "mv file2.txt .." while inside the "test" directory. This will move the "file2.txt" file to the parent directory.
10. Delete the "test" directory and all its contents recursively:
Command: `rm -r test`
Details: Open the terminal and enter the command "rm -r test" to delete the "test" directory and all its contents recursively. Be cautious while using this command, as it will permanently remove the directory and its contents.
11. List all files in the current directory, including hidden files:
Command: `ls -a`
Details: Open the terminal and enter the command "ls -a" to list all files in the current directory, including hidden files and directories. The output will display all files, including those with names starting with a dot (hidden files).
12. Change the permission of a file to read and write for the owner only:
Command: `chmod 600 filename`
Details: Open the terminal and enter the command "chmod 600 filename" to change the permission of the specified file, replacing "filename" with the actual file name. This command grants read and write permissions exclusively to the owner of the file.
13. List all processes running on the system:
Command: `ps -ef`
Details: Open the terminal and enter the command "ps -ef" to list all processes running on the system. The output will display details such as process IDs, user names, and the commands associated with each process.
14. Sort the output of a file containing a list of names alphabetically:
Command: `sort filename`
Details: Open the terminal and enter the command "sort filename" to sort the lines in the specified file in alphabetical order. Replace "filename" with the actual file name you want to sort.
15. Display the first 10 lines of a text file:
Command: `head -n 10 filename`
Details: Open the terminal and enter the command "head -n 10 filename", replacing "filename" with the actual file name. This command will display the first ten lines of the specified text file.
16. Count the number of lines in a file:
Command: `wc -l filename`
Details: Open the terminal and enter the command "wc -l filename" to count the number of lines in the specified file. Replace "filename" with the actual file name you want to count the lines of.
17. Search for a specific pattern in a file and print the matching lines:
Command: `grep "pattern" filename`
Details: Open the terminal and enter the command "grep "pattern" filename", replacing "pattern" with the specific pattern you want to search for and "filename" with the actual file name. This command will display all the lines in the file that contain the specified pattern.
18. Find and replace a word in a file using a command:
Command: `sed -i 's/old_word/new_word/g' filename`
Details: Open the terminal and enter the command "sed -i 's/old_word/new_word/g' filename", replacing "old_word" with the word you want to replace, "new_word" with the replacement word, and "filename" with the actual file name. This command will find all occurrences of the old word in the file and replace them with the new word.
19. Create a shell script that prints your name when executed:
Details: Open a text editor and create a new file with the extension ".sh". Add the following script to the file:
```
#!/bin/bash
echo "Your Name"
```
Save the file, and then open the terminal and run the script by entering the command "bash filename.sh", replacing "filename.sh" with the name of the script file you created.
20. Chain multiple commands together to achieve a specific task:
Details: This activity involves combining multiple commands using special characters such as "|" (pipe) or ";" (semicolon) to execute them sequentially or concurrently. For example, you can chain multiple commands to find all files modified in the last 24 hours and copy them to a new directory like this:
```
find /path/to/directory -type f -mtime 0 -exec cp {} /path/to/new_directory \;
```
Replace "/path/to/directory" with the actual directory path and "/path/to/new_directory" with the destination directory path.
Remember to practice these commands in a safe environment and take precautions when performing actions that may modify or delete files or directories.