unix file
unix file
1. `man` : Stands for "manual"; displays manual pages for commands. - Syntax: `man [command]`.
3. `cat` : Concatenates files and displays them on the standard output. - Syntax: `cat [file]`.
12. `echo` : Prints arguments to the standard output. - Syntax: `echo [arguments]`.
13. `more` : Displays the contents of a file one screen at a time. - Syntax: `more [file]`.
14. `date`: Displays or sets the system date and time. - Syntax: `date [options]`.
15. `time` : Measures the time it takes for a command to execute. - Syntax: `time [command]`.
16. `kill` : Sends signals to processes. - Syntax: `kill [options] [process ID]`.
17. `history` : Displays the command history list. - Syntax: `history [options]`.
18. `chmod` : Changes file permissions. - Syntax: `chmod [options] [mode] [file]`.
19. `chown` : Changes file ownership. - Syntax: `chown [options] [user:group] [file]`.
24. `shutdown` : Shuts down or restarts the system. - Syntax: `shutdown [options] [time]`.
Vi Editor
- A text editor available in Unix/Linux systems.
- Basic operations:
- Switch to Insert mode: `i` (insert before cursor), `a` (append after cursor)
.bashrc
- A shell script that Bash runs whenever it is started interactively.
/etc/bashrc
- System-wide Bash configuration file.
Environment Variables
- Variables that define the environment in which programs run.
- Examples:
- Persisting changes: Modify `.bashrc` for user-specific changes or `/etc/bashrc` for system-wide changes. Displays the
contents of a file one screen at a time. - Syntax: `more [file]`.
Experiment 2. Write a shell script program to: a) display list of user currently logged in; b) to copy
contents of one file to another.
#!/bin/bash
echo "$users"
#!/bin/bash
exit 1
fi
destination_file="$2"
exit 1
fi
else
exit 1
fi
Experiment 3. Write a program using sed command to print duplicated lines of Input.
CODE :
Code Explanation:
CODE :
#!/bin/bash
if [ $# -ne 1 ]; then
exit 1
fi
filename=$1
Code :
#!/bin/awk -f
function fibonacci(n) {
if (n <= 1)
return n;
else
BEGIN {
printf("\n");
}
b) display the pattern of given string or number.
#!/bin/awk -f
printf("%s\n", pattern);
BEGIN {
display_pattern(input);
}
Experiment 6. Write a shell script program to a) display the process attributes; b) change priority of
processes; c) change the ownership of processes; d) to send back a process from foreground ; e) to
retrieve a process from background ; f) create a Zombie process
read pid
if [ ! -d "/proc/$pid" ]; then
exit 1
fi
echo "----------------------------------"
exit 0
b) change priority of processes
#!/bin/bash
echo -n "Enter the process ID (PID): " # Prompt the user to enter a process ID (PID) read pid
exit 1
fi
echo -n "Enter the new priority value (range: -20 to 19, default is 0): " # Prompt the user to enter the new priority
read priority
if [ "$priority" -lt -20 ] || [ "$priority" -gt 19 ]; then # Check if the entered priority is within the valid
range
echo "Invalid priority value. Priority must be in the range of -20 to 19."
exit 1
fi
else
Fi
exit 0
#!/bin/bash
echo -n "Enter the process ID (PID) to send to background: " # Prompt the user to enter the process ID (PID)
read pid
exit 1
fi
else
Fi
exit 0
read pid
exit 1
fi
fi
exit 0
Experiment 7. Write a program to create a child process and allow the parent to display “parent” and the
child to display “child” on the screen
#!/bin/bash
echo "child"
exit 0
Experiment 8. Write a makefile to compile a C program.
# Compiler
CC = gcc
$(CC) $(CFLAGS) -o $@ $^
rm -f $(EXE)
Experiment 9. Study to execute programs using gdb to utilize its various features like breakpoints, conditional
breakpoints. Also write a shell script program to include verbose and xtrace debug option for debugging.
1. Setting Up GDB:
- Ensure that GDB is installed on your system. If not, you can install it using your package manager (e.g., `sudo apt
install gdb` on Debian-based systems).
- Compile your C program with debugging symbols enabled. For example, use the `-g` flag with `gcc`: `gcc -g
program.c -o program`.
- Start GDB by running `gdb` followed by the name of the executable: `gdb program`.
- You can also start GDB and immediately run the program by using the `run` command: `gdb program --args
[arguments]`.
3. Breakpoints:
- Set breakpoints at specific lines of code using the `break` command: `break filename:linenumber`.
4. Conditional Breakpoints:
- Set conditional breakpoints using the `break` command followed by a condition: `break linenumber if condition`.
- Use the `next` (`n`) and `step` (`s`) commands to step through the code line by line.
- Use the `print` (`p`) command followed by the variable or expression you want to print: `print variable`.
7. Examining Memory:
#!/bin/bash
ls -l
Experiment 10. Study to use ssh, telnet, putty, ftp, ncftp and other network tools.
- SSH is a protocol used to securely access and manage remote systems over an unsecured network.
- It provides strong encryption and authentication mechanisms to protect sensitive data during transmission.
- SSH clients, such as OpenSSH (command-line), PuTTY (Windows), and SecureCRT (multi-platform), establish
encrypted connections to SSH servers.
- SSH supports various authentication methods, including password authentication, public key authentication, and
keyboard-interactive authentication.
- It allows users to securely execute commands on remote systems, transfer files, and forward ports for secure
remote access.
2. Telnet :
- Telnet is a protocol used for remote terminal connection and communication over TCP/IP networks.
- It provides a bidirectional interactive text-oriented communication session between a client and a server.
- Telnet operates on port 23 by default and sends data, including usernames and passwords, in plaintext, making it
insecure.
- Due to security concerns, Telnet is rarely used for remote access and has largely been replaced by SSH.
3. PuTTY :
- PuTTY is a free and open-source terminal emulator, serial console, and network file transfer application primarily
used for SSH connections.
- It supports various network protocols, including SSH, Telnet, rlogin, and raw socket connections.
- PuTTY is lightweight, easy to use, and highly configurable, making it a popular choice for SSH clients on Windows
platforms.
- It provides features such as session management, SSH key management, and port forwarding for secure remote
access.
4. FTP (File Transfer Protocol) :
- FTP is a standard network protocol used for transferring files between a client and a server on a computer
network.
- It operates over TCP/IP and provides commands for uploading, downloading, renaming, and deleting files and
directories.
- FTP clients establish connections to FTP servers using port 21 for control information and port 20 for data
transmission.
- Although FTP is widely supported and easy to use, it lacks security features, such as encryption, making it
vulnerable to eavesdropping and data tampering.
5. ncftp :
- ncftp is a command-line FTP client that provides an interactive interface for transferring files between systems.
- It supports various FTP protocols, including FTP, FTPS (FTP over SSL), and SFTP (SSH File Transfer Protocol).
- ncftp offers features such as bookmarking, recursive file transfer, and directory synchronization, making it
suitable for both novice and advanced users.
- It is lightweight, efficient, and cross-platform, available for Unix-like operating systems and Windows.