Bourne shell viewing files in directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bourne shell viewing files in directory
# 8  
Old 05-14-2009
Hi,
Thanks for the reply. I will try it now.

Thank you.
# 9  
Old 05-14-2009
Hi,
The solution is not working. Anyone can help me?

The scenario should be like this. Eg:

The user enter: prog test #test is a directory name in $HOME

In the prog shell script, the first thing it does is count the number of files in that directory. Then, it will list the time of each files and and me whether do I want to copy that file.

Sample output:

-rwxr-xr-x 1 kay test 373 May 5 18:43 max-min
-rw-r--r-- 1 kay test 157 May 5 18:20 reverse
-rwxr-xr-x 1 kay test 145 May 5 18:25 reverse1
-rwxr-xr-x 1 kay test 286 May 5 18:25 reverse2
-rwxr-xr-x 1 kay test 56 May 5 18:25 reverse3
-rwxr-xr-x 1 kay test 324 May 5 18:29 sum-ave

Then it should be like this [filename time: Do you want to copy the file?] :-
max-min 18:43: Do you want to copy this file?[y/n]
y

reverse 18:20: Do you want to copy this file?[y/n]
n
....
...
...(until all the files were scanned in that folder.)

Somehow, with those codes stated, the output is:
max-min 18:43 reverse 18:20 reverse1 18:25 reverse2 18:25 reverse3 18:25 sum-ave 18:29 : Do you want to copy the file?[y/n]

Do anyone know how to make it one by one? Any help would be much appreciated.

Thank you.
# 10  
Old 05-14-2009
Something to start with:

Code:
for i in $dir
do
  file=`ls -l "$i" | awk '{print $9, $8}'`
  printf "$file" Do you want to copy this file?[y/n] "
  read answer
  if [ "$answer" = "y" ]
  then
    cp ......
  fi
done

# 11  
Old 05-14-2009
Thanks Franklin. This helps a lot.
Thank you so much for the help. ^^
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies

2. UNIX for Dummies Questions & Answers

Viewing file size in current directory

What is the command line for viewing the sizes(lines and bytes)of all the files in your present working directory? Is it >ls -la (2 Replies)
Discussion started by: Payton2704
2 Replies

3. Tips and Tutorials

Viewing changes in directory

Hi, I have a directory, and there is a job running and constantly writes and removes files from and to this directory. I would like to see somehow these changes without pressing `ls` every second. Kind of `tail -f` command, but for a directory list and not for file content. I thought maybe kind... (5 Replies)
Discussion started by: ilya_dv
5 Replies

4. Shell Programming and Scripting

List files in the current directory - BOURNE SHELL

i am trying to write a program, that will list .txt files and .png files. it will ask the user what type of files do they want to list! so if the user inputs txt files.. how would you list all the .txt files in the current directory (the directory the program is running)!! thanks (1 Reply)
Discussion started by: bshell_1214
1 Replies

5. UNIX for Advanced & Expert Users

HP-UX: Problem viewing directory with BDF...

Hi all, When I use BDF command on this particular server, it outputs mostly normal stuff. However, there is one directory it can't read at all. Also, it doesn't seem to exist. When I BDF my file system with a small panic script (it happens even if you use just the bdf command): As you... (17 Replies)
Discussion started by: zixzix01
17 Replies

6. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

7. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

8. UNIX for Dummies Questions & Answers

Viewing Directory Content as You Navigate Directories in UNIX

Hi, Can someone help me figure out how to view directory content while I navigate directories (without having to go to the actual directory and "ls-ing" it)? Is there some keyboard shortcut for this? For instance, it would be useful if I could see the content of a directory when I'm copying... (2 Replies)
Discussion started by: shelata
2 Replies

9. UNIX for Dummies Questions & Answers

Viewing files

I have a file (called CORE) that is a dump created by a crashing process. This file, I believe, is in "binary" form, so when I try to use cat, more, or vi on it, it has a bunch of garbage. Is there anything I can use to "read" or view this file just like I might a non-binary file? I am running... (2 Replies)
Discussion started by: dsimpg1
2 Replies

10. UNIX for Dummies Questions & Answers

Viewing files in a directory?

How do I view files in a directory? (1 Reply)
Discussion started by: Ania
1 Replies
Login or Register to Ask a Question