Visit Our UNIX and Linux User Community


List all files except *.txt in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List all files except *.txt in a directory
# 1  
Old 09-27-2009
List all files except *.txt in a directory

I have many types of files (Eg: *.log, *.rpt, *.txt, *.dat) in a directory. I want to display all file types except *.txt.

What is the command to display all files except "*.txt"
# 2  
Old 09-27-2009
Code:
 find -not -iname "*.txt"

# 3  
Old 09-27-2009
I want the listing only from current directory not from its child ddirectories. find willl list out all the files from current as well as child directories

ls -lrt |grep -v '.txt' will give me the desired result. however i want to know is there any direct option in ls command available
# 4  
Old 09-27-2009
you can use the maxdepth option to find to limit result to current directory:

Code:
find -not -iname "*.txt" -maxdepth 1

# 5  
Old 09-27-2009
The shell (bash and ksh) pattern would be:
Code:
!(*.txt)

All the solutions so far include sub-directories. To list only files, and one more condition to varontron's find:

Code:
find -not -iname "*.txt" -maxdepth 1 -type f


Last edited by binlib; 09-27-2009 at 02:18 PM..
# 6  
Old 09-28-2009
find + xargs

find / -type f ! -name "*.txt" | xargs ls -lrt
# 7  
Old 09-28-2009
Quote:
Originally Posted by binlib
The shell (bash and ksh) pattern would be:
Code:
!(*.txt)

Cool, I never thought of that...

So

Code:
ls -F1 !(*.txt)|grep '\b$'

would work too I guess

- edit - should be :

Code:
ls -dF1 !(*.txt)|grep '\b$'


Last edited by Scrutinizer; 09-28-2009 at 06:26 PM..
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #31
Difficulty: Easy
Alan Turing was the founder of IBM.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can i add each line from a txt file to different files in the same directory?

Hello, this is my first thread here :) So i have a text file that contains words in each line like abcd efgh ijkl mnop and i have 4 txt files, i want to add each line to each file, like file 1 gets abcd at the end; file 2 gets efgh at the end .... I tried with: cat test | while read -r... (6 Replies)
Discussion started by: azaiiez
6 Replies

2. Shell Programming and Scripting

Cpio all *.txt-files out of folders to just one directory

I need a hint for reading manpage (I did rtfm really) of cpio to do this task as in the headline described. I want to put all files of a certain type, lets say all *.txt files or any other format. Spread in more than hundreds of subdirectories in one directory I would like to select them and just... (3 Replies)
Discussion started by: 1in10
3 Replies

3. Shell Programming and Scripting

Save files in directory as txt

wget -x -i link.txt The above downloads and create unique entries for the 97 links in the text file. However, each new file is saved as CM080 with a FILE extention. Is there a way to convert each file in that directory to a .txt? The 97 files are in... (12 Replies)
Discussion started by: cmccabe
12 Replies

4. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

5. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

6. Solaris

list of files in a txt file from sftp location

I want equivalent of ftp in sftp for listing of files into local machine from sftp location. ftp>ls -l list.txt the above creates a file list.txt in the local machine's current directory. sftp>ls -l list.txt it is giving Couldn't stat remote file: No such file or directory is there... (1 Reply)
Discussion started by: megh
1 Replies

7. Shell Programming and Scripting

Checking if the files in a directory have a txt extension

foreach file ($dir1/*) if ($file ~ *.txt) then echo "Skipping $file (is a txt file)" endif end that should work right guys? :confused: (15 Replies)
Discussion started by: pantelis
15 Replies

8. Solaris

list files .txt and .TXT in one command

Dear experts, In a directory i have both *.TXT and *.txt files. I have a script- for file in `ls *.txt`; do mv $file /tmp/$file How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find. br//purple (4 Replies)
Discussion started by: thepurple
4 Replies

9. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies

10. Shell Programming and Scripting

Read from fileList.txt, copy files from directory tree

Hi, hopefully this is a fairly simple Q&A. I have a clean file list of approximately 180 filenames with no directory or slashes in front of the filename nor any extension or dot ".". I would like to read from this list, find these files recursively down through directory trees, copy the files... (1 Reply)
Discussion started by: fxvisions
1 Replies

Featured Tech Videos