Week1 My Unix
Week1 My Unix
● This will display the names of the subdirectories dir1, dir2, and dir3 inside lab1.
a. Create three files named file1.txt, file2.txt, and file3.txt inside dir1
touch dir1/file1.txt dir1/file2.txt dir1/file3.txt
● This also allows you to view the contents of file1_copy.txt, but less is more
interactive than more.
c. Use the sort command to sort the contents of file1.txt and save the sorted output
to sorted_file1.txt
bash
Copy code
sort dir1/file1.txt > dir1/sorted_file1.txt
● This removes duplicate lines from sorted_file1.txt and saves the result in
unique_sorted_file1.txt.
a. Use the cut command to extract the first column from sorted_file1.txt and save it
to column1.txt
bash
Copy code
cut -d ' ' -f 1 dir1/sorted_file1.txt > dir1/column1.txt
● This extracts the first field (column) from sorted_file1.txt assuming space (' ') as
the delimiter and saves it to column1.txt.
● This merges the contents of column1.txt and sorted_file1.txt side by side and
saves the result in pasted_file.txt.
c. Use the split command to split file1.txt into pieces of 5 lines each
bash
Copy code
split -l 5 dir1/file1.txt dir1/file1_part_
● This splits file1.txt into smaller files, each containing 5 lines, with names like
file1_part_aa, file1_part_ab, etc.
6. User and System Information
● This displays detailed information about the system including the kernel name, version,
and architecture.
● This provides detailed information about the specified user (e.g., <username> can be
replaced with a specific username).
7. Security by File Permissions
b. Change its permissions to read-only for the owner and no permissions for others
bash
Copy code
chmod 400 permissions_test.txt
● This sets the file permissions so that only the owner can read the file, and others have
no permissions.
● This displays the file's permissions in the long format (e.g., -r--------).
● This changes the ownership of the file to <newuser>. You need sudo privileges to
execute this command.