UNIX commands and scripts

Hi guys,

Hoping someone can help with the below - involves basic commands and some scripting. Thanks so much in advance for your amazing time and help.

  1. The file / etc/profile contains the default initialization options for your shell.
    Produce a unique list of all variables with uppercase names that have been set
    in /etc/profile sorted in alphabetical order.

the output should be something like:

EUID
HISTCONTROL
HISTSIZE
HOSTNAME
LOGNAME
MAIL
PATH
UID
USER
  1. The file /etc/passwd contains lines that look like this:
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin

The field delimiter is : and the fields are:

username:password:userid:groupid:realname:homedirectory:shell

Come up with a UNIX command that will find and print out the home directory of
the user whose username is 'root'.

  1. Come up with a UNIX command that will print a sorted, unique list of all of
    the different shells used by the different users in /etc/passwd .

  2. Come up with a UNIX command that will print a list of usernames from /etc/passwd
    that end with a vowel.

  3. The ' env' command prints out all of the environment variables and their values.
    Come up with a command that prints a list of environment variables whose names
    end with either 'NAME', 'DIR' or 'PATH'.

  4. Write a script called ' home.sh ' which takes a username as its argument and
    will print out the home directory of that user as follows:

$ ./home.sh root
root's home directory is /root
$ ./home.sh nobody
nobody's home directory is /

If the command is used incorrectly, print a usage error to stderr:

$ ./home.sh
Usage: ./home.sh username
  1. Write a script called big which takes a filepath as an argument. The script
    should print "Big" if the file is more than 1000 bytes or "Small" if the file
    is less than 1000 bytes. If exactly one argument was not given, print "Error"
    to stderr.

  2. Using the metric system, where 1 kilobyte = 1000 bytes, write a script that
    takes a filename as an argument and prints out the file size in kilobytes by
    dividing the number of bytes by 1000.

Kindly do not post classroom or homework type of problems in the main forums.

Homework and coursework-related questions should only be posted in this forum using a special homework template.

Discussed with the new member in Live Chat.

Thank You.

The UNIX and Linux Forums.

REF: Here is a part of the Live Chat on this with the new member:

2 Likes