Solved

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

Posted on 2000-04-07
3
229 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
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 20

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
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 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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now