Solved

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

Posted on 2000-04-07
3
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 40 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
llcommand 6 111
Unix Question 19 56
Access_log 17 183
grep command usage 10 34
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

752 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