0% found this document useful (0 votes)
20 views

Ass 1

It's a assignment on operating system

Uploaded by

h4198390
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Ass 1

It's a assignment on operating system

Uploaded by

h4198390
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Task 1 : To study and execute the Commands in UNIX / LINUX

1. pwd Command

● Purpose: Prints the current working directory.


● Usage: pwd
● Description: This command outputs the full path of the current directory, allowing
users to identify their location within the filesystem.

2. cd Command

● Purpose: Changes the current directory.


● Usage: cd [directory]
● Description: This command allows users to navigate to a different directory. For
instance, cd /home/user moves to the specified directory. The command cd ..
navigates up one level in the directory hierarchy.

3. ls Command

● Purpose: Lists directory contents.


● Usage: ls [options] [directory]
● Description: Lists files and directories within a specified directory. Common options
include -l for a detailed list and -a for including hidden files.

4. rm Command

● Purpose: Removes files or directories.


● Usage: rm [options] [file/directory]
● Description: Deletes specified files or directories. The -r option allows recursive
deletion of directories and their contents, while -f forces removal without prompting.

5. mv Command

● Purpose: Moves or renames files and directories.


● Usage: mv [source] [destination]
● Description: This command can be used to move files from one location to another
or rename files and directories.

6. cat Command

● Purpose: Concatenates and displays file content.


● Usage: cat [file]
● Description: Outputs the content of files to the standard output. Useful for viewing
short files or combining multiple files.

7. cmp Command

● Purpose: Compares two files byte by byte.


● Usage: cmp [file1] [file2]
● Description: This command compares two files and reports the first byte and line
number where they differ. Useful for verifying file integrity.

8. cp Command

● Purpose: Copies files or directories.


● Usage: cp [options] [source] [destination]
● Description: Copies files or directories to a specified location. The -r option copies
directories recursively, and -i prompts before overwriting.

9. echo Command

● Purpose: Displays a line of text or a variable value.


● Usage: echo [text]
● Description: Outputs the specified text or value to the terminal. Often used in scripts
to display messages or variable values.

10. mkdir Command

● Purpose: Creates new directories.


● Usage: mkdir [options] [directory]
● Description: Creates one or more new directories. The -p option allows the creation
of parent directories as needed.

11. paste Command

● Purpose: Merges lines of files.


● Usage: paste [options] [file1] [file2]
● Description: Combines lines from multiple files horizontally. Useful for merging
related data files side by side.

12. rmdir Command

● Purpose: Removes empty directories.


● Usage: rmdir [directory]
● Description: Deletes empty directories. To remove non-empty directories, use the rm
-r command instead.
13. head Command

● Purpose: Displays the beginning of a file.


● Usage: head [options] [file]
● Description: Outputs the first few lines of a file, with the default being the first 10
lines. Useful for previewing file contents.

14. tail Command

● Purpose: Displays the end of a file.


● Usage: tail [options] [file]
● Description: Outputs the last few lines of a file, with the default being the last 10
lines. Commonly used for viewing log files.

15. date Command

● Purpose: Displays or sets the system date and time.


● Usage: date [options]
● Description: Outputs the current system date and time. Can be formatted with
options to display in different formats or set the date and time.

16. grep Command

● Purpose: Searches for patterns within files.


● Usage: grep [options] [pattern] [file]
● Description: Searches for lines in a file that match a specified pattern. Commonly
used with regular expressions for powerful text searching.

17. touch Command

● Purpose: Creates empty files or updates timestamps.


● Usage: touch [file]
● Description: Creates a new, empty file if it does not exist, or updates the
modification and access times of an existing file.

18. chmod Command

● Purpose: Changes file permissions.


● Usage: chmod [options] [permissions] [file]
● Description: Modifies the access permissions of a file or directory. Permissions can
be set using symbolic or numeric modes.

19. chown Command

● Purpose: Changes file ownership.


● Usage: chown [options] [owner][:group] [file]
● Description: Changes the owner and/or group of a file or directory. Useful for
managing file permissions and ownership in a multi-user environment.

20. man Command

● Purpose: Displays manual pages for commands.


● Usage: man [command]
● Description: Provides detailed documentation for various commands and system
calls. Essential for understanding the usage and options of commands.

21. clear Command

● Purpose: Clears the terminal screen.


● Usage: clear
● Description: Removes all content from the terminal window, providing a clean slate
for new commands or output.

22. ln Command

● Purpose: Creates hard and symbolic links.


● Usage: ln [options] [target] [link_name]
● Description: Creates links to files. The -s option creates a symbolic (soft) link,
whereas without it, a hard link is created.

23. mount Command

● Purpose: Mounts a filesystem.


● Usage: mount [options] [device] [mount_point]
● Description: Attaches a filesystem to the directory tree at a specified mount point.
Essential for accessing external drives or partitions.

24. umount Command

● Purpose: Unmounts a filesystem.


● Usage: umount [options] [mount_point]
● Description: Detaches a mounted filesystem from the directory tree, making it safe
to remove the device or partition.
Process related Commands

1. top Command

● Purpose: Displays real-time information about system processes.


● Usage: top
● Description: The top command provides a dynamic, real-time view of the system’s
processes, including their CPU and memory usage, process IDs, and other
performance metrics. It allows users to monitor system performance and resource
usage continuously. The display updates periodically, and users can interact with it to
sort and filter processes.

2. ps Command

● Purpose: Provides a snapshot of current processes.


● Usage: ps [options]
● Description: The ps command displays information about active processes at the
moment the command is run. It offers a snapshot of process details such as process
IDs, user IDs, CPU and memory usage, and command names.

Common Options:

- -e or -A: Displays all processes. - -f: Provides a full-format listing with additional details.
- -u [user]: Shows processes for a specific user. - -aux: A commonly used combination
that displays all processes with detailed information.

3. kill Command

● Purpose: Sends signals to processes, commonly used to terminate them.


● Usage: kill [options] [PID]
● Description: The kill command is used to send signals to processes, with the
most common signal being SIGTERM (signal number 15) which gracefully terminates
a process. The SIGKILL signal (signal number 9) forcefully terminates a process.

Common Signals:

- -15 or SIGTERM: Requests the process to terminate gracefully. - -9 or SIGKILL: Forces


the process to terminate immediately. Use with caution as it does not allow the process to
clean up resources. - -HUP: Often used to instruct a process to reload its configuration
without restarting.

4. nice Command

● Purpose: Starts a process with a specified priority.


● Usage: nice [options] [command]
● Description: The nice command adjusts the priority of processes when they are
started. The priority, known as "niceness," affects the amount of CPU time a process
receives. A higher nice value means lower priority, and a lower nice value (or
negative) means higher priority.

Common Options:

- -n [priority]: Sets the priority of the process. The priority value ranges from -20
(highest priority) to 19 (lowest priority). - -n is followed by a number that indicates the
priority level, e.g., nice -n 10 command starts command with a niceness of 10.

Network Related Commands

1. Ping Command

● Purpose: Checks connectivity to a network host.


● Usage: ping [options] host
● Description: Sends ICMP echo requests to a specified host and measures response
time. It's a basic tool to determine if a host is reachable.

Example:

ping google.com

2. ifconfig Command

● Purpose: Displays and configures network interfaces.


● Usage: ifconfig [options] interface
● Description: Shows details about network interfaces, such as IP addresses, MAC
addresses, and network masks. It can also be used to configure interfaces in some
cases.

Note: ifconfig is being replaced by ip in newer Linux systems.

Example:

ifconfig eth0

3. netstat Command
● Purpose: Displays network connections, routing tables, interface statistics, protocol
statistics, and more.
● Usage: netstat [options]
● Description: Provides a snapshot of network activity, including active connections,
listening ports, and routing table information.

Example:

netstat -anp

4. nslookup Command

● Purpose: Queries the Domain Name System (DNS) for information.


● Usage: nslookup [options] hostname
● Description: Resolves domain names to IP addresses and vice versa. It can also be
used to query DNS records for other information.

Example:

nslookup google.com

5. telnet Command

● Purpose: Provides a basic text-based communication protocol.


● Usage: telnet [host] [port]
● Description: Establishes a connection to a remote host on a specific port. It's
primarily used for debugging network services.

Note: Telnet is generally insecure due to plain text transmission. It's often replaced by SSH
for secure remote access.

Example:

telnet google.com 80

6. traceroute Command

● Purpose: Shows the route a packet takes to reach a destination.


● Usage: traceroute [options] host
● Description: Identifies intermediate hops between the source and destination,
measuring response time for each hop. Useful for troubleshooting network issues.

Example:

traceroute google.com
2. Explore Features of vi Editor

Basic Modes of vi

vi operates in different modes, each of which is used for specific tasks:

Normal Mode (Command Mode)

● Purpose: Used for navigation and command execution.


● Function: In this mode, you can move the cursor, delete text, copy and paste
content, and execute other editing commands. Pressing Esc from other modes will
return you to Normal Mode.

Insert Mode

● Purpose: Used for inserting and editing text.


● Function: In this mode, you can type and modify text as you would in any standard
text editor. You enter Insert Mode by pressing i, I, a, A, o, or O from Normal Mode.
Press Esc to return to Normal Mode.

Visual Mode

● Purpose: Used for selecting text.


● Function: In Visual Mode, you can highlight text for operations such as copying or
deleting. Enter Visual Mode by pressing v (character-wise), V (line-wise), or Ctrl+v
(block-wise) in Normal Mode. Press Esc to return to Normal Mode.

Command-Line Mode

● Purpose: Used for executing complex commands and saving files.


● Function: You enter Command-Line Mode by pressing : from Normal Mode. This
mode allows you to perform operations such as saving the file, quitting the editor, or
searching and replacing text.

Basic Operations in vi

Starting and Exiting vi

● Start vi: vi [filename]


○ Opens filename for editing. If the file does not exist, a new file is created.
● Save and Exit:
○ :wq or :x: Save changes and exit.
○ :w: Save changes without exiting.
○ :q: Exit without saving (if no changes were made).
○ :q!: Force exit without saving changes.
Navigation

● Arrow Keys: Move the cursor up, down, left, or right.


● h, j, k, l: Move the cursor left, down, up, or right (alternative to arrow keys).
● gg: Move to the beginning of the file.
● G: Move to the end of the file.
● :: Move to a specific line number.

Editing

● Insert Text:
○ i: Insert before the cursor.
○ I: Insert at the beginning of the line.
○ a: Append after the cursor.
○ A: Append at the end of the line.
○ o: Open a new line below the current line.
○ O: Open a new line above the current line.
● Delete Text:
○ x: Delete the character under the cursor.
○ dd: Delete the current line.
○ d[number]d: Delete multiple lines.
● Copy and Paste:
○ yy: Copy (yank) the current line.
○ p: Paste the copied content after the cursor.
○ P: Paste the copied content before the cursor.
● Undo and Redo:
○ u: Undo the last action.
○ Ctrl+r: Redo the last undone action.

You might also like