LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-23-2008, 06:25 PM   #1
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Rep: Reputation: 0
Remove files - the command


I want to delete the first created file from a total number of 7 files in a directory.

I can list it that way: ls -l | tail -n 7 | head -n 1

How can I run 'rm -rf' before it?

Thanks!

Last edited by Cheloo; 03-23-2008 at 06:27 PM.
 
Old 03-23-2008, 06:40 PM   #2
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Original Poster
Rep: Reputation: 0
tried a script:
Code:
#!/bin/bash
delete=`ls -l | tail -n 7 | head -n 1`
rm -rfi $delete
but it says:

./deleteit.sh
rm: invalid option -- w
 
Old 03-23-2008, 07:04 PM   #3
ak_random
Member
 
Registered: Jun 2007
Location: Silicon Valley, CA
Distribution: Xubuntu
Posts: 83

Rep: Reputation: 15
What's the file name of the file you're trying to remove? You may want to add an "echo '$delete'" to your script so you can see what it is.

Another way to possibly go about this might be to use the "find" command. e.g., if your file is older than a certain date, or some other identifying attribute.
 
Old 03-24-2008, 01:12 AM   #4
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ak_random View Post
What's the file name of the file you're trying to remove? You may want to add an "echo '$delete'" to your script so you can see what it is.

Another way to possibly go about this might be to use the "find" command. e.g., if your file is older than a certain date, or some other identifying attribute.
The name is variable by date, like name-24-03-2008, name-23-03-2008...
 
Old 03-24-2008, 01:24 AM   #5
ak_random
Member
 
Registered: Jun 2007
Location: Silicon Valley, CA
Distribution: Xubuntu
Posts: 83

Rep: Reputation: 15
And what is the file name that is failing (causing the error message to be printed)?

You may want to try starting your script with "#!/bin/bash -x" to see what the script think it's executing.

Last edited by ak_random; 03-24-2008 at 01:26 AM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove command not working gazman1 Programming 7 06-12-2006 11:20 AM
how do I remove this startup Command? kushalkoolwal Debian 5 05-17-2006 06:48 PM
Command Line Help: Remove a List of Files lukasbradley Linux - Newbie 2 08-17-2005 04:21 AM
Terminal command for GUI command "Remove to trash" GunSkit Linux - General 3 06-29-2004 01:50 PM
what is the command to remove the directory Harish_f Linux - General 6 06-19-2002 03:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:19 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
Open Source Consulting | Domain Registration