Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux : adding the new user with password option, 11 107
LINUX ZIP - UNCOMPRESS WINDOWS PATH 3 100
awk sed 8 43
remove one line from a file in solaris 8 29
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

810 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