1.
Understanding Inodes
• [Link]: Create a file [Link] and display its inode number,
permissions, and timestamps.
Explain how inodes help in file system efficiency.
• Commands to Use:
• touch [Link]
• ls -i [Link]
• stat [Link]
2. Hard Link Creation
• [Link]:
• Create a hard link named hard_lab1.txt for [Link].
• Verify that both files share the same inode number.
• Edit one file and check if changes reflect in the other.
• Commands to Use:
• ln [Link] hard_lab1.txt
• ls -i [Link] hard_lab1.txt
• echo "Test line" >> [Link]
• cat hard_lab1.txt
Soft (Symbolic) Link Creation
• [Link]:
• Create a soft link named soft_lab1.txt for [Link].
• Check the inode numbers of both files.
• Delete [Link] and observe what happens to the soft link.
• Commands to Use:
• ln -s [Link] soft_lab1.txt
• ls -i [Link] soft_lab1.txt
• rm [Link]
• cat soft_lab1.txt # What happens?
Input-Output Redirection in Linux Shell
• [Link] a file [Link] with the content "Alice" and then append
"Bob" to it.
• echo "Alice" > [Link]
• echo "Bob" >> [Link]
• [Link] sort to alphabetically sort the contents of [Link].
• Inside the [Link] written it (Alice,Bob, xender, zen, yencee, cage,
orange, green, universal, black, round)
• sort < [Link]
• 6. find the list of files containing "zip" in `/usr/bin`
• ls /usr/bin | grep "zip“
• 7. Saves "No such file" error in [Link]
• touch [Link]
• ls /nonexistent 2> [Link]
Cron Job Setup
• [Link]:
• Schedule a cron job to backup the /home/user/documents directory
every Sunday at 11:30 PM using tar.
• List the cron jobs for the current user.
• Commands to Use:
• crontab -e
• # Add: 30 23 * * 0 tar -cvf ~/backup_docs.tar /home/user/documents
• crontab -l
grep for Text Analysis
• [Link]:
• Create a file [Link] with sample text (include lines with "error",
"Error", "ERROR").
• Use grep to find all case-insensitive occurrences of "error".
• Display line numbers where matches occur.
• Commands to Use:
• grep -ni "error" [Link]
Regular Expressions with grep
• [Link]:
• Create a file [Link] with mixed content (ID: 123, Name: Alice, 404 Not Found, start ing a line, this is the end,
name:fix, id:fox, if:fax, ).
• Use grep to extract all lines starting with a number.
• Find the line the word is start from “start” word.
• Find the line the word is end from “end” word.
• Find the marches of words which is starting letter is “f” and end letter is “x”
• Commands to Use:
• grep "^[0-9]" [Link]
• grep "^start" [Link]
• grep "end$" [Link]
• grep "f.x" [Link]
Archive Files with tar
• [Link]:
• Archive [Link], hard_lab1.txt, and soft_lab1.txt into lab_files.tar.
• Extract the archive into a new directory lab_backup.
• Commands to Use:
• tar -cvf lab_files.tar [Link] hard_lab1.txt soft_lab1.txt
• mkdir lab_backup
• tar -xvf lab_files.tar -C lab_backup
• [Link] the contents of lab_files.tar without extracting.
• tar -tvf lab_files.tar
Compress Files with gzip
• [Link]:
• Compress lab_files.tar using gzip.
• Decompress it and verify the contents.
• Commands to Use:
• gzip lab_files.tar
• gunzip lab_files.[Link]
Compress Files with bzip2
• [Link]:
• Compress [Link] using bzip2.
• Compare file sizes before/after compression.
• Decompress [Link].bz2 file
• Commands to Use:
• bzip2 [Link]
• ls -lh [Link].bz2
• bunzip2 [Link].bz2
Compare gzip vs. bzip2
• [Link]: a directory named project_files that contains several project documents.
Your task is to compress this directory into a .[Link] archive named
project_backup.[Link].
mkdir project_files
tar -czvf project_backup.[Link] project_files
Explanation:
-c creates a new archive
-z compresses using gzip
-v shows verbose output
-f specifies the archive file name
• 16. You have received a compressed archive named
project_backup.[Link]. Extract the contents of this archive to the
current directory.
• tar -xzvf project_backup.[Link]
• Explanation:
• -x extracts the archive
• -z decompresses a gzip archive
• -v shows progress
• -f specifies the file to extract
• 17. You are asked to compress a folder named logs using bzip2
compression and save it as logs_backup.tar.bz2.
• mkdir logs
• tar -cjvf logs_backup.tar.bz2 logs
• Explanation:
• -c creates an archive
• -j compresses using bzip2
• -v shows the process
• -f names the output file
• 18. a compressed archive named logs_backup.tar.bz2. Extract its
contents in the current directory.
• tar -xjvf logs_backup.tar.bz2
• Explanation:
• -x extracts the files
• -j decompresses a bzip2 archive
• -v provides progress output
• -f indicates the archive file