Solved

C Shel script that search your home directory and re-organize

Posted on 2000-04-07
3
216 Views
Last Modified: 2010-04-21
How do you write a C Shell script that will search your home directory and re-organize it as follows:
1.  Place.java files in java directory.
2.  Place.class files in class directory.
3.  Place.cpp files in cplus2 directory.
4.  Place executables in execute directory.
5.  Place .txt  files in text directory.
6.  Place other files in others directory.

Your home directory should only contain these directories.  A file should be created with lines containing directoryname and number_of_files_per_ directory.  This file should be sorted by directory name.

Make sure that every .java file has its equivalent  .class file.

A statement of the UNIX name and version used.
0
Comment
Question by:colekl
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
tfewster earned 40 total points
Comment Utility
What qualification will I get if I complete this course for you?

Anyway, here's a rough top-down design, that you can complete & debug - Probably not up to classwork standards, but the principle will work if this is a genuine problem.

#!/usr/bin/csh
#(Path will depend on the Unix variant)

cd ~
 .
#Move files
foreach f in ( #list of .java files)
do
  #Move $f to java directory
done
 .
#etcetera
 .
# check .class files
foreach f in ( #list java directory )
do
  #strip off the extension (sed? awk?)
  #so f2 is the "main" filename
  if # test if class/$f2.class exists
  then
    # It exists, we're OK
  else
    # .class is missing;
    # What should we do?
  endif
done

#count the files in the subdirectories,
#now there's nothing left in the home #dir

for d in ( # list of directories )
# which gives us the sorted list :)
do
  echo $d >> /tmp/count
  #count the files in $d >> /tmp/count
done

0
 

Author Comment

by:colekl
Comment Utility
tfewster, I like your humor!
Thank you.
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
Thank you - I feel guilty now, in case this WAS a course assignment (especially if you get a lousy grade for it).

One more "generic" tip anyway: Consider using "ls -1 ..." to generate the lists the "foreach" statements are using.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now