23521111_LAB1
23521111_LAB1
OS
LAB 1
CHECKLIST
1. Homework
1 2 3 4 5 6
Explanation
Your code
Results and discussions
Mark:
*Notice: Export PDF file, name format:
<MSSV>_LAB1.pdf
1
2. Lab 1
Answer:
The command sudo apt-get install installs the lshw (List Hardware) tool, which is used to
retrieve detailed information about the hardware components of your Ubuntu system.
- sudo: Runs the command with superuser (root) privileges, which is necessary to install
software on Ubuntu.
- apt-get: The package management tool for Debian-based distributions like Ubuntu,
used to install, update, and remove software packages.
- install: The subcommand specifying that you want to install a package.
- lshw: The name of the package to install. Once installed, the lshw command can be
used to display detailed information about hardware components like CPU, memory,
disks, and network interfaces.
2
*The sudo lshw command provides a detailed list of hardware information on your
system, including CPU, memory, motherboard, hard drives, network cards, and
peripheral devices. Specifically, this command displays the following:
CPU: Detailed information about the processor, including name, clock speed,
cores, and threads.
RAM: Memory capacity and type.
Motherboard: Information about the motherboard name and manufacturer.
Storage and Partitions: Storage capacity, disk type, and partition details.
Network Devices: Information about network cards, Ethernet, or Wi-Fi
connections.
Graphics Card: Details about the graphics card, if available.
Peripheral Devices: Lists devices connected via USB or other interfaces.
3
The command df -h is used to display information about disk space usage on all mounted
file systems in a human-readable format.
- df: stands for "disk filesystem" and is used to check the amount of disk space used and
available on file systems.
- -h: stands for "human-readable," which means the output will be displayed in a format
that's easier to read, such as MB, GB, or TB instead of blocks.
The command typically outputs columns such as:
Filesystem: The name of each file system or disk partition.
Size: The total size of each file system.
Used: The amount of space that has been used.
Avail: The amount of free space available.
Use%: The percentage of disk space used.
Mounted on: The directory where the file system is mounted.
4
The command cat /etc/*release is used to display information about the Linux distribution
version. This command works by reading files in the /etc directory that contain the word
"release" in their names.
- cat: This command outputs the contents of files.
- */etc/release: This uses a wildcard (*) to match any file in the /etc directory with
"release" in its name, such as os-release or lsb-release.
The output usually includes information such as:
NAME: The name of the distribution, e.g., "Ubuntu."
VERSION: The version number of the OS.
ID: The identifier of the distribution, e.g., "ubuntu."
PRETTY_NAME: A user-friendly name and version, like "Ubuntu 20.04 LTS."
VERSION_CODENAME: The codename of the release, such as "focal."
5
Answer:
**Command ls : The ls command in Linux is used to list directory contents. It’s
one of the most frequently used commands to view files, directories, and other
information about them. This command, when run without options, lists the files and
directories in the current directory.
Usage : ls [options] [folder]
Common options :
- ls -l: long listing format
- ls -a: show hidden files
- ls -lh: show file sizes in a human-readable format, such as KB, MB, GB
- ls -R: lists all files and directories recursively, including subdirectories and their
contents.
- ls -lt: lists files and directories sorted by modification time, with the most recently
modified items first
- ls -lS: lists files sorted by size, with the largest files first
- ls -i: show inode numbers for each file, which is a unique identifier for each file or
directory on the disk.
- ls -d: displays only directories without showing their contents
**Command cd : The cd command in Linux stands for "change directory" and is used to
navigate between directories in the filesystem.
Usage: cd [directory_path]
Examples:
+ Change to a Specific Directory: cd /home/user/Documents
6
+ Navigate to the Home Directory: cd ~
+ Go Up One Level : cd ..
+ Return to the Previous Directory: cd –
+ Navigate to the Root Directory: cd /
**Command pwd: The pwd command in Linux stands for "print working directory." It is
used to display the current directory you are in within the file system. It outputs the full
path of the current working directory. This is particularly useful for confirming your
location in the directory structure, especially when navigating through multiple
directories.
Usage : pwd
When you run the pwd command, it outputs the full path of the current working
directory. This is particularly useful for confirming your location in the directory
structure, especially when navigating through multiple directories.
**Command touch: The touch command in Linux is primarily used to create empty files
or update the access and modification timestamps of existing files.
touch [file_name]
file_name: The name of the file you want to create or update.
7
-nano: The nano command in Linux is a text editor that operates within the
terminal. It is user-friendly and designed for simplicity, making it a popular choice
for editing text files directly from the command line.
nano [file_name]
file_name: The name of the file you want to edit. If the file does not exist, nano
will create a new file with that name.
Basic Navigation and Commands within nano:
Move the Cursor:
o Use the arrow keys to move the cursor around the document.
Save Changes:
o Press Ctrl + O (the letter O) to write (save) changes.
o After pressing Ctrl + O, you'll be prompted to confirm the filename. Press
Enter to save.
Exit nano:
o Press Ctrl + X to exit the editor. If you have unsaved changes, it will
prompt you to save them.
Cut Text:
8
o Use Ctrl + K to cut the current line. You can paste it using Ctrl + U.
Search for Text:
o Press Ctrl + W to search for a specific text string within the file.
o
**Command mkdir: The mkdir command in Linux is used to create new directories
(folders) in the file system.
mkdir [directory_name]
directory_name: The name of the directory you want to create.
-rm: The rm command in Linux is used to remove (delete) files and directories
from the file system. It's a powerful command that should be used with
caution, as deleted files are typically not recoverable.
rm [options] [file_name]
file_name: The name of the file you want to delete.
9
Common Options:
+ rm -i myfile.txt : interactive mode
+ rm -f myfile.txt : force deletion
+ rm -r myfolder : remove directories and their contents recursively
+ rm -v myfile.txt : verbose mode
Caution:
The rm command permanently deletes files and directories, which means they are
not sent to a trash or recycle bin. Once deleted, they cannot be easily recovered, so
it’s important to double-check before running this command, especially with the -r
and -f options.
**Comand cp: The cp command in Linux is used to copy files and directories from one
location to another. It can copy a single file, multiple files, or entire directories.
cp [options] source destination
+ source: The file or directory you want to copy.
+ destination: The location where you want to copy the source. This can be a
file name or a directory.
Common Options:
-i: Interactive mode.
-f: Force overwrite.
-v: Verbose mode.
-u: Copy only when the source file is newer than the destination file or when the
destination file does not exist.
Caution:
When copying files, if a file with the same name exists in the destination, it will be
overwritten unless the -i option is used to prompt for confirmation. Always
double-check your commands, especially when using options like -f.
10
**Command mv: The mv command in Linux is used to move or rename files and
directories. It can either move files from one location to another or rename them within
the same directory.
Usage: mv [options] source destination
- source: The file or directory you want to move or rename.
- destination: The new location or new name for the file or directory.
Common Options:
-i: Interactive mode.
-f: Force move.
-v: Verbose mode.
Caution:
When moving files, if a file with the same name exists in the destination, it will be
overwritten unless the -i option is used to prompt for confirmation. Always
double-check your commands, especially when using options like -f to avoid
accidental data loss.
**Command echo: The echo command in Linux is used to display a line of text or a
variable's value in the terminal. It is commonly used in shell scripts and command-line
interfaces for outputting information.
echo [options] [string]
Common Options:
-n: Suppress the trailing newline.
-e: Enable interpretation of backslash escapes.
-E: Disable interpretation of backslash escapes (default behavior).
11
**Command cat: The cat command in Linux is used to concatenate and display the
contents of files. It is a versatile command that can read multiple files and print their
contents to the terminal, making it useful for viewing file content, combining files, and
creating new files.
cat [options] [file_name]
file_name: The name of the file(s) you want to display or manipulate.
Common Options:
-A: Show all characters, including non-printing characters.
-b: Number non-empty output lines.
-s: Suppress repeated empty output lines.
Answer:
-To create the images folder inside the Myweb folder, we execute the command: mkdir
Desktop/Myweb/images
12
- To ensure that we have successfully executed the mkdir Desktop/Myweb command, we
can use the ls Desktop command to check the directories in the Desktop directory before
and after using the mkdir Desktop/Myweb command. At this point, we see that the
Myweb folder is already in the Desktop folder after using the mkdir Desktop/Myweb
command, which means we have successfully created the Myweb folder inside the
Desktop folder.
- To create the Myweb folder inside the Desktop folder, we execute the command: mkdir
Desktop/Myweb.
- To create the databases folder inside the Myweb folder, we execute the command:
mkdir Desktop/Myweb/databases
13
- To ensure that we have successfully executed the mkdir Desktop/Myweb/databases
command, we can use the ls Desktop/Myweb command to check the directories
contained in the Myweb directory before and after using the mkdir
Desktop/Myweb/databases command. . At this point, we see that the databases directory
is already in the Myweb directory after using the command mkdir
Desktop/Myweb/databases, which means we have successfully created the databases
directory inside the Myweb directory.
- To create the scripts folder inside the Myweb folder, we execute the command: mkdir
Desktop/Myweb/scripts
- To create the java directory inside the Myweb directory, we execute the command:
mkdir Desktop/Myweb/java
14
this point, we see that the java directory is already in the Myweb directory after using the
mkdir Desktop/Myweb/java command, which means we have successfully created the
java directory inside the Myweb directory.
- To create an icon folder inside the images folder, we execute the command: mkdir
Desktop/Myweb/images/icon
- To create a background folder inside the images folder, we execute the command:
mkdir Desktop/Myweb/images/background
15
- To create an animation folder inside the images folder, we execute the command: mkdir
Desktop/Myweb/images/animation
16
To ensure that we have successfully executed the command find / -name *.html, we can
look at the screen and see that the system has listed the files with the .html extension for
us, which means we have successfully found the .html files in the system.
-To find some files with the .class extension in the file system (searching from the root
directory), we execute the command: sudo find / -name *.class
17
Unlike the previous command that searched for .html files, to find files with the .class
extension, we need to add the sudo command at the beginning to provide access
permissions; otherwise, we will encounter a "Permission denied" error. To ensure that we
have successfully executed the command sudo find / -name *.class, we can look at the
screen and see that the system has listed the files with the .class extension for us, which
means we have successfully found the .class files in the system.
*Copy file into Myweb :
-To copy an .html file into the Myweb directory, we need to find the address of an .html
file. Specifically, I choose the file located at
/usr/share/gtk-doc/html/iio-sensor-proxy/index.html. Then we execute the command:
cp /usr/share/gtk-doc/html/iio-sensor-proxy/index.html Desktop/Myweb
18
5. Remove the directory Myweb/scripts.
Answer:
To delete the Myweb/scripts directory, we execute the command: rm -rf
Desktop/Myweb/scripts
19
To ensure that we have successfully executed the command chmod u=rwx,go=
Desktop/Myweb/databases, we can use the command ls -l Desktop/Myweb to check the
access permissions of the directories in Myweb before and after using the command
chmod u=rwx,go= Desktop/Myweb/databases. At this point, we see that in the databases
directory, before using the command, the permissions were u=rwx (user has read, write,
and execute permissions), g=rwx (group has read, write, and execute permissions), and
o=r-x (others have read and execute permissions, but no write permissions). After using
the command chmod u=rwx,go= Desktop/Myweb/databases, the permissions are now
u=rwx (user has read, write, and execute permissions), g=--- (group has no permissions),
and o=--- (others have no permissions), which means we have successfully set the
permissions for the Myweb/databases directory.
20