1- How to display the 10th line of a file?
1 |
head -10 filename | tail -1 |
2- How to remove the header from a file?
1 |
sed -i '1 d' filename |
3- How to remove the footer from a file?
1 |
sed -i '$ d" filename |
4- Write a command to find the length of a line in a file?
it can be used to get a line from a file.
1 |
sed -n '<n> p' filename |
To find the length of 10th line in a file.
1 |
sed -n '10 p' filename|wc -c |
5- How to get the nth word of a line in Unix?
1 |
cut -f <n> -d'' |
6- How to reverse a string in UNIX?
1 |
echo "Linux" | rev |
7- How to check if the last command was successful in unix?
1 |
kur:~ kur$ echo $? |
8 – How will you find which operating system is running on Unix?
1 |
kur:~ kur$ uname -a |
9-Â Write a command to print the lines that starts with the word “while”?
1 2 3 4 |
command : grep '^while' filename kur:~ kur$ grep '^while' hello.py while b < 200: |
10-Â What does $# stands for?
It will return the number of parameters passed as command line argument.
11-Â What is difference between diff and cmp command?
- cmp -It compares two files byte by byte and displays first mismatch.
- diff – It displays all changes required to make files identical.
12-Â What is command to kill last background Job?
1 |
kur:~ kur$ kill $! |
13- How kill the process?
1 2 3 4 5 |
command : kill -9 process id kur:~ kur$ ps -ef | grep java 1546581436 48801 600 0 12:14AM ttys001 0:00.00 grep java kur:~ kur$ kill -9 48801 |
14-Â What is command to check space in Unix?
1 2 3 4 5 6 7 8 |
kur:~ kur$ df -k Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on /dev/disk1 233242624 220130000 12856624 95% 2363205 4292604074 0% / devfs 191 191 0 100% 664 0 100% /dev /dev/disk3 487194624 471402940 15791684 97% 369572 4294597707 0% /Volumes/DATA HDD map -hosts 0 0 0 100% 0 0 100% /net map auto_home 0 0 0 100% 0 0 100% /home map -fstab 0 0 0 100% 0 0 100% /Network/Servers |
15 –Â How to check all the running processes in Unix?
1 2 3 4 5 6 7 |
kur:~ kur$ ps aux | grep java kur 48850 0.0 0.0 2442020 760 s001 S+ 12:17AM 0:00.00 grep java kur:~ kur$ ps -ef | grep java 1546581436 48862 600 0 12:18AM ttys001 0:00.00 grep java kur:~ kur$ ps -e -o stime,user,pid,args,%mem,%cpu |
16-Â How to check if a file is present in a particular directory in Unix?
1 2 3 |
kur:conf kur$ ls -l gitolite.conf; echo $? -rw-r--r-- 1 kur staff 13230 Jul 26 15:18 gitolite.conf 0 |
17-Â How to check the length of any line in a file?
1 2 |
kur:~ kur$ sed –n '<n> p' gitolite.conf kur:~ kur$ sed –n '35 p' gitolite.conf| wc –c |
18-Â Write a command to display todays date in the format of ‘yyyy-mm-dd’?
1 2 |
kur:censhare-product kur$ date '+%Y-%m-%d' 2017-08-03 |
19-Â Write a command to print the line number before each line?
1 2 3 4 5 6 7 8 9 10 11 12 |
kur:~ kur$ awk '{print NR, $0}' hello.py 1 #! python 2 3 # Fibonacci series: 4 # the sum of two elements defines the next 5 a, b = 0, 1 6 while b < 200: 7 print b, 8 a, b = b, a+b 9 10 11 |
20 –Â Write a command to print the lines that has the the pattern “july” in all the files in a particular directory?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
kur:~ kur$ grep july * grep: 10.153.8.128:8889: Is a directory grep: Applications: Is a directory grep: Desktop: Is a directory grep: Documents: Is a directory grep: Downloads: Is a directory grep: IT-services: Is a directory grep: Inventory: Is a directory grep: Library: Is a directory grep: Movies: Is a directory grep: Music: Is a directory grep: Pictures: Is a directory grep: Public: Is a directory grep: SSL: Is a directory grep: VirtualBox VMs: Is a directory grep: ansible: Is a directory |
21-Â Write a command to replace the word “divide” with “sum” in file?
1 2 3 4 5 6 7 8 9 |
kur:~ kur$ sed s/divde/sum/ < hello.py #! python # Fibonacci series: # the sum of two elements defines the next a, b = 0, 1 while b < 200: print b, a, b = b, a+b |
22-