Unix
Unix
Link is used to assigning more than one name to a file. It is like a pointer to a file and one file can
have multiple pointers. There are two types of link
Hard link- These hard-linked files are assigned to the same inode value as the original and thus
reference the same physical location of the file. Also if the file is moved to a different directory the
link will still work
Symbolic link- A soft link is similar to the file shortcut feature and it contains a separate inode
than the original one. If the original file is moved then the link might not work, but it can
reference across the different file systems.
Swapping: In the case of swapping the main memory is loaded with the complete process and
thus only the process less than the main memory size is executable. This is fairly easy to
implement but not very efficient.
Paging: On the other hand in the case of paging instead of loading the whole process into the
main memory only required memory pages are loaded. This is complex to implement but allows
us to run a number of processes simultaneously.
shell variables?
The shell has a few sets of predefined internal variables with the support of creating new ones as
well. Some of these are environment variables whereas others are local variables. These can be
accessed by different processes. The name of a variable can contain only letters(A-z), numbers(0-
9), or the underscore character ( _).
NAME="Sumit Roy"
$ echo $NAME
$ unset NAME
Explain the file system in UNIX
Boot lock
Inode lock
Data Block
Super Block
The UNIX file system has many different file system types such as ufs (UNIX filesystem),
NFS(Network file system), vxfs(Veritas file system), and cdfs(CD-ROM filesystem). Among these,
the ufs file system type is the most standard UNIX file system. Reads and writes to a ufs file
system are done in blocks depending on the size of the file system block size. Block sizes can
range from 1 KB to 8 KB depending on the file system type selected
It gives information about the location of where the engine is placed. The engine is the one that
executes the given script. It is placed at the top of the script
telnet: This is used for remote login and for communication with another hostname.
ping: This is used for checking network connectivity.
hostname: This gives the IP address and domain name.
nslookup: This performs a DNS query.
xtraceroute: This is used to determine the number of hops and response time required to reach
the network host.
netstat: This provides information about system and ports, routing tables, interface statistics,
etc.
tcpdump: This provides info about both incoming and outgoing network traffic
Name the various commands that are used for the user information in UNIX.
The various commands that are used for displaying the user information in Unix are:
id: This displays the active user id with login and group.
last: This displays the last login of the user in the system.
who: This determines who is logged onto the system.
groupadd admin: This is used to add group ‘admin’.
usermod –a: This is used to add an existing user to the group
getppid() retrieves the Parent Process ID, getpid() retrieves the Process ID and getpgrp()
retrieves the process group ID. The process also has a real user ID (the UID), an effective user ID
(the EUID), a real user group ID (the GID), and an effective user group ID (the EGID)
Current shell
sreejith@sreejith-vb:~/Projects/persius$ ps -p $$
PID TTY TIME CMD
1247 pts/1 00:00:00 bash
sreejith@sreejith-vb:~/Projects/persius$ echo $SHELL
/bin/bash
Find duplicate lines in a file and count how many time each line was duplicated?
sort <file> | uniq -c
print duplicate lines only, with counts:
sort FILE | uniq -cd
how many files are in each dir under your current dir:
for i in */ .*/ ; do
echo -n $i": " ;
(find "$i" -type f | wc -l) ;
Done
How to change permissions for a folder and its subfolders/files in one step
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
Cmp – Compare given two files with byte by byte and display the first
mismatch.
Diff – Display changes that need to do to make both files identical.
What are the various IDs in UNIX processes?
Answer: Process ID is a unique integer that UNIX uses to identify each process. The
process executes to initiate other processes is called parent process and its ID is
defined as PPID (Parent Process ID).
Every process is associated with a specific user and is called the owner of the
process. The owner has all the privileges over the process. The owner is also the
user who executes the process.
Identification for a user is the User ID. The process is also associated with Effective
User ID which determines the access privileges for accessing resources like files.