Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-30-2010, 09:06 AM   #1
LQ Newbie
Registered: Nov 2010
Posts: 4

Rep: Reputation: 0
Delete a file from different dir without using cd


we assume that we have 2 folders with the name 1 and 2 .

The folder 2 is inside 1 .

Also, in folder 2 we have file with name "file.txt".

And we are in folder 1 .

How can we delete the file.txt in one command line ?

I mean without using the code below:

cd 2
rm -f file.txt
cd ..
Old 11-30-2010, 09:08 AM   #2
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Give the path to the file? For example, "rm 2/file.txt"..
1 members found this post helpful.
Old 11-30-2010, 09:09 AM   #3
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 333Reputation: 333Reputation: 333Reputation: 333
rm 2/file.txt
1 members found this post helpful.
Old 11-30-2010, 09:10 AM   #4
LQ Newbie
Registered: Jul 2008
Distribution: CentOS
Posts: 6

Rep: Reputation: 1
rm -f 2/file.txt
1 members found this post helpful.


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
[SOLVED] Read file names in a Dir and its Sub Dir in Perl sagarkha Programming 2 04-28-2010 04:58 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM
Recursive Delete DIR and Sub Dir with CONTENTS jCash Linux - Newbie 1 05-14-2007 05:54 PM
delete oldest file in dir. by c program hitesh.sharma84 Linux - Kernel 1 05-02-2007 10:18 AM
I Can't Delete a DIR carlosinfl Linux - General 2 10-19-2005 07:44 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:37 PM.

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