Listing folders that have a file inside them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing folders that have a file inside them
# 1  
Old 09-14-2012
Listing folders that have a file inside them

Hi guys,

I'm new to the forums and putting my foot in the door with SED and AWK. I was wondering if someone could help me as I think I'm making this harder than it needs to be...

I have a list of folders named as urls, inside these are log files and possibly a 'status' file. I'm trying to get a list of folders that do not have the file called 'status'.

So if the folder url2 has status the list would be:
url1
url3

The current command I'm using is:
Code:
ls -R | grep -v "****-**-**.log.*" | sed -n '/.\/www.*.*/,+1p'

At the moment this is giving me the following:
./url1

./url2
status

./url3

Any help would be much appreciated, only I only used the grep -v command because I was spending so much time on the regex haha.
# 2  
Old 09-14-2012
directly from the system
Code:
find /path/to/dirs -type d |
while read dir
do
  ls ${dir}/status >/dev/null 2&>1 || echo $dir
done

I think I have what you want.

Or from a file with directory names.
Code:
while read dir
do
  ls ${dir}/status >/dev/null 2&>1 || echo $dir 
done < list_of_directories.txt

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 09-14-2012
Ok so I ran your command on the home directory and it's getting very close to what I need.

This is the output I get, but it seems it is still showing the url2 directory which has the status file inside:

/home
/home/url1
/home/url2
/home/url3
# 4  
Old 09-14-2012
Try something like this:

Code:
find .|grep www|nawk -F/ '/status$/{a[$2]=1};{b[$2]=1};END{for(i in b){if(a[i]!=1){print i}}}'

You have to be in the directory where the url-directories are to run this command though
This User Gave Thanks to Subbeh For This Post:
# 5  
Old 09-14-2012
I had to install nawk, but that worked perfectly, thank you!
Also thank you to Jim for your help.
# 6  
Old 09-14-2012
Quote:
Originally Posted by KakersUK
I had to install nawk, but that worked perfectly, thank you!
Also thank you to Jim for your help.
You can just use awk as well the same way.
# 7  
Old 09-14-2012
So you can... Awesome Smilie Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Uncompress several tar.gz files inside several folders

Hi, I need to uncompress sevral tar.gz files that are located insides sevral folders using a shell script. Folder tree looks like this : /folder/001 /folder/002 /folder/003 Inside each folder dossier (001,002,003) we can find 1 or several tar.gz files. I've scripted something... (9 Replies)
Discussion started by: shellX
9 Replies

2. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

3. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

4. Shell Programming and Scripting

Editing all files inside folders and updating pos 88-94 with continuous numbering.

Here is expected output:- For each file with following file name pattern we need to look at position 1 inside first file matching our search criteria if first letter of the line is 5 then position 88-94 will be 0000001 then look for line immediately after 5 which starts with i.e. position 1 = 8... (6 Replies)
Discussion started by: lancesunny
6 Replies

5. UNIX for Dummies Questions & Answers

Listing folders and files within

is there any command that can make listing files like this /data/seismic/prestack-4/eon5/PEP/JAWA/AKASIA-BAGUS/3D/F/BL3-4/F12AKB3D_SW82-128_ID1696-1850.segy /data/seismic/prestack-4/eon5/PEP/JAWA/AKASIA-BAGUS/3D/F/BL3-4/F12AKB3D_SW82-128_ID1851-1975.segy ... (2 Replies)
Discussion started by: muhnandap
2 Replies

6. Shell Programming and Scripting

Need help in listing directories inside korn shell script

Hi All, I need to loop through each item in current path, if it is a direcotry do soemthing, if its a file jsut skip it and move to next item in loop. Tried if test ! -d $i then echo "The current item $i is not a directory" continue fi This doesnt seems to be working .... (8 Replies)
Discussion started by: justchill
8 Replies

7. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

8. Shell Programming and Scripting

listing folders and using in script

im a bit new to this and have been playing quite a bit and cant figure it out :( I have made a basic script: cd /folder/software1/bin/; echo "software1," >> /in/local/var/trace/davescripts/software.txt "\c"; ls -tm >> /in/local/var/trace/davescripts/software.txt; and this basically... (1 Reply)
Discussion started by: truCido
1 Replies

9. Filesystems, Disks and Memory

Sun UNIX Files & Folders listing

Hi guys, i'm new to UNIX and only know a small amout about it, but have just had some changes at work which now require me to interact with and work on SUN Unix systems often. I have reasonable knowledge of PC's but hope that you will be able to help me with these questions. Part1. I would like... (3 Replies)
Discussion started by: Scrat
3 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