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

new 31

The document provides a comprehensive list of Unix commands and scripting techniques, addressing various tasks such as file manipulation, process management, and system monitoring. It includes commands for deleting files, transferring data, connecting to databases, and using loops and conditions in shell scripting. Additionally, it explains concepts like shebang, zombie processes, and the importance of pipes in Unix.

Uploaded by

fathima.uipath20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

new 31

The document provides a comprehensive list of Unix commands and scripting techniques, addressing various tasks such as file manipulation, process management, and system monitoring. It includes commands for deleting files, transferring data, connecting to databases, and using loops and conditions in shell scripting. Additionally, it explains concepts like shebang, zombie processes, and the importance of pipes in Unix.

Uploaded by

fathima.uipath20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q 1. How to delete empty lines in a file? --> sed '/^$/d' sample.txt > output.

txt
Q 2. How to print the hidden files? --> ls -a/ls -lart
Q 3. How to display the files in a directory, size less than 4 MB? --> find . -type
f -size -4M
Q 4. How to transfer files from one application Server to another server? --> scp
[email protected]:/home/opengenus/iq/information.txt . / scp -r
[email protected]:/home/opengenus/iq/ . r to copy entire directory
Q 5. How to connect to DB from Unix Server? --> sqlcmd -S SERVERNAME -U User -P pwd
-d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"

Q 6. What is the first line of the Script (shebang) and what it denotes/indicates?

On Linux, a shebang (#!) is a special line at the beginning of a script that tells
the operating system which interpreter to use when executing the script. This line,
also known as a hashbang, shabang or "sharp-exclamation", is the first line of a
dash and starts with "#!" followed by the path to the interpreter

Q 7. How to run a process in background and what is it’s advantage?


you can run other commands; you do not have to wait until it completes to start
another! The simplest way to start a background process is to add an ampersand (&)
at the end of the command
$ls ch*.doc &

Q 8 . How do you find the number of occurrences of the word in the file? (wc -w) --
> $ grep -o -i needs inspire.txt | wc -l

Q 10. How do you delete the files older than 10 days?


find /path/to/the/directory/ -type f -name '*' -mtime +10 -exec rm {} \;

Q 11. How do you find the line count for the matching pattern? grep -o -i mauris
example.txt | wc -l

Q 12. Write a command to print the lines that ends with the word "specific_word"?
grep 'unix$' your_file | sort

Q 13. Write a command to print the lines matching with exact word? grep 'unix$'
your_file | sort

Q 14. Match all words starting with “Particular String”. grep -w 'warning\|error\|
critical' /var/log/messages

Q 15. Match all pattern which starts with q and doesn’t follow by u?
Q 16. To show below and above 2 lines of the matching pattern?
Q 17. How to zip and unzip the files? unzip and zip
Q 18. How to display files names which contain given word?
Q 19. How to search for multiple matching string in the file?
Q 20. To delete the file which is having permission 644?
Q 21. How to change the permission of any file?
Q 22. How to set default permission of any file?
Q 23, What is the default permission newly created file and directory?
Q 24. Create a 0 byte file with 477 permission?
Q 25. If file content is space separated, then how to show only last field of the
file?
Q 26. Print all input lines from filename that have more than 4 fields.
Q 27. Print the total number of lines in the filename to the screen.
Q 28. If the files having 4 fields and if any field is blank then delete that
particular line?
Q 29. How to replace 4th occurrence of any pattern with given new pattern?
Q 30. How to replace the word from the 11th to 19th line only?
Q 31. How to replace all the occurrences of any word with given word in a file?
Q 32. How to print from 34th to 45th line with repeating the line?
Q 33. Write a command to print the lines that do not contain the word "run"?
Q 34. What is the difference between ‘cmp’ and ‘diff’ commands?
Q 35. How to open the file from 60th line?
Q 36. How to search any ERROR string in VI editor and navigate it? (upward &
downward)
Q 37. How to copy and delete any line in VI?
Q 38. How to go into Insert mode from Command mode?
Q 39. How to save the changes and exit from VI?
Q 40. How to go to 56th line in VI? Q: How you will find %memory & %CPU
utilization? (TOP command and it’s output)
Q 41. How to replace all occurrences of some specific character?
(:%s/oldText/newText/g)
Q 42. How to append a file to current file using VI editor?
Q 43. What is the UNIX command to list files/folders in alphabetical order and
sorted with modified time?
Q 44. What ‘more’ command does?
Q 45. How to display 57th line of the file? (with head and tail command)

tail -57 state.txt

Q 46. What is Zombie Process and how you get Zombie process in unix?

a zombie process or defunct process is a process that has completed execution (via
the exit system call) but still has an entry in the process table: it is a process
in the "Terminated state".

Q 47. What is the command to find maximum memory taking process on the server? Top

Q 48. What is the command to find the currently running process in Unix Server? ps
-ef

Q 49. What is the command to find remaining disk space] in the UNIX server? df -H
--output=source,size,used,avail

Q 50. What is the UNIX command to confirm a remote host is alive or not? --- ping -
s hostname
Q 51. What is the method to see command line history? -- doskey /history
Q 52. What is the command to find if the system is 32 bit or 64 bit? -- uname -a
Q 53. What is the purpose of the “echo” command? -- allows users to display lines
of text or strings that are passed as arguments
Q 54. Write a command to erase all files in the current directory including all its
subdirectories. rm -r /path/to/dir/*
Q 55. Which command is used for remote login? Telnet
Q 56. Which command determines the IP address and domain name?
Nslookup is the name of a program that lets users enter a host name and find out
the corresponding IP address or domain name system (DNS) record.

Q 57. What is the importance of $#? (arguments)

Stores the number of command-line arguments that were passed to the shell program
Q 58. How do you find status of the last command executed? (meaning of 0 & 1) fc -s
Q 59. Name the command that is used to take the backup?
dump [-level#] [-a autosize] [-A file] [-B records] [-b blocksize]
[-d density] [-D file] [-e inode numbers] [-E file] [-f file]
[-F script] [-h level] [-I nr errors] [-jcompression level] [-L label]
[-Q file] [-s feet] [-T date] [-y] [-zcompression level] files-to-dump
dump [-W | -w]

sudo dump 0uf /dev/qft0 /dev/sda6

Q 60. difference between $$ and $!?


$$ gives the process id of the currently executing process whereas $! Shows the
process id of the process that recently went into the background.

Q 61. If-Else condition in Shell Scripting?

if [condition]
then
statement1
else
statement2
fi

#!/bin/bash
m=1
n=2

if [ $n -eq $m ]
then
echo "Both variables are the same"
else
echo "Both variables are different"
fi

#!/bin/bash
a=2
b=7
if [ $a -ge $b ]
then
echo "The variable 'a' is greater than the variable 'b'."
else
echo "The variable 'b' is greater than the variable 'a'."
fi

Q 62. How to write a function in BASH Shell?

#!/bin/bash

printHello(){
echo "Hello World!"
}

printHello

functionName(){ echo "hello"; }


Q 63. What is the importance of PIPE command in Unix?
Generally, a pipe is a form of redirecting output to another destination for
further processing. It provides a temporary connection between two or more
commands, programs or processes. In Unix and Linux systems, a pipe enables more
complex processing. A pipe can also be used to combine two or more commands or
programs

Q 64. WHILE & FOR loop and CASE statement in Shell?

while [ condition ]
do
command1
command2
done

for var in list


do
command 1
command 2
done

Q 65. Why we use Break & Continue is Shell Scripting?


The break and continue commands allow you to exit loops in bash scripts or skip
remaining commands and go back to the top of a loop depending on particular
situations. They can be very handy when you need to skip some commands depending on
the data you are processing.

Q 66. Operators in UNIX Shell Scripting

#!/bin/bash

#reading data from the user


read -p 'Enter a : ' a
read -p 'Enter b : ' b

if(($a == "true" & $b == "true" ))


then
echo Both are true.
else
echo Both are not true.
fi

if(($a == "true" || $b == "true" ))


then
echo Atleast one of them is true.
else
echo None of them is true.
fi

if(( ! $a == "true" ))
then
echo "a" was initially false.
else
echo "a" was initially true.
fi
Arithmetic Operators
Relational Operators
Boolean Operators
Bitwise Operators
File Test Operators

You might also like