Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › shell programming help
New Posts  All Forums:Forum Nav:

shell programming help

post #1 of 7
Thread Starter 
hey guys. im using the bashshell and i've run into a problem with an assignment question.

Write a simple shell script mnamed lsd whihc generates a long listing of files with todays date in teh current working directory. So if today is Sept 26 and ls-l . will generate a listing of all the files in my directory that have been accessed today.


any help would be great. im just really struggling on how to figure out which command will cut out the files that were not accessed on the 26th.
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
post #2 of 7
You can pump the LS output into the SED interpeter.

Something like
ls-l > File.out
sed "/9\\/26\\/2006/!d" < file.out > TodaysFiles.txt
TITAN-6
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4GHZ ASRock Extreme 3 Gen 3 Gigabyte Nvidia GTX 570 8GB G.skill Sniper DDR3 1866 
Hard DriveOptical DriveCoolingOS
Crucial M4 CT128M4SSD2 2.5" 128GB SATA III MATSHITA BD-CMB UJ160 Blu Ray DVD writer Cooler Master Hyper 212+ Windows 7 x64 
MonitorMonitorKeyboardPower
Sceptre 24" LCD BENQ 3D 24" LCD Logitech G510 Corsair 750W HX professional single rail 
CaseMouseMouse PadAudio
CM Storm Sniper Razer Naga left-handed version None Onboard 
  hide details  
Reply
TITAN-6
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4GHZ ASRock Extreme 3 Gen 3 Gigabyte Nvidia GTX 570 8GB G.skill Sniper DDR3 1866 
Hard DriveOptical DriveCoolingOS
Crucial M4 CT128M4SSD2 2.5" 128GB SATA III MATSHITA BD-CMB UJ160 Blu Ray DVD writer Cooler Master Hyper 212+ Windows 7 x64 
MonitorMonitorKeyboardPower
Sceptre 24" LCD BENQ 3D 24" LCD Logitech G510 Corsair 750W HX professional single rail 
CaseMouseMouse PadAudio
CM Storm Sniper Razer Naga left-handed version None Onboard 
  hide details  
Reply
post #3 of 7
Thread Starter 
^ thanks

is there any simpler way of doing it because our prof hasnt gone over reg exp. yet


what i came up with was

Ls -l | sort -u | grep 'Sept 26'

it works but the only problem is it works only for that day, is there someting i can put to replace Sept 26 such that it will update automatically acoording to the date?
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
post #4 of 7
Quote:
Originally Posted by c_loke
^ thanks

is there any simpler way of doing it because our prof hasnt gone over reg exp. yet


what i came up with was

Ls -l | sort -u | grep 'Sept 26'

it works but the only problem is it works only for that day, is there someting i can put to replace Sept 26 such that it will update automatically acoording to the date?
maybe try date or date %D

Just a thought. Not sure it'll get the date or just output it though.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #5 of 7
Thread Starter 
ls -l | sort -u | grep 'date "+%b"'

if anyone is curious.

now i run into another problem.

Write a shell script named ftype whihch accepts a list o filenames from command line and determines whether each file is regular file or directory.

any ideas?
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
post #6 of 7
When you ls -l the permission list shows if it a file, special file, or directory. You know, like drwxr-xr-x. I'm thinking awk or something... oh yeah, the way easier way is built into bash iirc, they have a if [-x something ] expression for executable, some other letter for directory, etc.
post #7 of 7
Thread Starter 
thanks for the help guys, i managed to get my stuff done
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
Nov 7 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 930 Asus P6X58D-E XFX Radeon HD 6870 Kingston HyperX DDR3-1600 6 Gig 
Hard DriveOSKeyboardPower
Crucial C300 64 Gig Windows 7 Professional Logitech G15 Corsair TX750W 
CaseMouse
Coolermaster CM690 Logitech G5 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › shell programming help