Skip to content

Instantly share code, notes, and snippets.

@ynonp
Last active August 29, 2015 14:20
Show Gist options
  • Save ynonp/352418e430cc3537150a to your computer and use it in GitHub Desktop.
Save ynonp/352418e430cc3537150a to your computer and use it in GitHub Desktop.

Unix Scripting Lab

Part 1: Getting Parameters

  1. Take a directory name and a file name. Create the directory and then create the file inside.
  2. Take a user name and print all processes from that user
  3. Write a shell script that reads a file name from the user, prints its contents and the number of lines in the file.

Part 2: Conditionals

  1. Write a shell script that asks the user for a number, if the user chooses 7 - print "You Win".
  2. Write a shell script that takes two file names, and prints the contents of the larger one.
  3. Write a shell script that reads a file name from the user, checks that the file is valid, and lowecases its name. For example, running lc MyFile should rename the file MyFile to myfile (Hint: use tr).

Part 3: Loops

  1. Write a shell script that takes a file name and prints the file double spaced

  2. Write a shell script that takes a file name and prints only even lines

  3. The command "unzip" extracts contents of a zip file. Write a shell script that unzips all zip files in a directory

  4. write a shell script that takes several file names as inputs, and copies itself to each of the files. Also change permissions of target files to executables.

  5. Write a shell script that counts the number of files in each directory and print each directory name and its file count Sample output:

     dir = ., files = 12
     dir = ./a b, files = 0
     dir = ./bar, files = 0
     dir = ./foo, files = 2
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment