List file types


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List file types
# 8  
Old 10-28-2013
What OS and shell are you using?
# 9  
Old 10-28-2013
on solaris aix and hpux I get the same:
Code:
e.g. solaris:
/export/home/vbe $ ls -b | grep -v "/$" | xargs file -b
file: illegal option -- b
usage: file [-dh] [-M mfile] [-m mfile] [-f ffile] file ...

once -b removed works fine...
on linux now: (Debian)
Code:
as:/home/vbe $ ls -b | grep -v "/$" | xargs file -b
ASCII English text
ASCII English text
ASCII text
ERROR: cannot open `bin' (No such file or directory)
ERROR: cannot open `configure-debian_1.0.2-0.1.tar.gz' (No such file or directory)
ERROR: cannot open `creer_newuser' (No such file or directory)
ERROR: cannot open `creer_newuser.last' (No such file or directory)
ASCII text
ERROR: cannot open `dot.bashrc' (No such file or directory)
Korn shell script text executable
ASCII text
ASCII text
empty
ASCII English text
ASCII English text
ASCII text
ASCII English text
ASCII text
Korn shell script text executable
ERROR: cannot open `silly_prg' (No such file or directory)
ERROR: cannot open `sm' (No such file or directory)
ASCII English text
a /usr/bin/ksh script text executable
ASCII text
ERROR: cannot open `window_title' (No such file or directory)
ERROR: cannot open `wks' (No such file or directory)

generates errors when it has directories ...
# 10  
Old 10-28-2013
Not sure about the OS - this is a university box.
As for the shell it is a C shell.
So then, is there any workaround this situation? No other way to combine ls and file command to get a list of files?
I feel like I am really close but still not there .....
# 11  
Old 10-28-2013
Quote:
Originally Posted by adrianvas12
Maybe I am not clear enough - my task is to list the files from the current directory in the following format:
FileName FileSize FileType

So I was able to do the first 2 columns by using the following C shell:

Code:
awk 'BEGIN {printf "%-15s %-15s %-15s\n","Filename","Filesize","DateModified"}'

foreach file (*)
if (-f $file) then
   set x = `ls -l $file`
   #PRINT CURRENT DIRECTORY
   #echo $x | awk '{ printf "%-15s %-15s %-3s %-3s %-6s\n", $9, $5, $6, $7, $8}'
   echo $x | awk '{ printf "%-15s %-15s %-3s %-3s %-6s\n", $9, $5, $6, $7, $8}'
endif
end

Now I need to find a way to add the file type to that using filecommand
I tried your code:
Code:
ls -b | grep -v "/$" | xargs file -b

but that did not work.
If you change the %-6s\n in your awk printf command to just be %-6s and then add the following command:
Code:
   file $file

after that echo | awk pipeline, you'll come close to getting what you want. But without file's -b option, you'll get the filename twice.

I don't like writing scripts using csh, but the following Korn shell script seems to do what I think you're trying to do:

<obscured>

and will work even if some of your filenames contain whitespace characters. I just added the file type output to the end of the output your script was producing. Obviously, it would be easy to change this to print the file type instead of the DateModified field your script produced if you don't want both fields in your output.

If this isn't what you want, please show us the output of the command:
Code:
uname -a

which will tell us what operating system and what version of that operating system you're using.

Last edited by Corona688; 10-28-2013 at 05:21 PM..
This User Gave Thanks to Don Cragun For This Post:
# 12  
Old 10-28-2013
Thank you for your help - I really appreciate.
I am afraid that I have to use C Shell - part of the assignment.
Here is the output of the command:

Linux merlin 2.6.27.25-78.2.56.fc9.i686 #1 SMP Thu Jun 18 12:47:50 EDT 2009 i686 i686 i386 GNU/Linux


Give me one second and I'll try your suggestion.

---------- Post updated at 04:20 PM ---------- Previous update was at 04:15 PM ----------

I think that worked - all I have to do is to remove the extra notes after each file type i.e. PDF Document, version 1.0
I just need to keep PDF Document.
I think grep and sed may help.
# 13  
Old 10-28-2013
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cp -r except certain file types

the following excludes certain directories successfully cp -r probe/!(dir) /destination I want to exclude certain file types and tried unsuccessfully cp -r probe/!(*.avi) /destination (2 Replies)
Discussion started by: tmf
2 Replies

2. Red Hat

Copy certain file types recursively while maintaining file structure on destination?

Hi guys, I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash. I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Discussion started by: rockf1bull
1 Replies

3. UNIX for Dummies Questions & Answers

Types of File in a directory

Hello, I have several thousand files with different extensions in a directory. Is there a single command to get what the various extensions are with a single command. Thanks for your help! Best, Guss (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

4. Shell Programming and Scripting

list quantity of files by file types

I'm trying to create a simple file inventory for a series of huge directories containing e-records. What I'm after is a list of all directories and sub-directories with just the number of each type of file in that directory/sub-directory. For example output would look like: ... (6 Replies)
Discussion started by: dorcas
6 Replies

5. UNIX for Dummies Questions & Answers

How do I grep in specific file types?

I have a directory with file types ending .log, .mml, .gll, .dll . How can I grep expressions only in say the .log files? (3 Replies)
Discussion started by: bbbngowc
3 Replies

6. Shell Programming and Scripting

Parsing a file that contains 2 types of delimeters

Now that I have a file that looks something like this; 20050926 Unknown 20050926 MUREXFO 20050926 MUREXFO 20050926 MUREXFO 20050926 Unknown 20050926 KADDUSS 20050926 KADDUSS 20050926 KADDUSS 20050926 MUREXFO Is there a way in vi that I can search the file and remove any line... (2 Replies)
Discussion started by: morgadoa
2 Replies

7. Shell Programming and Scripting

Parsing a file that contains 2 types of delimeters

I am trying to write a script and failing miserably. I have a file that looks something like this; 20050924-155819;Backoffice;1037;0;DDT-TCP/IP;;0;Node 20050924-155902;Unknown;1036;0;DDT-TCP/IP;;0;Node 20050924-155922;FrontOffice;1040;5;DDT- The desired result is one file containing only... (4 Replies)
Discussion started by: morgadoa
4 Replies

8. UNIX for Dummies Questions & Answers

Details on the ls command and file types

Hey y'all, I need some help with the nitty gritty of the ls command. -First off in the man pages in the -l mode the first character can be "door" can anyone tell me what a door is??? -also in the -l mode the first character can be "fifo"or"pipe" can anyone tell me what a this is??? -What... (4 Replies)
Discussion started by: jacob358
4 Replies

9. Filesystems, Disks and Memory

associated file types

I have a file of type .for extension .In a guui based unix environment like solaris if I double click on that file a specific program designed by me has to run which takes this file as the parameter and exceutes the program. Can anyone help me? (8 Replies)
Discussion started by: nhk_srd
8 Replies

10. Linux

File types help needed

Hi all, quick question... Im trying to configure Redhat 9 to dial out to my ISP AOL. I have found some software to do this but at present I can't get net access under Linux for the reason stated. I can however acces the net using my laptop running windows. The question is: I have downloaded... (3 Replies)
Discussion started by: brady9953
3 Replies
Login or Register to Ask a Question