You are on page 1of 4

Describe a link in 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

ln  [original filename] [link name]

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.

ln  -s [original filename] [link name]

What do chmod, chown, chgrp commands do?

 These are file management commands. These are used for:


 chmod - It changes the permission set of a file
 chown - It changes the ownership of the file.
 chgrp - It changes the group of the file.

$ chmod g+w testfile


It changes permission for a user group to write.
$ chown sroy8091 testfile
It changes the owner of testfile to sroy8091.
$ chgrp moderators testfile
It changes a group of testfile to moderators

Differentiate between swapping and paging?

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

These are a fundamental component of the file system:

 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

 In shell scripting, what is the significance of the Shebang line?

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

Can you enlist some commonly used network commands?

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

What are the various IDs in UNIX processes?


There are 3 ids associated with the Unix process:
PID - Process Id, which is unique in the range of 0 to 3000.
PPID - Parent process id
PGID - Process group id, which is used to group processes together.

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)

Which command is used to check the memory status?


The command used mostly to check memory status in Linux is “free”. Other commands that can
be used are given below: 

cat: It can be used to show or display Linux memory information. (cat/proc/meminfo)


vmstat: It can be used to report statistics of virtual memory. 
top: It can be used to check the usage of memory. 
htop: It can be used to find the memory load of each process

How to print lines with blank 5th field in CSV


awk -F, '!length($5)' file
awk -F',' '{if($5=="")print $0}' myfile
How to remove empty/blank lines from a file in Unix (including spaces)?
sed -i '/^$/d' file.txt

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

Show sum of file sizes in directory listing


du -bch

Count all occurrences of a string in a files with grep


grep -o string files | wc -l

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 {} \;

How to exclude a directory in find . command


Use the -prune primary. For example, if you want to exclude ./misc:
find . -path ./misc -prune -o -name '*.txt' -print
To exclude multiple directories, OR them between parentheses.
find . -type d \( -path ./dir1 -o -path ./dir2 -o -path ./dir3 \) -prune -o -name '*.txt' -print
To exclude directories with a specific name at any level, use the -name primary instead of -path.
find . -type d -name node_modules -prune -o -name '*.json' -print

Identify the zombie processes


top -b1 -n1 | grep Z
Describe fork() system call?

Answer: The command used to create a new process from an existing process is


called fork(). The main process is called the parent process and the new process id is
called the child process. The child process id is returned to the parent process and
the child gets 0. The returned values are used to check the process and the code
executed.

What is the process group?

Answer: A collection of one or more processes is called a process group. There is a


unique process id for each process group. The function “getpgrp” returns the process
group ID for the calling process.

What is the behavioral difference between “cmp” and “diff” commands?

Answer: Both commands are used for file comparison.

 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).

getppid() – Is a command to retrieve PPID

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.

 getpid() – Retrieve process id


 getuid() – Retrieve  user-id
 geteuid() – Retrieve effective user-id

You might also like