The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 4 Weeks Ago 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Oct 2006
Posts: 3
Unhappy ls command help

Okay so I am very confused as to how to do this it says it is an exercise in my book but never talks about it or explains it please help I have tried everything every combination i can think of.

find out which of these filename paths exist using the ls command and save the list to a file in the pwd name 'existentFiles'

/etc/magic /sbin/fsck /boot/grub/menu.lst /usr/share/games/wombat /var/cache/man/index.db /usr/bin/defcon

with parameters that aside from the file name args, only the -1 flag for the ls command should be used.

I have no clue what the command would be I have tried
ls -1 /etc/magic /sbin/fsck /boot/grub/menu.lst /usr/share/games/wombat /var/cache/man/index.db /usr/bin/defcon > existentFiles

and many variations but nothing........

then the 2nd part is to find out from the same list which pats exist and which dont using the same parameters except adding both a list in the pwd named existentFiles and a list in the pwd for nonexistantFiles

Please help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
hey the option is not -1, its -l (el)...use it...it'll work fine

for the second part, after >existentfiles, type 2>nonexistentfiles it will send the error output to nonexistentfiles
Reply With Quote
  #3 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Oct 2006
Posts: 3
it is actually -1 which is a new line for every file
Reply With Quote
  #4 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
hmmm...i'll chk it out n let u know...am also a newbie
Reply With Quote
  #5 (permalink)  
Old 10-23-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Are you allowed to use "cut"?
Code:
ls -1 /etc/magic /sbin/fsck /boot/grub/menu.lst /usr/share/games/wombat /var/cache/man/index.db /usr/bin/defcon 2>&1 1>existingFiles | cut -d" " -f1 >nonexistingFiles
If not, try
Code:
ls -1 /etc/magic /sbin/fsck /boot/grub/menu.lst /usr/share/games/wombat /var/cache/man/index.db /usr/bin/defcon 2>&1 1>existingFiles 2>nonexistingFiles
The drawback there is that instead of a simple list of files in "nonexistingFiles", you'll have a list like:
Code:
/boot/grub/menu.lst not found
/var/cache/man/index.db not found
Reply With Quote
  #6 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Oct 2006
Posts: 7
use grep -v ?
Reply With Quote
  #7 (permalink)  
Old 10-23-2006
Registered User
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 382
Code:
#!/bin/ksh

if [ -f existentFiles ]
then
  rm existentFiles
fi

for a in /etc/magic /sbin/fsck /boot/grub/menu.lst /usr/share/games/wombat /var/cache/man/index.db /usr/bin/defcon

do
  if ( ls $a > /dev/null 2>&1 )
  then
    echo $a >> existentFiles
  fi
done
On my Mandrake box (using /bin/bash as the first line) I get:

Code:
$ cat existentFiles
/sbin/fsck
On my OpenBSD box (using /bin/ksh as the first line) I get:

Code:
$ cat existentFiles
/etc/magic
/sbin/fsck
Carl
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0