Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   ls question (http://www.programmingforums.org/showthread.php?t=12533)

cwl157 Feb 8th, 2007 11:50 AM

ls question
 
Does anyone know how to write the command for listing all files in a folder except the file tt using ls and meta characters? I have tried ls [^tt]* but this lists all files in the sub directories also and I don't want that i just want all the files in the current directory.
Thanks

Arevos Feb 8th, 2007 12:12 PM

"ls -d" will display directories without displaying their contents. However, I don't think globs support "not" clauses like "^tt". Perhaps you should pipe the output through a more sophisticated filter, like grep?

Infinite Recursion Feb 9th, 2007 8:56 AM

If this isn't some sort of an metacharacter assignment, you could always do this:

ls | grep -v tt

Also, ls [^tt]* works in /bin/bash.

jim mcnamara Feb 9th, 2007 3:44 PM

In ksh and bash you can use a limited form of regex called pattern-matching

ls *.c lists all of the file that have a . followed by the letter c
ls *.[!c] lists all of the files that have a do and do not end in c

the [c] thing is a class of characters. The [!c] means not this class of characters. You can also do
ls *.[Oo] This lists files that end in O or o.

This is all part of globbing in shell.


All times are GMT -5. The time now is 10:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC