Listing files script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing files script
# 15  
Old 11-07-2010
Quote:
Originally Posted by DGPickett
The parentheses mean the cd moves a subshell but not the parent shell. If you
Code:
cd dir1; cd dir2

with relative paths, you are not in dir2, you are in dir1/dir2 -- you are digging down an imaginary tree. Even with absolute paths, for repeatability, it is nice not to move from the starting $PWD. If you
Code:
(cd dir1 ) ;( cd dir2)

, you have not moved.

so from this

Code:
for file in $(ls -a $2)
   do
        if [ ! -e  $1/$file ]
            then
            cd $2
         ls -ld $file
        fi

I have to get into my $PWD then cd in $2? If so how would the new code look or it would have to be completely different from what I have now.
# 16  
Old 11-07-2010
Put the cd and ls in (). cd changes your working directory, $(pwd) = $PWD, the base of all relative paths.
This User Gave Thanks to DGPickett For This Post:
# 17  
Old 11-07-2010
so like this?

Code:
for file in $(ls -a $2)
   do
        if [ ! -e  $1/$file ]
            then
            (cd $2)
         (ls -ld $file)
        fi
   done

if so now it says this:
Code:
ls: cannot access file2: No such file or directory
ls: cannot access .hidden.file: No such file or directory
ls: cannot access phones: No such file or directory
ls: cannot access prog2.c: No such file or directory
ls: cannot access test2.dir: No such file or directory

these are the right files it just cant access them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

2. Shell Programming and Scripting

Request for shell script for listing directories, subdirs containing specific files.

I'm looking for a script which outputs the list of directories and sub directories from root level consisting of specific files. For instance I want shell script to list all the directories and subdirectories containing .txt files.:wall: (4 Replies)
Discussion started by: super210
4 Replies

3. UNIX for Dummies Questions & Answers

Need help with listing files

Hi, I came up with this question in one of the exercises . Use find to produce a long ls listing of all files in /usr/bin that are more than 750Kb long. You’ll need to use a form like find ..... -exec ls -l {} \; The semicolon must be escaped, but not the . I tried using below code ,... (1 Reply)
Discussion started by: krthknaidu
1 Replies

4. Shell Programming and Scripting

Listing the files

Hi, I have to list the files in a particular folder which are having file names like below: 1000_aa.csv, 1000_ab.csv, 1000_az.csv,1000_ba.csv,1000_bb.csv,1000_ca.csv,1000_cb.csv. How can i get the list? Thanks, Selva (2 Replies)
Discussion started by: bharathappriyan
2 Replies

5. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

6. UNIX for Dummies Questions & Answers

Listing files

Hi there! I would like to list all the files from a directory and its subdirectories. For example: DIRECTORY |- SUBDIR1 ||- sub1.txt ||- sub2.txt |- SUBDIR2 ||- sub3.txt |- root1.txt |- root2.txt I would like to create a fulllist.txt file which contains the list of these files (with... (2 Replies)
Discussion started by: bobix
2 Replies

7. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

8. Shell Programming and Scripting

script needed for listing files

hi, i have a the direcories like usr\clone1\heap001.txt usr\clone2\heap334.txt usr\clone3\heap8899.txt i nead a command which list all the file starting with heap*.i have to execute the command from usr directory. find command is hanging, i need some other form of script to do ... (2 Replies)
Discussion started by: jayaramanit
2 Replies

9. Shell Programming and Scripting

script for listing files of today's time stamp

Hi, I need to write a script,which behaves like this, Given the folder name, it should list the files with today's timestamp. Please direct me on this. Thanks. (2 Replies)
Discussion started by: kid123
2 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question