LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-11-2011, 09:43 PM   #1
JuankyKong
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
ls /dev output


As you can all see I'm the rookiest around here :P well here goes my question, I'm trying to learn some scripting and so far seems i can do my first stuff on bash shell, at the moment I'm trying to create an script that reads from the ls /[DIRECTORY] command and the output of it for each file returned represents a character special file, a block special file or neither and this is what i have concluded
#!/bin/bash
clear
while read script
do
file=$(echo -e "$file" |

if [expression]
then
[do stuff here]
fi
done < ls /[direcotory name]
now on the grepping upthere is where i need to know how to find every type of file and then with the if statements clasiffy it and printout something for each file am i on the right track ? anyone can help ?
 
Old 11-11-2011, 10:10 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
First, please wrap your code in tags to make it easier to read. Second, you're not "grepping" anything in the code you have here. Thirdly, you might check the file command to see if it provides the type information you're looking for. It's difficult to tell because your question is slightly unintelligible.
 
Old 11-11-2011, 10:16 PM   #3
JuankyKong
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
I'll figure it out thanks a lot for your help ^^
 
Old 11-11-2011, 10:22 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
1. Here are reasons why you should not parse ls if you can help it.

2. The following will not work:
Code:
done < ls /[direcotory name]
3. What were you intending for the pipe in this line:
Code:
file=$(echo -e "$file" |
4. As previous poster pointed out, where is the grep?

5. Along with file you could also do a man on test to see how you can get some classifications on what a device is

6. Here is a reference that may help you (if you don't already have one)
 
1 members found this post helpful.
Old 11-13-2011, 06:39 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Have a look at the stat command. It's much better for accessing the metadata about a file than ls.

Edit: Don't forget the various test options either.

http://www.tldp.org/LDP/abs/html/fto.html

Last edited by David the H.; 11-13-2011 at 06:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
output of ls -las /dev/ jone kim Linux - General 3 04-24-2011 06:51 AM
[SOLVED] V4L - 2 capture cards result in fuzzy /dev/video0 and /dev/video1 output d_t_baker Linux - Software 1 10-03-2010 07:50 PM
if output to /dev/null how can i still get some output ?? naveen76 Linux - Software 2 11-23-2009 11:12 AM
[lirc] No output from irw, but cat /dev/lirc0 and mode2 /dev/lirc0 work fine Meson Linux - Software 0 10-20-2009 12:28 PM
All output to /dev/null? Satriani Programming 13 10-17-2003 02:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration