Write a command that will output the sorted contents of a file named IN.TXT and place the output in another file named OUT.TXT, while at the same time excluding duplicate entries.
Answer:
sort IN.TXT | uniq > OUT.TXT
44) Write a command that will allow a UNIX system to shut down in 15 minutes, after which it will perform a reboot.
Answer:
/sbin/shutdown –r +15
45) What command will change your prompt to MYPROMPT?
To change a prompt, we use the PS1 command, such as this:
PS1 = 'MYPROMPT:'
46) What does this command do? cat food 1 > kitty
Answer: it redirects the output of cat food into the file kitty; the command is the same as:cat food > kitty
47) What is wrong with this interactive shell script?
echo What month is this?read $monthecho $month is as good a month as any.
Answer: Initially, the question mark should be escaped (\?) so that it is not interpreted as a shell metacharacter. Second, it should be read month, not read $month.
48) Write a shell script that requests the user's age and then echoes it, along with some suitable comment.
Answer:
echo Hello! What\'s your age\?
read age
echo $age! I\'ll be obsolete by that age!
49) Write a script that prints out date information in this order: time, the day of week, day number, month, year(sample output: 17:34:51 PDT Sun 12 Feb 2012)
Answer:
set 'date'
echo $4 $5 $1 $3 $2 $6
50) Write a script that will show the following as output:
Give me a U!
U!
Give ma a N!
N!
Give me a I!
I!
Give me a X!
X!
Answer:for i in U N I Xdo
echo Give me a $i!
echo $i!
done