12-11-2009
Searching for file names in a directory while ignoring certain file names
Sun Solaris Unix Question
Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain extensions. For example :
Files in directory
----------------
testfile1.txt
testfile2.txt
testfile3.txt
testfile4.txt
testfile1.exe
testfile2.exe
testfile3.exe
testfile4.exe
I have a find command like :
find . -name '*' -print > filelist.lst
This would obviously give me all of the file names listed above in the file called filelist.lst.
However, what command syntax would I use if I wanted to ignore *.exe files. So, in the end this find command should generate a file called filelist.lst which should contain only the names of the files that end in .txt.
I tried the -not command but that is not valid in my version of Sun Solaris. (i.e. find . -name "*' -not \( -name "*.exe" \) -print > filelist.lst )
---------- Post updated at 03:09 PM ---------- Previous update was at 02:57 PM ----------
Disregard. I finally found the answer.
find . -name '*' ! -name '*.exe' -print > filelist.lst
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
If I have a directory full of say 100 random files, and I would like to organize them, for example: FILE001, FILE002, FILE003, FILE004, etc.
How would I do this from Terminal, instead of manually changing each file? I'm using Mac OS X, if that makes a difference.
Thank you in advance... (8 Replies)
Discussion started by: andou
8 Replies
2. AIX
Hi,
I am trying to find the content of file using grep and find command and list only the file names
but i am getting entire file list of files in the directory
find . -exec grep "test" {} \; -ls
Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies
3. UNIX for Dummies Questions & Answers
Hi ,
I have a list of files in the directory I want to sort based on the file name.
But in the middle of filename contains the number based on that I need to sort.Could you suggest me on the same?
Example filenames:
/user1$ls
RS.DEV.ISV.F1.RS.REFDATA.DATA... (1 Reply)
Discussion started by: praveen.thumati
1 Replies
4. Shell Programming and Scripting
I am having n files in a directory i want to read all the file names from the script file .It is better if any one provide a sample script.
Elaborating the scenario:
i am having n number of sql files in a directory i am running all the sql files from a single script.
sqlplus... (4 Replies)
Discussion started by: dineshmurs
4 Replies
5. UNIX for Dummies Questions & Answers
I am interested in writing a really simple alias to search for duplicates in file names in a given directory.
As an example, the file names follow a convention like:
TGIFRIDAY_55566_RESTAURANT
TGIFRIDAY_98744_RESTAURANT
TGIFRIDAY_67778_RESTAURANT
TGIFRIDAY_55566_RESTAURANT
These are all... (8 Replies)
Discussion started by: Tennesseej
8 Replies
6. Shell Programming and Scripting
got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies
7. Shell Programming and Scripting
Hello everyone
We have a problem about searching and copying files with variables.
we have variables like $year $jday $date and we want to search the files whose name contain these variables.
we tried *$year*$jday*$date or with ? instead of *
thank you everyone!!! (4 Replies)
Discussion started by: miriammiriam
4 Replies
8. Shell Programming and Scripting
Dears,
Would you please help on following bash script:
I want to get the most recent file named alfaYYYYMMDD.gz in one directory:
for example:
in directory /tmp/
ls -ltr
alfa20130715.gz
holding.gz
alfa20130705.gz
sart.txt
merge.txt.gz
alfa20130802.gz
my result shoud be... (1 Reply)
Discussion started by: maxsub
1 Replies
9. Shell Programming and Scripting
Data files coming in different names in a file name called process.txt.
1. shipments_yyyymmdd.gz
2 Order_yyyymmdd.gz
3. Invoice_yyyymmdd.gz
4. globalorder_yyyymmdd.gz
The process needs to discard all the below files and only process two of the 4 file names available
... (1 Reply)
Discussion started by: dsravanam
1 Replies
10. UNIX for Beginners Questions & Answers
Hi, I have about 60 files in a directory and need to rename those files. For example the file names are
i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc)
i_usa_phone_1_yymmdd.txt
i_eng_phone_4_yymmdd.txt
The new file names should be
phone.txt
phone_1.txt
phone_4.txt
I am... (4 Replies)
Discussion started by: naveed
4 Replies
LEARN ABOUT SUSE
file::dosglob
File::DosGlob(3pm) Perl Programmers Reference Guide File::DosGlob(3pm)
NAME
File::DosGlob - DOS like globbing and then some
SYNOPSIS
require 5.004;
# override CORE::glob in current package
use File::DosGlob 'glob';
# override CORE::glob in ALL packages (use with extreme caution!)
use File::DosGlob 'GLOBAL_glob';
@perlfiles = glob "..\pe?l/*.p?";
print <..\pe?l/*.p?>;
# from the command line (overrides only in main::)
> perl -MFile::DosGlob=glob -e "print <../pe*/*p?>"
DESCRIPTION
A module that implements DOS-like globbing with a few enhancements. It is largely compatible with perlglob.exe (the M$ setargv.obj
version) in all but one respect--it understands wildcards in directory components.
For example, "<..\l*b\file/*glob.p?"> will work as expected (in that it will find something like '..libFile/DosGlob.pm' alright). Note
that all path components are case-insensitive, and that backslashes and forward slashes are both accepted, and preserved. You may have to
double the backslashes if you are putting them in literally, due to double-quotish parsing of the pattern by perl.
Spaces in the argument delimit distinct patterns, so "glob('*.exe *.dll')" globs all filenames that end in ".exe" or ".dll". If you want
to put in literal spaces in the glob pattern, you can escape them with either double quotes, or backslashes. e.g. "glob('c:/"Program
Files"/*/*.dll')", or "glob('c:/Program Files/*/*.dll')". The argument is tokenized using "Text::ParseWords::parse_line()", so see
Text::ParseWords for details of the quoting rules used.
Extending it to csh patterns is left as an exercise to the reader.
NOTES
o Mac OS (Classic) users should note a few differences. The specification of pathnames in glob patterns adheres to the usual Mac OS
conventions: The path separator is a colon ':', not a slash '/' or backslash ''. A full path always begins with a volume name. A
relative pathname on Mac OS must always begin with a ':', except when specifying a file or directory name in the current working
directory, where the leading colon is optional. If specifying a volume name only, a trailing ':' is required. Due to these rules, a
glob like <*:> will find all mounted volumes, while a glob like <*> or <:*> will find all files and directories in the current
directory.
Note that updirs in the glob pattern are resolved before the matching begins, i.e. a pattern like "*HD:t?p::a*" will be matched as
"*HD:a*". Note also, that a single trailing ':' in the pattern is ignored (unless it's a volume name pattern like "*HD:"), i.e. a glob
like <:*:> will find both directories and files (and not, as one might expect, only directories).
The metachars '*', '?' and the escape char '' are valid characters in volume, directory and file names on Mac OS. Hence, if you want
to match a '*', '?' or '' literally, you have to escape these characters. Due to perl's quoting rules, things may get a bit
complicated, when you want to match a string like '*' literally, or when you want to match '' literally, but treat the immediately
following character '*' as metachar. So, here's a rule of thumb (applies to both single- and double-quoted strings): escape each '*' or
'?' or '' with a backslash, if you want to treat them literally, and then double each backslash and your are done. E.g.
- Match '*' literally
escape both '' and '*' : '\*'
double the backslashes : '\\\*'
(Internally, the glob routine sees a '\*', which means that both '' and '*' are escaped.)
- Match '' literally, treat '*' as metachar
escape '' but not '*' : '\*'
double the backslashes : '\\*'
(Internally, the glob routine sees a '\*', which means that '' is escaped and '*' is not.)
Note that you also have to quote literal spaces in the glob pattern, as described above.
EXPORTS (by request only)
glob()
BUGS
Should probably be built into the core, and needs to stop pandering to DOS habits. Needs a dose of optimizium too.
AUTHOR
Gurusamy Sarathy <gsar@activestate.com>
HISTORY
o Support for globally overriding glob() (GSAR 3-JUN-98)
o Scalar context, independent iterator context fixes (GSAR 15-SEP-97)
o A few dir-vs-file optimizations result in glob importation being 10 times faster than using perlglob.exe, and using perlglob.bat is
only twice as slow as perlglob.exe (GSAR 28-MAY-97)
o Several cleanups prompted by lack of compatible perlglob.exe under Borland (GSAR 27-MAY-97)
o Initial version (GSAR 20-FEB-97)
SEE ALSO
perl
perlglob.bat
Text::ParseWords
perl v5.12.1 2010-04-26 File::DosGlob(3pm)