http://stackoverflow.com/
http://serverfault.com/
http://meta.stackoverflow.com
http://superuser.com
http://programmers.stackexchange.com
http://webapps.stackexchange.com/
http://security.stackexchange.com/
http://dba.stackexchange.com/
http://askubuntu.com/
http://unix.stackexchange.com/
http://stackexchange.com/
http://www.michael-noll.com/
http://www.thegeekstuff.com/
http://graphite.wikidot.com/
http://graphite.wikidot.com/faq
http://graphite.wikidot.com/start
http://graphite.readthedocs.org
http://tompurl.com/2011/08/12/installing-graphite-on-ubuntu-10-4-lts/
http://www.smilecouple.org/2011/03/01/fix-out-of-resource-problem-with-mysql
http://kaivanov.blogspot.in/
http://www.americanscientist.org/issues/pub/2002/3/the-easiest-hard-problem/2
http://www.slideshare.net/sudhirpg/ganglia-monitoring-tool
http://www.ibm.com/developerworks/library/l-ganglia-nagios-1/
http://blogs.hbr.org/cs/2013/02/write_e-mails_that_people_wont.html
http://redis.io/
http://redis.io/topics/data-types#strings
http://redis.io/documentation
http://try.redis.io/
http://redis.io/commands
Hadoop Operations: [http://www.amazon.com/Hadoop-Operations-Eric-Sammer/dp/1449327052/ref=pd_sim_b_1 ]
http://www.tummy.com/articles/isolating-heavy-load/
http://www.tummy.com/
http://cherry.world.edoors.com/
http://www.infoworld.com/d/application-development/10-programming-languages-could-shake-it-181548
Disclaimer: Its a collection from lots of other site(s) and few of my notes. I would also like to declare that I am not owning lots of its content. Please feel free to contact me directly if you want me to remove any of your content, that you don't want to share to other through this blog.
Wednesday, 12 June 2013
AWS_Amazon_Spot_Instance
AWS: Amazon spot instance:
The purpose of using an Amazon Spot instance is for:
1. To save money (it’s cheaper to run servers on Amazon as Spot instances)
2. To make recovering a failed instance very fast and easy.
Q1. How this is cheaper?
Few example:
http://www.youtube.com/embed/WD9N73F3Fao?rel=0&hd=1
http://www.youtube.com/embed/BD1X5ItelOk?rel=0&hd=1
Because, even if we have bid for the higher price, its charges for the current spot price.
Example:
1. A linux c1xl server's current bid price is $0.070 [ 7 cents only per hour ]
2. The On demand price is around $0.50 [ 50 cents per hour]
and out bid price is $0.75 [ 75 cents per hour ] which is higher even the on demand price, but how its can cost less? Because its charge on the current spot price [ which is 7 cents now]. Then why we are requesting for that high bid price [ around 75 cents ] even higher then spot price?
Note that, the spot instance goes away if some one bid in higher price, so when we have our bid price is more then the on-demand price, then most likely we have a higher chances that out hosts will not go down, and the spot price stay much lower then on demand price for a longer time. Hence we save an overall money and a higher chances of getting the spot instance for longer time.
For more details, please follow the above youtube links.
A Spot Instance on Amazon is how customers can ‘bid’ for unused capacity on Amazon’s infrastructure. The cost to run a Spot Instance is always fluctuating. As long as that cost is below the maximum ‘bid’ price that we bid, then the server continues to run. However, when Amazon has system issues, network issues, etc, then the current Spot Instance price will go up, exceeding our maximum bid price. When this happens, the server will be terminated instantly without any warning. Therefore, Spot Instances are useless for things like a Database Server. And they are only useful for areas of the product that are designed to take advantage of them.
AWS wiki link: http://aws.amazon.com/ec2/spot-instances/ [ Further details ]
The purpose of using an Amazon Spot instance is for:
1. To save money (it’s cheaper to run servers on Amazon as Spot instances)
2. To make recovering a failed instance very fast and easy.
Q1. How this is cheaper?
Few example:
http://www.youtube.com/embed/WD9N73F3Fao?rel=0&hd=1
http://www.youtube.com/embed/BD1X5ItelOk?rel=0&hd=1
Because, even if we have bid for the higher price, its charges for the current spot price.
Example:
1. A linux c1xl server's current bid price is $0.070 [ 7 cents only per hour ]
2. The On demand price is around $0.50 [ 50 cents per hour]
and out bid price is $0.75 [ 75 cents per hour ] which is higher even the on demand price, but how its can cost less? Because its charge on the current spot price [ which is 7 cents now]. Then why we are requesting for that high bid price [ around 75 cents ] even higher then spot price?
Note that, the spot instance goes away if some one bid in higher price, so when we have our bid price is more then the on-demand price, then most likely we have a higher chances that out hosts will not go down, and the spot price stay much lower then on demand price for a longer time. Hence we save an overall money and a higher chances of getting the spot instance for longer time.
For more details, please follow the above youtube links.
A Spot Instance on Amazon is how customers can ‘bid’ for unused capacity on Amazon’s infrastructure. The cost to run a Spot Instance is always fluctuating. As long as that cost is below the maximum ‘bid’ price that we bid, then the server continues to run. However, when Amazon has system issues, network issues, etc, then the current Spot Instance price will go up, exceeding our maximum bid price. When this happens, the server will be terminated instantly without any warning. Therefore, Spot Instances are useless for things like a Database Server. And they are only useful for areas of the product that are designed to take advantage of them.
AWS wiki link: http://aws.amazon.com/ec2/spot-instances/ [ Further details ]
Spot Instance Issues
A Spot Instance has to be set up in a special way in order for it to work correctly.
When
our maximum ‘bid’ price is exceeded, the server will be terminated.
Then, when the current price drops back below our maximum bid price, the
server will be re-launched. When it is re-launched, it’s like it was
launched for the first time: it gets a new InstanceId, all data is lost,
etc. Therefore, any data that must be retained has to be on a separate EBS volume.
Also,
the IP addresses that the spot instance uses will also change when it
is re-launched. This causes issues for both monitoring and for
database access, since the server’s IP address is used for both.
This means that the Spot Instance must have boot-up scripts that:
- mount an /ebs volume where the data is stored,
-
all data that we change on a regular basis (Apache Document Root, etc)
must be links from the root disk to locations under /ebs
- we must assign an Elastic IP address when the instance boots up, so it gets the same public IP address and Amazon DNS name each time it is re-launched. The Amazon DNS name will not change, but the Private IP Address that it resolves to *does* change.
Monday, 20 May 2013
Media Coversion with avconv
This is the note on using some tools at "Ubuntu" to convert different file type of source to multiple destination file type at the destination:
NOTE:
The bit rate is quantified using the bits per second (bit/s or bps) unit.
MP3
The MP3 audio format lossy data compression. Audio quality improves with increasing bitrate.
32 kbit/s - generally acceptable only for speech
96 kbit/s - generally used for speech or low-quality streaming
128 or 160 kbit/s – mid-range bitrate quality
192 kbit/s - a commonly used high-quality bitrate
320 kbit/s - highest level supported by MP3 standard
Video
128–384 kbit/s – business-oriented videoconferencing quality using video compression
1.5 Mbit/s max – VCD quality (using MPEG1 compression)[16]
9.8 Mbit/s max – DVD (using MPEG2 compression)[17]
8 to 15 Mbit/s typ – HDTV quality (with bit-rate reduction from MPEG-4 AVC compression)
19 Mbit/s approximate — HDV 720p (using MPEG2 compression)[18]
24 Mbit/s max — AVCHD (using MPEG4 AVC compression)[19]
25 Mbit/s approximate — HDV 1080i (using MPEG2 compression)[18]
29.4 Mbit/s max – HD DVD
40 Mbit/s max – Blu-ray Disc (using MPEG2, AVC or VC-1 compression)[20]
I believe youtube 320p use somewhere around 720k [.7M] bit rate.
The lower the bit rate the lesser the filesize but it will reduce the file quility, mean while if you use higher bit rate then the original file then you will find empty bits and that is not good.
=========================================================================
-> Package needed "ffmpeg"
Converting "mkv" file to "mp4" file.
avconv -i "file_name.mkv" -c copy "file_name.mp4"
avconv [global options] [[infile options][-i infile]]... {[outfile options] outfile}...
Specified by the "-i" option, and writes to an arbitrary number of output "files", which are specified by a plain output filename. As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.
Do not mix input and output files -- first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.
· To set the video bitrate of the output file to 64kbit/s:
avconv -i input.avi -b 64k output.avi
· To force the frame rate of the output file to 24 fps:
avconv -i input.avi -r 24 output.avi
· To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:
avconv -r 1 -i input.m2v -r 24 output.avi
The format option may be needed for raw input files.
-codecs
Show available codecs. The fields preceding the codec names have the following meanings:
D Decoding available
E Encoding available
V/A/S Video/audio/subtitle codec
S Codec supports slices
D Codec supports direct rendering
T Codec can handle input truncated at random locations instead of only at frame boundaries
Main options
-f fmt (input/output)
Force input or output file format. The format is normally autodetected for input files and guessed from file extension for output files, so this option is not needed in most cases.
-i filename (input)
input file name
-y (global)
Overwrite output files without asking.
-t duration (output)
Stop writing the output after its duration reaches duration. duration may be a number in seconds, or in "hh:mm:ss[.xxx]" form.
-fs limit_size (output)
Set the file size limit.
-ss position (input/output)
When used as an input option (before "-i"), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate. position may be either in seconds or in "hh:mm:ss[.xxx]" form.
-target type (output)
Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50"). type may be prefixed with "pal-", "ntsc-" or "film-" to use the corresponding standard. All the format options (bitrate, codecs, buffer sizes) are then set automatically.
You can just type:
avconv -i myfile.avi -target vcd /tmp/vcd.mpg
Nevertheless you can specify additional options as long as you know they do not conflict with the standard, as in:
avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
-aspect[:stream_specifier] aspect (output,per-stream)
Set the video display aspect ratio specified by aspect. aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values.
-bt tolerance
Set video bitrate tolerance (in bits, default 4000k). Has a minimum value of: (target_bitrate/target_framerate). In 1-pass mode, bitrate tolerance specifies how far ratecontrol is willing to deviate from the target average bitrate value. This is not related to min/max bitrate. Lowering tolerance too much has an adverse effect on quality.
-maxrate bitrate
Set max video bitrate (in bit/s). Requires -bufsize to be set.
-minrate bitrate
Set min video bitrate (in bit/s). Most useful in setting up a CBR encode:
avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
It is of little use elsewise.
· You can set several input files and output files:
avconv -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
Converts the audio file a.wav and the raw YUV video file a.yuv to MPEG file a.mpg.
avconv -i /tmp/a.wav -map 0:a -b 64k /tmp/a.mp2 -map 0:a -b 128k /tmp/b.mp2
Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map file:index' specifies which input stream is used for each output stream, in the order of the definition of output streams.
· You can transcode decrypted VOBs:
avconv -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi
This is a typical DVD ripping example; the input is a VOB file, the output an AVI file with MPEG-4 video and MP3 audio. Note that in this command we use B-frames so the MPEG-4 stream is DivX5 compatible, and GOP size is 300 which means one intra frame every 10 seconds for 29.97fps input video. Furthermore, the audio stream is MP3-encoded, so you need to enable LAME support by passing "--enable-libmp3lame" to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language.
NOTE: To see the supported input formats, use "avconv -formats".
· You can extract images from a video, or create a video from many images:
For extracting images from a video:
avconv -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.
If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.
For creating a video from many images:
avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
The syntax "foo-%03d.jpeg" specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.
=========================================================================
For more details man avconv.
NOTE:
The bit rate is quantified using the bits per second (bit/s or bps) unit.
MP3
The MP3 audio format lossy data compression. Audio quality improves with increasing bitrate.
32 kbit/s - generally acceptable only for speech
96 kbit/s - generally used for speech or low-quality streaming
128 or 160 kbit/s – mid-range bitrate quality
192 kbit/s - a commonly used high-quality bitrate
320 kbit/s - highest level supported by MP3 standard
Video
128–384 kbit/s – business-oriented videoconferencing quality using video compression
1.5 Mbit/s max – VCD quality (using MPEG1 compression)[16]
9.8 Mbit/s max – DVD (using MPEG2 compression)[17]
8 to 15 Mbit/s typ – HDTV quality (with bit-rate reduction from MPEG-4 AVC compression)
19 Mbit/s approximate — HDV 720p (using MPEG2 compression)[18]
24 Mbit/s max — AVCHD (using MPEG4 AVC compression)[19]
25 Mbit/s approximate — HDV 1080i (using MPEG2 compression)[18]
29.4 Mbit/s max – HD DVD
40 Mbit/s max – Blu-ray Disc (using MPEG2, AVC or VC-1 compression)[20]
I believe youtube 320p use somewhere around 720k [.7M] bit rate.
The lower the bit rate the lesser the filesize but it will reduce the file quility, mean while if you use higher bit rate then the original file then you will find empty bits and that is not good.
=========================================================================
-> Package needed "ffmpeg"
Converting "mkv" file to "mp4" file.
avconv -i "file_name.mkv" -c copy "file_name.mp4"
avconv [global options] [[infile options][-i infile]]... {[outfile options] outfile}...
Specified by the "-i" option, and writes to an arbitrary number of output "files", which are specified by a plain output filename. As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.
Do not mix input and output files -- first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.
· To set the video bitrate of the output file to 64kbit/s:
avconv -i input.avi -b 64k output.avi
· To force the frame rate of the output file to 24 fps:
avconv -i input.avi -r 24 output.avi
· To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:
avconv -r 1 -i input.m2v -r 24 output.avi
The format option may be needed for raw input files.
-codecs
Show available codecs. The fields preceding the codec names have the following meanings:
D Decoding available
E Encoding available
V/A/S Video/audio/subtitle codec
S Codec supports slices
D Codec supports direct rendering
T Codec can handle input truncated at random locations instead of only at frame boundaries
Main options
-f fmt (input/output)
Force input or output file format. The format is normally autodetected for input files and guessed from file extension for output files, so this option is not needed in most cases.
-i filename (input)
input file name
-y (global)
Overwrite output files without asking.
-t duration (output)
Stop writing the output after its duration reaches duration. duration may be a number in seconds, or in "hh:mm:ss[.xxx]" form.
-fs limit_size (output)
Set the file size limit.
-ss position (input/output)
When used as an input option (before "-i"), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate. position may be either in seconds or in "hh:mm:ss[.xxx]" form.
-target type (output)
Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50"). type may be prefixed with "pal-", "ntsc-" or "film-" to use the corresponding standard. All the format options (bitrate, codecs, buffer sizes) are then set automatically.
You can just type:
avconv -i myfile.avi -target vcd /tmp/vcd.mpg
Nevertheless you can specify additional options as long as you know they do not conflict with the standard, as in:
avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
-aspect[:stream_specifier] aspect (output,per-stream)
Set the video display aspect ratio specified by aspect. aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values.
-bt tolerance
Set video bitrate tolerance (in bits, default 4000k). Has a minimum value of: (target_bitrate/target_framerate). In 1-pass mode, bitrate tolerance specifies how far ratecontrol is willing to deviate from the target average bitrate value. This is not related to min/max bitrate. Lowering tolerance too much has an adverse effect on quality.
-maxrate bitrate
Set max video bitrate (in bit/s). Requires -bufsize to be set.
-minrate bitrate
Set min video bitrate (in bit/s). Most useful in setting up a CBR encode:
avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
It is of little use elsewise.
· You can set several input files and output files:
avconv -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
Converts the audio file a.wav and the raw YUV video file a.yuv to MPEG file a.mpg.
avconv -i /tmp/a.wav -map 0:a -b 64k /tmp/a.mp2 -map 0:a -b 128k /tmp/b.mp2
Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map file:index' specifies which input stream is used for each output stream, in the order of the definition of output streams.
· You can transcode decrypted VOBs:
avconv -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi
This is a typical DVD ripping example; the input is a VOB file, the output an AVI file with MPEG-4 video and MP3 audio. Note that in this command we use B-frames so the MPEG-4 stream is DivX5 compatible, and GOP size is 300 which means one intra frame every 10 seconds for 29.97fps input video. Furthermore, the audio stream is MP3-encoded, so you need to enable LAME support by passing "--enable-libmp3lame" to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language.
NOTE: To see the supported input formats, use "avconv -formats".
· You can extract images from a video, or create a video from many images:
For extracting images from a video:
avconv -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.
If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.
For creating a video from many images:
avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
The syntax "foo-%03d.jpeg" specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.
=========================================================================
For more details man avconv.
Monday, 6 May 2013
External Read Me Links
Monitoring:
----------
https://www.elance.com/ [ Find great freelance jobs ]
http://hasgeek.com/
https://groups.google.com/forum/?fromgroups#!forum/algogeeks
http://www.slideshare.net/sudhirpg/ganglia-monitoring-tool
http://www.ibm.com/developerworks/library/l-ganglia-nagios-1/
http://blogs.hbr.org/cs/2013/02/write_e-mails_that_people_wont.html
http://redis.io/
http://redis.io/topics/data-types#strings
http://redis.io/documentation
http://try.redis.io/
http://redis.io/commands
Hadoop Operations: [http://www.amazon.com/Hadoop-Operations-Eric-Sammer/dp/1449327052/ref=pd_sim_b_1 ]
http://www.tummy.com/articles/isolating-heavy-load/
http://www.tummy.com/
http://www.tutorialspoint.com
http://techpreparation.com/mysql-interview-questions-answers1.htm
http://mysqlboss.blogspot.in/
http://www.iheavy.com/2012/02/26/top-mysql-dba-interview-questions-part-1/
http://mangesh7rhcss.wordpress.com/2010/09/01/mysql-interview-questions/
http://www.techinterviews.com/29-mysql-interview-questions
http://www.sandykadam.com/interview-questions/mysql-interview-questions-part-2/
http://www.webslike.com/Thread-Puppet-System-Administrator-Interview-Questions-Answers
http://isitup.wordpress.com/tag/linux-administrator-interview-questions/
https://ext4.wiki.kernel.org/index.php/Frequently_Asked_Questions
http://www.thegeekstuff.com/2011/05/ext2-ext3-ext4/
http://en.wikipedia.org/wiki/Journaling_file_system
http://www.thegeekstuff.com/2009/01/15-practical-usages-of-mysqladmin-command-for-administering-mysql-server/
http://www.techinterviews.com/29-mysql-interview-questions
http://isitup.wordpress.com/tag/linux-administrator-interview-questions/
http://amitmund.blogspot.in/2013/02/bash-notes.html
https://sites.google.com/site/amitmund/unix_interview_question
http://amitmund.blogspot.in/2013/03/linuxinterviewquestions.html
http://nixcraft.com/linux-software/9693-linux-administrator-interview-questions.html
http://xtremediary.blogspot.in/2010/04/top-100-linux-interview-questions.html
http://www.gointerviews.com/top-50-linux-interview-questions/
http://javarevisited.blogspot.in/2011/05/unix-command-interview-questions.html
http://www.domainavenue.com/faq_dns.htm
http://docs.oracle.com/cd/E19683-01/806-4077/6jd6blbbp/index.html
http://www.cyberciti.biz/tips/determine-block-size-on-hard-disk-quota.html
http://www.cyberciti.biz/faq/unix-linux-shell-remove-delete-empty-lines/
----------
https://www.elance.com/ [ Find great freelance jobs ]
http://hasgeek.com/
https://groups.google.com/forum/?fromgroups#!forum/algogeeks
http://www.slideshare.net/sudhirpg/ganglia-monitoring-tool
http://www.ibm.com/developerworks/library/l-ganglia-nagios-1/
http://blogs.hbr.org/cs/2013/02/write_e-mails_that_people_wont.html
http://redis.io/
http://redis.io/topics/data-types#strings
http://redis.io/documentation
http://try.redis.io/
http://redis.io/commands
Hadoop Operations: [http://www.amazon.com/Hadoop-Operations-Eric-Sammer/dp/1449327052/ref=pd_sim_b_1 ]
http://www.tummy.com/articles/isolating-heavy-load/
http://www.tummy.com/
http://www.tutorialspoint.com
http://techpreparation.com/mysql-interview-questions-answers1.htm
http://mysqlboss.blogspot.in/
http://www.iheavy.com/2012/02/26/top-mysql-dba-interview-questions-part-1/
http://mangesh7rhcss.wordpress.com/2010/09/01/mysql-interview-questions/
http://www.techinterviews.com/29-mysql-interview-questions
http://www.sandykadam.com/interview-questions/mysql-interview-questions-part-2/
http://www.webslike.com/Thread-Puppet-System-Administrator-Interview-Questions-Answers
http://isitup.wordpress.com/tag/linux-administrator-interview-questions/
https://ext4.wiki.kernel.org/index.php/Frequently_Asked_Questions
http://www.thegeekstuff.com/2011/05/ext2-ext3-ext4/
http://en.wikipedia.org/wiki/Journaling_file_system
http://www.thegeekstuff.com/2009/01/15-practical-usages-of-mysqladmin-command-for-administering-mysql-server/
http://www.techinterviews.com/29-mysql-interview-questions
http://isitup.wordpress.com/tag/linux-administrator-interview-questions/
http://amitmund.blogspot.in/2013/02/bash-notes.html
https://sites.google.com/site/amitmund/unix_interview_question
http://amitmund.blogspot.in/2013/03/linuxinterviewquestions.html
http://nixcraft.com/linux-software/9693-linux-administrator-interview-questions.html
http://xtremediary.blogspot.in/2010/04/top-100-linux-interview-questions.html
http://www.gointerviews.com/top-50-linux-interview-questions/
http://javarevisited.blogspot.in/2011/05/unix-command-interview-questions.html
http://www.domainavenue.com/faq_dns.htm
http://docs.oracle.com/cd/E19683-01/806-4077/6jd6blbbp/index.html
http://www.cyberciti.biz/tips/determine-block-size-on-hard-disk-quota.html
http://www.cyberciti.biz/faq/unix-linux-shell-remove-delete-empty-lines/
Thursday, 25 April 2013
SRE Interview Questions 4
SRE Interview Questions 4
1. How SSL Certificate works? Give some more details on certificates and https.
2. Can we use single SSL certificate for on shared hosting where, we have multiple domain that is running on a single public IP address.
3. Can you please tell few Dns records types.
4. What is the difference between exec() and fork()
5. Lets say I have a host with 8GB of RAM and one of my application can grow upto 5GB of memory use, and as per my application in some time it do a scp call for some data receive/transfer. But some time its don't work. On the Log it says the can't start the scp. What can be the issue and what type of Architectural decision you will do for this kind of the issue.
6. What is zfs and zpool?
7. what is block and what is chunk?
8. What is the linux boot process?
9. One of the developer said that today my application is working slow, what all you will check for resolve this?
10. Site is slow, what all you will do to resolve this ?
11. What all you will do to fine tune a mysql db?
12. How you can find what are the slow query on a mysql db.
13. How you will find how many connection is there at the mysql?
14. What is the difference between different type of file-systems [ ext3 or ext4 ] example?
15. How DNS works?
16. How the nagios NRPE talk to the nagios Server.
Nagios <-> NRPE Data flow.
--------------------------------------
A. Nagios Server execute check_nrpe command at the nagios server and request the remote host to execute the run the command.
B. The check_nrpe command at nagios-server contact NRPE daemon on the remote host and remote to execute the check-command.
C. The output of the remote command returned back ti broe daemon to the check_nrpe on the nagios server.
1. How SSL Certificate works? Give some more details on certificates and https.
2. Can we use single SSL certificate for on shared hosting where, we have multiple domain that is running on a single public IP address.
3. Can you please tell few Dns records types.
4. What is the difference between exec() and fork()
5. Lets say I have a host with 8GB of RAM and one of my application can grow upto 5GB of memory use, and as per my application in some time it do a scp call for some data receive/transfer. But some time its don't work. On the Log it says the can't start the scp. What can be the issue and what type of Architectural decision you will do for this kind of the issue.
6. What is zfs and zpool?
7. what is block and what is chunk?
8. What is the linux boot process?
9. One of the developer said that today my application is working slow, what all you will check for resolve this?
10. Site is slow, what all you will do to resolve this ?
11. What all you will do to fine tune a mysql db?
12. How you can find what are the slow query on a mysql db.
13. How you will find how many connection is there at the mysql?
14. What is the difference between different type of file-systems [ ext3 or ext4 ] example?
15. How DNS works?
16. How the nagios NRPE talk to the nagios Server.
Nagios <-> NRPE Data flow.
--------------------------------------
A. Nagios Server execute check_nrpe command at the nagios server and request the remote host to execute the run the command.
B. The check_nrpe command at nagios-server contact NRPE daemon on the remote host and remote to execute the check-command.
C. The output of the remote command returned back ti broe daemon to the check_nrpe on the nagios server.
Sunday, 10 March 2013
Unix System Calls
UNIX system calls are used to manage the file system, control processes,
and to provide interprocess communication. The UNIX system interface
consists of about 80 system calls (as UNIX evolves this number will
increase). The following table lists about 40 of the more important
system call:
GENERAL CLASS SPECIFIC CLASS SYSTEM CALL
---------------------------------------------------------------------
File Structure Creating a Channel creat()
Related Calls open()
close()
Input/Output read()
write()
Random Access lseek()
Channel Duplication dup()
Aliasing and Removing link()
Files unlink()
File Status stat()
fstat()
Access Control access()
chmod()
chown()
umask()
Device Control ioctl()
---------------------------------------------------------------------
Process Related Process Creation and exec()
Calls Termination fork()
wait()
exit()
Process Owner and Group getuid()
geteuid()
getgid()
getegid()
Process Identity getpid()
getppid()
Process Control signal()
kill()
alarm()
Change Working Directory chdir()
----------------------------------------------------------------------
Interprocess Pipelines pipe()
Communication Messages msgget()
msgsnd()
msgrcv()
msgctl()
Semaphores semget()
semop()
Shared Memory shmget()
shmat()
shmdt()
----------------------------------------------------------------------
[NOTE: The system call interface is that aspect of UNIX that has
changed the most since the inception of the UNIX system. Therefore,
when you write a software tool, you should protect that tool by putting
system calls in other subroutines within your program and then calling
only those subroutines. Should the next version of the UNIX system
change the syntax and semantics of the system calls you've used, you
need only change your interface routines.]
Original Link: http://www.di.uevora.pt/~lmr/syscalls.html
Friday, 1 March 2013
linux_interview_questions
1. How to display the 10th line of a file?
head -10 filename | tail -1
2. How to remove the header from a file? [ -i in sed will update the file ]
sed -i '1 d' filename
3. How to remove the footer from a file? [ $ is for end of the file ]
sed -i '$ d' filename
4. Write a command to find the length of a line in a file?
The below command can be used to get a line from a file.
sed –n '<n> p' filename
We will see how to find the length of 10th line in a file
sed -n '10 p' filename|wc -c
5. How to get the nth word of a line in Unix?
cut –f<n> -d' '
6. How to reverse a string in unix?
echo "java" | rev
7. How to get the last word from a line in Unix file?
echo "unix is good" | rev | cut -f1 -d' ' | rev
8. How to replace the n-th line in a file with a new line in Unix?
sed -i'' '10 d' filename # d stands for delete
sed -i'' '10 i new inserted line' filename # i stands for insert
9. How to check if the last command was successful in Unix?
echo $?
10. Write command to list all the links from a directory?
ls -lrt | grep "^l"
11. How will you find which operating system your system is running on in UNIX?
uname -a
12. Create a read-only file in your home directory?
touch file; chmod 400 file
13. How do you see command line history in UNIX?
The 'history' command can be used to get the list of commands that we are executed.
14. How to display the first 20 lines of a file?
By default, the head command displays the first 10 lines from a file. If we change the option of head, then we can display as many lines as we want.
head -20 filename
An alternative solution is using the sed command
sed '21,$ d' filename
The d option here deletes the lines from 21 to the end of the file
15. Write a command to print the last line of a file?
The tail command can be used to display the last lines from a file.
tail -1 filename
Alternative solutions are:
sed -n '$ p' filename
awk 'END{print $0}' filename
1. How do you rename the files in a directory with _new as suffix?
ls -lrt|grep '^-'| awk '{print "mv "$9" "$9".new"}' | sh
2. Write a command to convert a string from lower case to upper case?
echo "apple" | tr [a-z] [A-Z]
3. Write a command to convert a string to Initcap.
echo apple | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'
4. Write a command to redirect the output of date command to multiple files?
The tee command writes the output to multiple files and also displays the output on the terminal.
date | tee -a file1 file2 file3
5. How do you list the hidden files in current directory?
ls -a | grep '^\.'
6. List out some of the Hot Keys available in bash shell?
Ctrl+l - Clears the Screen.
Ctrl+r - Does a search in previously given commands in shell.
Ctrl+u - Clears the typing before the hotkey.
Ctrl+a - Places cursor at the beginning of the command at shell.
Ctrl+e - Places cursor at the end of the command at shell.
Ctrl+d - Kills the shell.
Ctrl+z - Places the currently running process into background.
7. How do you make an existing file empty?
cat /dev/null > filename
8. How do you remove the first number on 10th line in file?
sed '10 s/[0-9][0-9]*//' < filename
9. What is the difference between join -v and join -a?
join -v : outputs only matched lines between two files.
join -a : In addition to the matched lines, this will output unmatched lines also.
10. How do you display from the 5th character to the end of the line from a file?
cut -c 5- filename
1. Display all the files in current directory sorted by size?
ls -l | grep '^-' | awk '{print $5,$9}' |sort -n|awk '{print $2}'
2. Write a command to search for the file 'map' in the current directory?
find -name map -type f
3. How to display the first 10 characters from each line of a file?
cut -c -10 filename
4. Write a command to remove the first number on all lines that start with "@"?
sed '\,^@, s/[0-9][0-9]*//' < filename
5. How to print the file names in a directory that has the word "term"?
grep -l term *
The '-l' option make the grep command to print only the filename without printing the content of the file. As soon as the grep command finds the pattern in a file, it prints the pattern and stops searching other lines in the file.
6. How to run awk command specified in a file?
awk -f filename
7. How do you display the calendar for the month march in the year 1985?
The cal command can be used to display the current month calendar. You can pass the month and year as arguments to display the required year, month combination calendar.
cal 03 1985
This will display the calendar for the March month and year 1985.
8. Write a command to find the total number of lines in a file?
wc -l filename
Other ways to pring the total number of lines are
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename
awk 'END{print NR}' filename
9. How to duplicate empty lines in a file?
sed '/^$/ p' < filename
10. Explain iostat, vmstat and netstat?
Iostat: reports on terminal, disk and tape I/O activity.
Vmstat: reports on virtual memory statistics for processes, disk, tape and CPU activity.
Netstat: reports on the contents of network data structures.
1. How do you write the contents of 3 files into a single file?
cat file1 file2 file3 > file
2. How to display the fields in a text file in reverse order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "\n"}' filename
3. Write a command to find the sum of bytes (size of file) of all files in a directory.
ls -l | grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'
4. Write a command to print the lines which end with the word "end"?
grep 'end$' filename
The '$' symbol specifies the grep command to search for the pattern at the end of the line.
5. Write a command to select only those lines containing "july" as a whole word?
grep -w july filename
The '-w' option makes the grep command to search for exact whole words. If the specified pattern is found in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern "july" is found. However "july" is not a whole word in that string.
6. How to remove the first 10 lines from a file?
sed '1,10 d' < filename
7. Write a command to duplicate each line in a file?
sed 'p' < filename
8. How to extract the username from 'who am i' comamnd?
who am i | cut -f1 -d' '
9. Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of lines in each file?
wc -l /usr/ch*
Another way is
find /usr -name 'ch*' -type f -exec wc -l {} \;
10. How to remove blank lines in a file ?
grep -v ‘^$’ filename > new_filename
1. How to display the processes that were run by your user name ?
ps -aef | grep <user_name>
2. Write a command to display all the files recursively with path under current directory?
find . -depth -print
3. Display zero byte size files in the current directory?
find -size 0 -type f
4. Write a command to display the third and fifth character from each line of a file?
cut -c 3,5 filename
5. Write a command to print the fields from 10th to the end of the line. The fields in the line are delimited by a comma?
cut -d',' -f10- filename
6. How to replace the word "Gun" with "Pen" in the first 100 lines of a file?
sed '1,00 s/Gun/Pen/' < filename
7. Write a Unix command to display the lines in a file that do not contain the word "RAM"?
grep -v RAM filename
The '-v' option tells the grep to print the lines that do not contain the specified pattern.
8. How to print the squares of numbers from 1 to 10 using awk command
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'
9. Write a command to display the files in the directory by file size?
ls -l | grep '^-' |sort -nr -k 5
10. How to find out the usage of the CPU by the processes?
The top utility can be used to display the CPU usage by the processes.
1. Write a command to remove the prefix of the string ending with '/'.
The basename utility deletes any prefix ending in /. The usage is mentioned below:
basename /usr/local/bin/file
This will display only file
2. How to display zero byte size files?
ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }'
3. How to replace the second occurrence of the word "bat" with "ball" in a file?
sed 's/bat/ball/2' < filename
4. How to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file?
sed 's/jhon//2g' < filename
5. How to replace the word "lite" with "light" from 100th line to last line in a file?
sed '100,$ s/lite/light/' < filename
6. How to list the files that are accessed 5 days ago in the current directory?
find -atime 5 -type f
7. How to list the files that were modified 5 days ago in the current directory?
find -mtime 5 -type f
8. How to list the files whose status is changed 5 days ago in the current directory?
find -ctime 5 -type f
9. How to replace the character '/' with ',' in a file?
sed 's/\//,/' < filename
sed 's|/|,|' < filename
10. Write a command to find the number of files in a directory.
ls -l|grep '^-'|wc -l
1. Write a command to display your name 100 times.
The Yes utility can be used to repeatedly output a line with the specified string or 'y'.
yes <your_name> | head -100
2. Write a command to display the first 10 characters from each line of a file?
cut -c -10 filename
3. The fields in each line are delimited by comma. Write a command to display third field from each line of a file?
cut -d',' -f2 filename
4. Write a command to print the fields from 10 to 20 from each line of a file?
cut -d',' -f10-20 filename
5. Write a command to print the first 5 fields from each line?
cut -d',' -f-5 filename
6. By default the cut command displays the entire line if there is no delimiter in it. Which cut option is used to supress these kind of lines?
The -s option is used to supress the lines that do not contain the delimiter.
7. Write a command to replace the word "bad" with "good" in file?
sed s/bad/good/ < filename
8. Write a command to replace the word "bad" with "good" globally in a file?
sed s/bad/good/g < filename
9. Write a command to replace the word "apple" with "(apple)" in a file?
sed s/apple/(&)/ < filename
10. Write a command to switch the two consecutive words "apple" and "mango" in a file?
sed 's/\(apple\) \(mango\)/\2 \1/' < filename
11. Write a command to display the characters from 10 to 20 from each line of a file?
cut -c 10-20 filename
1. Write a command to print the lines that has the the pattern "july" in all the files in a particular directory?
grep july *
This will print all the lines in all files that contain the word “july” along with the file name. If any of the files contain words like "JULY" or "July", the above command would not print those lines.
2. Write a command to print the lines that has the word "july" in all the files in a directory and also suppress the filename in the output.
grep -h july *
3. Write a command to print the lines that has the word "july" while ignoring the case.
grep -i july *
The option i make the grep command to treat the pattern as case insensitive.
4. When you use a single file as input to the grep command to search for a pattern, it won't print the filename in the output. Now write a grep command to print the filename in the output without using the '-H' option.
grep pattern filename /dev/null
The /dev/null or null device is special file that discards the data written to it. So, the /dev/null is always an empty file.
Another way to print the filename is using the '-H' option. The grep command for this is
grep -H pattern filename
5. Write a command to print the file names in a directory that does not contain the word "july"?
grep -L july *
The '-L' option makes the grep command to print the filenames that do not contain the specified pattern.
6. Write a command to print the line numbers along with the line that has the word "july"?
grep -n july filename
The '-n' option is used to print the line numbers in a file. The line numbers start from 1
7. Write a command to print the lines that starts with the word "start"?
grep '^start' filename
The '^' symbol specifies the grep command to search for the pattern at the start of the line.
8. In the text file, some lines are delimited by colon and some are delimited by space. Write a command to print the third field of each line.
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename
9. Write a command to print the line number before each line?
awk '{print NR, $0}' filename
10. Write a command to print the second and third line of a file without using NR.
awk 'BEGIN {RS="";FS="\n"} {print $2,$3}' filename
11. How to create an alias for the complex command and remove the alias?
The alias utility is used to create the alias for a command. The below command creates alias for ps -aef command.
alias pg='ps -aef'
If you use pg, it will work the same way as ps -aef.
To remove the alias simply use the unalias command as
unalias pg
12. Write a command to display todays date in the format of 'yyyy-mm-dd'?
The date command can be used to display todays date with time
date '+%Y-%m-%d'
head -10 filename | tail -1
2. How to remove the header from a file? [ -i in sed will update the file ]
sed -i '1 d' filename
3. How to remove the footer from a file? [ $ is for end of the file ]
sed -i '$ d' filename
4. Write a command to find the length of a line in a file?
The below command can be used to get a line from a file.
sed –n '<n> p' filename
We will see how to find the length of 10th line in a file
sed -n '10 p' filename|wc -c
5. How to get the nth word of a line in Unix?
cut –f<n> -d' '
6. How to reverse a string in unix?
echo "java" | rev
7. How to get the last word from a line in Unix file?
echo "unix is good" | rev | cut -f1 -d' ' | rev
8. How to replace the n-th line in a file with a new line in Unix?
sed -i'' '10 d' filename # d stands for delete
sed -i'' '10 i new inserted line' filename # i stands for insert
9. How to check if the last command was successful in Unix?
echo $?
10. Write command to list all the links from a directory?
ls -lrt | grep "^l"
11. How will you find which operating system your system is running on in UNIX?
uname -a
12. Create a read-only file in your home directory?
touch file; chmod 400 file
13. How do you see command line history in UNIX?
The 'history' command can be used to get the list of commands that we are executed.
14. How to display the first 20 lines of a file?
By default, the head command displays the first 10 lines from a file. If we change the option of head, then we can display as many lines as we want.
head -20 filename
An alternative solution is using the sed command
sed '21,$ d' filename
The d option here deletes the lines from 21 to the end of the file
15. Write a command to print the last line of a file?
The tail command can be used to display the last lines from a file.
tail -1 filename
Alternative solutions are:
sed -n '$ p' filename
awk 'END{print $0}' filename
1. How do you rename the files in a directory with _new as suffix?
ls -lrt|grep '^-'| awk '{print "mv "$9" "$9".new"}' | sh
2. Write a command to convert a string from lower case to upper case?
echo "apple" | tr [a-z] [A-Z]
3. Write a command to convert a string to Initcap.
echo apple | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'
4. Write a command to redirect the output of date command to multiple files?
The tee command writes the output to multiple files and also displays the output on the terminal.
date | tee -a file1 file2 file3
5. How do you list the hidden files in current directory?
ls -a | grep '^\.'
6. List out some of the Hot Keys available in bash shell?
Ctrl+l - Clears the Screen.
Ctrl+r - Does a search in previously given commands in shell.
Ctrl+u - Clears the typing before the hotkey.
Ctrl+a - Places cursor at the beginning of the command at shell.
Ctrl+e - Places cursor at the end of the command at shell.
Ctrl+d - Kills the shell.
Ctrl+z - Places the currently running process into background.
7. How do you make an existing file empty?
cat /dev/null > filename
8. How do you remove the first number on 10th line in file?
sed '10 s/[0-9][0-9]*//' < filename
9. What is the difference between join -v and join -a?
join -v : outputs only matched lines between two files.
join -a : In addition to the matched lines, this will output unmatched lines also.
10. How do you display from the 5th character to the end of the line from a file?
cut -c 5- filename
1. Display all the files in current directory sorted by size?
ls -l | grep '^-' | awk '{print $5,$9}' |sort -n|awk '{print $2}'
2. Write a command to search for the file 'map' in the current directory?
find -name map -type f
3. How to display the first 10 characters from each line of a file?
cut -c -10 filename
4. Write a command to remove the first number on all lines that start with "@"?
sed '\,^@, s/[0-9][0-9]*//' < filename
5. How to print the file names in a directory that has the word "term"?
grep -l term *
The '-l' option make the grep command to print only the filename without printing the content of the file. As soon as the grep command finds the pattern in a file, it prints the pattern and stops searching other lines in the file.
6. How to run awk command specified in a file?
awk -f filename
7. How do you display the calendar for the month march in the year 1985?
The cal command can be used to display the current month calendar. You can pass the month and year as arguments to display the required year, month combination calendar.
cal 03 1985
This will display the calendar for the March month and year 1985.
8. Write a command to find the total number of lines in a file?
wc -l filename
Other ways to pring the total number of lines are
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename
awk 'END{print NR}' filename
9. How to duplicate empty lines in a file?
sed '/^$/ p' < filename
10. Explain iostat, vmstat and netstat?
Iostat: reports on terminal, disk and tape I/O activity.
Vmstat: reports on virtual memory statistics for processes, disk, tape and CPU activity.
Netstat: reports on the contents of network data structures.
1. How do you write the contents of 3 files into a single file?
cat file1 file2 file3 > file
2. How to display the fields in a text file in reverse order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "\n"}' filename
3. Write a command to find the sum of bytes (size of file) of all files in a directory.
ls -l | grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'
4. Write a command to print the lines which end with the word "end"?
grep 'end$' filename
The '$' symbol specifies the grep command to search for the pattern at the end of the line.
5. Write a command to select only those lines containing "july" as a whole word?
grep -w july filename
The '-w' option makes the grep command to search for exact whole words. If the specified pattern is found in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern "july" is found. However "july" is not a whole word in that string.
6. How to remove the first 10 lines from a file?
sed '1,10 d' < filename
7. Write a command to duplicate each line in a file?
sed 'p' < filename
8. How to extract the username from 'who am i' comamnd?
who am i | cut -f1 -d' '
9. Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of lines in each file?
wc -l /usr/ch*
Another way is
find /usr -name 'ch*' -type f -exec wc -l {} \;
10. How to remove blank lines in a file ?
grep -v ‘^$’ filename > new_filename
1. How to display the processes that were run by your user name ?
ps -aef | grep <user_name>
2. Write a command to display all the files recursively with path under current directory?
find . -depth -print
3. Display zero byte size files in the current directory?
find -size 0 -type f
4. Write a command to display the third and fifth character from each line of a file?
cut -c 3,5 filename
5. Write a command to print the fields from 10th to the end of the line. The fields in the line are delimited by a comma?
cut -d',' -f10- filename
6. How to replace the word "Gun" with "Pen" in the first 100 lines of a file?
sed '1,00 s/Gun/Pen/' < filename
7. Write a Unix command to display the lines in a file that do not contain the word "RAM"?
grep -v RAM filename
The '-v' option tells the grep to print the lines that do not contain the specified pattern.
8. How to print the squares of numbers from 1 to 10 using awk command
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'
9. Write a command to display the files in the directory by file size?
ls -l | grep '^-' |sort -nr -k 5
10. How to find out the usage of the CPU by the processes?
The top utility can be used to display the CPU usage by the processes.
1. Write a command to remove the prefix of the string ending with '/'.
The basename utility deletes any prefix ending in /. The usage is mentioned below:
basename /usr/local/bin/file
This will display only file
2. How to display zero byte size files?
ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }'
3. How to replace the second occurrence of the word "bat" with "ball" in a file?
sed 's/bat/ball/2' < filename
4. How to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file?
sed 's/jhon//2g' < filename
5. How to replace the word "lite" with "light" from 100th line to last line in a file?
sed '100,$ s/lite/light/' < filename
6. How to list the files that are accessed 5 days ago in the current directory?
find -atime 5 -type f
7. How to list the files that were modified 5 days ago in the current directory?
find -mtime 5 -type f
8. How to list the files whose status is changed 5 days ago in the current directory?
find -ctime 5 -type f
9. How to replace the character '/' with ',' in a file?
sed 's/\//,/' < filename
sed 's|/|,|' < filename
10. Write a command to find the number of files in a directory.
ls -l|grep '^-'|wc -l
1. Write a command to display your name 100 times.
The Yes utility can be used to repeatedly output a line with the specified string or 'y'.
yes <your_name> | head -100
2. Write a command to display the first 10 characters from each line of a file?
cut -c -10 filename
3. The fields in each line are delimited by comma. Write a command to display third field from each line of a file?
cut -d',' -f2 filename
4. Write a command to print the fields from 10 to 20 from each line of a file?
cut -d',' -f10-20 filename
5. Write a command to print the first 5 fields from each line?
cut -d',' -f-5 filename
6. By default the cut command displays the entire line if there is no delimiter in it. Which cut option is used to supress these kind of lines?
The -s option is used to supress the lines that do not contain the delimiter.
7. Write a command to replace the word "bad" with "good" in file?
sed s/bad/good/ < filename
8. Write a command to replace the word "bad" with "good" globally in a file?
sed s/bad/good/g < filename
9. Write a command to replace the word "apple" with "(apple)" in a file?
sed s/apple/(&)/ < filename
10. Write a command to switch the two consecutive words "apple" and "mango" in a file?
sed 's/\(apple\) \(mango\)/\2 \1/' < filename
11. Write a command to display the characters from 10 to 20 from each line of a file?
cut -c 10-20 filename
1. Write a command to print the lines that has the the pattern "july" in all the files in a particular directory?
grep july *
This will print all the lines in all files that contain the word “july” along with the file name. If any of the files contain words like "JULY" or "July", the above command would not print those lines.
2. Write a command to print the lines that has the word "july" in all the files in a directory and also suppress the filename in the output.
grep -h july *
3. Write a command to print the lines that has the word "july" while ignoring the case.
grep -i july *
The option i make the grep command to treat the pattern as case insensitive.
4. When you use a single file as input to the grep command to search for a pattern, it won't print the filename in the output. Now write a grep command to print the filename in the output without using the '-H' option.
grep pattern filename /dev/null
The /dev/null or null device is special file that discards the data written to it. So, the /dev/null is always an empty file.
Another way to print the filename is using the '-H' option. The grep command for this is
grep -H pattern filename
5. Write a command to print the file names in a directory that does not contain the word "july"?
grep -L july *
The '-L' option makes the grep command to print the filenames that do not contain the specified pattern.
6. Write a command to print the line numbers along with the line that has the word "july"?
grep -n july filename
The '-n' option is used to print the line numbers in a file. The line numbers start from 1
7. Write a command to print the lines that starts with the word "start"?
grep '^start' filename
The '^' symbol specifies the grep command to search for the pattern at the start of the line.
8. In the text file, some lines are delimited by colon and some are delimited by space. Write a command to print the third field of each line.
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename
9. Write a command to print the line number before each line?
awk '{print NR, $0}' filename
10. Write a command to print the second and third line of a file without using NR.
awk 'BEGIN {RS="";FS="\n"} {print $2,$3}' filename
11. How to create an alias for the complex command and remove the alias?
The alias utility is used to create the alias for a command. The below command creates alias for ps -aef command.
alias pg='ps -aef'
If you use pg, it will work the same way as ps -aef.
To remove the alias simply use the unalias command as
unalias pg
12. Write a command to display todays date in the format of 'yyyy-mm-dd'?
The date command can be used to display todays date with time
date '+%Y-%m-%d'
Subscribe to:
Posts (Atom)