Linux commands/Shell Scripting Questions

How do you change the name of a file in Unix?

mv filename1 filename2

In UNIX, how do you display the lines that contain the string
"smith" in the file "names.txt"?

grep smith names.txt

In UNIX, how do you display the list of processes that belong to the
user "johns"?

ps -acefl | grep johns

In UNIX/Linux, the command ``ls | grep ercal > grep ''
does the following:

Stores those lines in the file listing of the current
directory which contains the string ``ercal'' into a file called
``grep''.

What happens when you put '&' at the end of a command line in Linux?
Explain this in terms of the shell's behavior.

The shell executes the Linux command in the background

When a process resumes execution after returning from a fork(), how can it
tell if it is the original process or the new one?

By the process ID which is returned by the fork() call. If it is equal
to 0, it is the new one (child process); if it is a non-zero positive
value, it is the original process.

Write the name of the system call for obtaining the process id
of a process in UNIX?

getpid()

Write the name of the system call for obtaining the process id
of a process' parent in UNIX?

getppid()

What does #! signify in a shell script?

It's a special notation which tells the shell, "After this mark, read the name of the script interpreter i want to use.

What does # signify in a shell script?

A comment

Write a command which lists the processes that are owned by or contain the word foo in their name.

ps -ef | grep foo

Create a variable named bar which stores the output of the 'users' command.

bar=$(users)

I've got a variable named flibble which contains the string 'tom Jerry harry'. write a command which stores just 'tom' into a new variable.

new=$(echo $flibble | cut -f1 -d' ')

Determine the output for these commands:
variable="Dennis"
echo '$variable'

$variable

Determine the output for these commands:
variable="Dennis"
echo "$variable

Dennis

Write an if statement which compares $variable to the integer 5 to see if it is equal

if [ $variable -eq 5 ]

Write a shell statement which first adds the numbers 5 and 7 and stores the result in $sum

sum=$(echo '5 + 7' | bc)

Write a shell statement which divide 3 / 2 and stores the answer in $average

average=$(echo '3 / 2' | bc)

Declare a string variable named oldguy which contains 'Dennis Ritchie' in the shell.

oldguy='Dennis Ritchie'

What does the command du do?

figures out disk usage (size of a directory)

Write the command which throws output and errors away while running the script foo.sh.

foo.sh >& /dev/null

Write a command which reads from the keyboard and stores it in the variable kbinput

read kbinput

Write a loop which reads the file 'foobar' into the variable 'lineIN' one line at a time

cat foobar | while read lineIN
do
...
done

Suppose i have a file which has a bunch of data separated by tabs. name a program that could return just one column

cut or awk

whats wrong with this command: PATH='cellardoor'

$PATH is a reserved system variable

if i issue the command "someprogram.sh textfile" how do i access 'textfile' as a variable ?

$1

What are the 3 possible dispositions that a process may specify with
respect to a signal (interrupt)?

1) ignore signal;
2) run the default signal handler provided by the OS;
3) catch the signal and run the user's signal handler.

True or False?
Different threads within a process may specify different
dispositions for a specific interrupt

True.

True or False?
If a running program chooses to ignore interrupts sent via keybord (e.g. Cntl-C), it can do so.

True

What function is used from within a process to send a signal to a process?

kill()