Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2000-04-07
3
Medium Priority
?
272 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 21

Accepted Solution

by:
tfewster earned 160 total points
ID: 2694582
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
ID: 2694797
tfewster, I like your humor!
Thank you.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2694875
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:
Suggested Courses
Course of the Month7 days, 2 hours left to enroll

783 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