0% found this document useful (0 votes)
31 views11 pages

Lab Task

The document provides instructions for Lab #1 on familiarizing with the Linux command line. It covers objectives of understanding basic Linux commands and their execution. It describes absolute and symbolic modes for file permissions representation and provides examples of chmod commands. The in-lab tasks section lists various Linux commands like pwd, ls, cd, mkdir, rmdir, cp, mv, rm, cat, chmod, top, ps and their usage with examples to create, view, modify and delete files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views11 pages

Lab Task

The document provides instructions for Lab #1 on familiarizing with the Linux command line. It covers objectives of understanding basic Linux commands and their execution. It describes absolute and symbolic modes for file permissions representation and provides examples of chmod commands. The in-lab tasks section lists various Linux commands like pwd, ls, cd, mkdir, rmdir, cp, mv, rm, cat, chmod, top, ps and their usage with examples to create, view, modify and delete files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab # 1

Objectives
• To Familiarize with the Linux command line interpreter
• To be able to execute and interpret Linux basic commands
Pre-Lab Theory:
There are 2 ways to use the command
1. Absolute mode
2. Symbolic mode
Absolute(Numeric) Mode in
Linux
In this mode, file permissions are not represented as characters but a three-digit
octal umber.
The table below gives numbers for all permissions types.

Number Permission Type Symbol


0 No Permission —
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write rwx
+Execute

The categories of people's access:


• a all users
• u the owner user
• g the owner group
• o others (neither u, nor g)
The format for permissions is:
chmod {a,u,g,o} {+,-} {r,w,x} files
The plus ("+") sign indicates give permission. The minus ("-") sign indicates
remove permission.
Permission examples:
• chmod a+r files are readable by all
1
• chmod a-r files cancels the ability for all to read the file
• chmod a-rwx cancels all access for all
• chmod g+rw files give the group read and write permission
• chmod u+rwx files give the owner all permissions
• chmod og+rw files give the world and the group read and write permission
a. PATH:
a. Absolute Path
. From root directory
/root/home/. .
b. From current directory
mydirectory
b. .(dot) and ..(dot dot)
.(dot) refers to current directory
..(dot dot) refers to one level up directory
In-Lab Tasks
Linux Commands:
1. Present Working Directory:
$pwd
Task: write the output

2. Files and Subdirectories:

a. $ls
b. $ls -l

2
Task: Explain all the columns in the output Also interpret the first character of the first
column values Possible characters (-, d, l, p, s, b, c)

Running ls -l displays a list of files and directories with columns:


First Column:
The first character represents the type (- for file, d for directory, l for symlink, etc.).
Permissions (Columns 2-10):
3 characters for owner, group, and others (r=read, w=write, x=execute, - = no
permission).
Hard Links Count (Column 11):
Number of hard links to the item.
Owner (Column 12):
Name of the owner.
Group (Column 13):
Name of the group.
File Size (Column 14):
Size of the file in bytes.
Modification Date (Columns 15-17):
Date and time of last modification.
Name (Last Column):
Name of the file or directory.
The first character in the first column represents the item's type: - (file), d (directory), l
(symlink), p (named pipe), s (socket), b (block device), or c (character device).

a. Display the Hidden files


$ls -a
Task:Write the Output of the task:

3
c. Metacharacters/wild card
i. $ls ch*.doc

Task: First execute ls and then list some files through wild card and write output

3. Change Directory:

$cd ../
Change the directory to one level up
Task: execute ‘pwd’ first then ‘cd ../’ and write the output

Task: First execute ls and then list some files through wild card and write output

4
4. Creating Subdirectories:
$mkdir <subdirectory path>
Task: write the command to create subdirectory Lab1 in pwd

$mkdir -p <subdirectory path with parent directories> Parent


directories will be created if not exist

Task: write the command to create directories with the following hierarchy
/Linux_Commands/Lab_Tasks

5. Removing Subdirectories
$rmdir
Task: write the command to create a subdirectory Temp in the current directory and
then write the command to remove it

c. Copy Files

5
$cp <source file path> <destination file path>
Task: create and edit a file temp.dat using gedit with some text and save the
file in the Lab1 directory.
Write the command to copy temp.dat to subdirectory Lab_Tasks created in the
previous task

6. Renaming the file


$mv <file to rename> <renamed file>
Task: write a command to rename a file ‘temp.dat’ to ‘myfile.dat’ and execute ‘ls’ to
verify it.

7. Removing/Deleting the file


$rm <filename>
Task: write a command to remove the file temp.dat from the Lab Tasks subdi- rectory

8. Display the Contents of the file on the screen:


$cat <file path>
Task: create a file using $gedit xyz.dat type something, save the file, and exit Write a
command to display the xyz.dat file contents

6
9. Changing the permissions of the file
$chmod <nnn> <filename>
$chmod 777 xyz.txt
Task1: execute ls and write the permissions

Task2: write the command chmod 640 xyz.txt using symbolic mode

10. Display the word count of the file:


$wc <filename>
Task: write the command to diplay the word count of any file and Interpret the output
values

11. Display the PATH environment variable


$echo $PATH
Task: write the output

Redirection Operator (>)


Task1: Execute $ls -l > xyz.dat and explain the behavior

Behavior:

7
The command $ls -l lists detailed information about files and directories
in the current directory, including permissions, owner, group, and more.
Using > xyz.dat redirects this information to a file called xyz.dat instead
of displaying it on the screen.

Task2: Append some contents in the existing file ‘xyz.dat’ Write the
command string used to achieve the above task

12. Top Command:


$top
Task: Execute top command and interpret the output. Explain all the columns

Columns:
PID (Process ID): This column shows the unique identification number assigned to
each running process. It's a way to uniquely identify and reference processes.
USER: Displays the username of the user who started the process. Each process is
associated with a user.
PR (Priority): Indicates the priority of the process. Lower values generally indicate
higher priority. However, this column is not always used or accurate on all systems.

NI (Nice Value): Represents the "niceness" of the process, which is a way to


influence a process's priority. Processes with higher nice values have lower priority.
VIRT (Virtual Memory): Shows the total virtual memory used by the process. This
includes both physical RAM and swap space.
RES (Resident Memory): Displays the resident memory, which is the portion of
8
virtual memory that is currently in physical RAM.

SHR (Shared Memory): Indicates the amount of shared memory used by the
process. Shared memory is memory that can be used by multiple processes
simultaneously.
S (Status): Shows the current status of the process. Common statuses include:
R: Running
S: Sleeping
D: Disk sleep
Z: Zombie (terminated but not reaped by its parent process)
T: Stopped
%CPU (CPU Usage): Displays the percentage of CPU time used by the process
since the last screen refresh. This column helps identify CPU-intensive processes.
%MEM (Memory Usage): Shows the percentage of physical RAM used by the
process. It's a measure of how much memory the process is consuming.
TIME+ (Total CPU Time): Represents the total accumulated CPU time used by the
process since it started. It's an indicator of how much CPU resources the process has
consumed.
COMMAND: This column displays the name of the command or program associated
with the process

1. Listing the processes


$ps
Task: write and interpret the output

The ps command provides a list of currently running processes, showing their unique Process IDs
(PID), associated terminal type (TTY), CPU time usage, and the associated command or program
(CMD). It's a quick way to see what processes are running on a Unix-like system.

1. $gedit myfile.dat &


Task: Execute the above command and explain the behavior and importance of &

Importance of &:
Running a command with & makes it run in the background, freeing up your terminal for
other tasks. This is essential for multitasking, allowing you to work on other tasks while
9
one runs. It's particularly useful for long-running processes and when working on remote
servers.

1
0
1
1

You might also like