LinuxQuestions.org
Visit Jeremy's Blog.
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 10-20-2010, 06:53 AM   #16
shayno90
Member
 
Registered: Oct 2009
Distribution: Debian Lenny 2.6.26 Ubuntu Lucid Lynx 10.04 Windows 7
Posts: 187
Blog Entries: 3

Original Poster
Rep: Reputation: 21

Quote:
Originally Posted by grail View Post
My query to see file format was more based on why the use of the convoluted search item:

If it is just the files under each A-ABC-* directory then crts' solution could be used without the -name option:
Code:
find /path/to/A-ABC-* -maxdepth 1 -type f -exec echo rm -f '{}' \;
Could you all also explain the syntax behind the find command particularly "#123,#125"?

Only files in the subfolder (this is ../ from the parent directory) of every A-ABC-* (this in the parent directory e.g. A-ABC-20100908-0001 etc.) needs to be deleted in A-ABC-*/folder/subfolder.

I.E. Only the csv files in the subfolder need deletion and not the parent directories or files in other non related folders.

Is this clearer?
 
Old 10-20-2010, 06:59 AM   #17
hairysocks
Member
 
Registered: May 2002
Location: Thorverton, Near Exeter, Devon, England
Distribution: Ubuntu 10.04 (used to be Red Hat 7.1, then Red Hat 9, then FC 2, FC 5, FC 6, FC 9 and Ubuntu 8.04)
Posts: 105

Rep: Reputation: 16
Quote:
Originally Posted by shayno90 View Post
Well, I don't want to delete the directories, only the files contained within the directories of each folder for example the 36 folders each have the following format with the subfolder the target folder to have files deleted:

A-ABC-DDMMYY-NN/folder/subfolder

e.g.
A-ABC-20100102-0001/folder/subfolder
A-ABC-20100204-0006/folder/subfolder
A-ABC-20100307-0005/folder/subfolder
A-ABC-20100602-0009/folder/subfolder
etc....
Use rm -f A-ABC-2010*/folder/subfolder/*
 
Old 10-20-2010, 08:38 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Based on your earlier example:
Code:
user@debian:~$ cd A-ABC-20100102-0001
user@debian:~/A-ABC-20100102-0001$ ls -1
csv
data
number
folder

user@debian:~/A-ABC-20100102-0001$ cd A-ABC-20100102-0001/folder
file.txt
line
subfolder

user@debian:~/A-ABC-20100102-0001$ cd A-ABC-20100102-0001/folder/subfolder
file.csv
file1.csv
file2.csv
From the above would you be wanting to delete the following:
Code:
csv
data
number
file.txt
line
file.csv
file1.csv
file2.csv
If this is correct then it is as simple as:
Code:
find /path/to/A-ABC-* -type f -exec echo rm -f '{}' \;
If not correct, please identify which files above should be removed?
 
Old 10-21-2010, 04:20 AM   #19
shayno90
Member
 
Registered: Oct 2009
Distribution: Debian Lenny 2.6.26 Ubuntu Lucid Lynx 10.04 Windows 7
Posts: 187
Blog Entries: 3

Original Poster
Rep: Reputation: 21
Quote:
user@debian:~/A-ABC-20100102-0001$ cd A-ABC-20100102-0001/folder/subfolder
file.csv
file1.csv
file2.csv
[/code]
From the above would you be wanting to delete the following:
Code:
file.csv
file1.csv
file2.csv
If this is correct then it is as simple as:
Code:
find /path/to/A-ABC-* -type f -exec echo rm -f '{}' \;
If not correct, please identify which files above should be removed?
Only the files with file.csv extension need to be deleted in the subfolder path. Not sure if you need to use rm -f though.

Last edited by shayno90; 10-21-2010 at 04:21 AM.
 
Old 10-21-2010, 09:16 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well that makes life easier:
Code:
find /path/to/A-ABC-* -type f -iname '*.csv' -exec echo rm -f '{}' \;
If you get the output you are looking for, just remove the echo and it will take affect.
 
1 members found this post helpful.
Old 10-21-2010, 10:33 AM   #21
shayno90
Member
 
Registered: Oct 2009
Distribution: Debian Lenny 2.6.26 Ubuntu Lucid Lynx 10.04 Windows 7
Posts: 187
Blog Entries: 3

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by grail View Post
Well that makes life easier:
Code:
find /path/to/A-ABC-* -type f -iname '*.csv' -exec echo rm -f '{}' \;
If you get the output you are looking for, just remove the echo and it will take affect.
Thanks grail, the command worked!

I also found another command to do the same job

ls -l A-ABC-*/folder/subfolder
find A-ABC-*/folder/subfolder -type f -delete
 
Old 10-21-2010, 12:55 PM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
find A-ABC-*/folder/subfolder -type f -delete
If you are going to go to this extreme of putting whole path in then as other have said, just use rm:
Code:
rm A-ABC-*/folder/subfolder/*csv
By the way, your command will also delete non csv files
 
  


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
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 01:40 PM
Remove files that contain a specific string poymode Linux - General 5 02-17-2010 04:01 AM
Remove ALL files from specific Directory bianchi Programming 9 11-24-2005 12:27 AM
/bin/bash how to remove specific file anywhere on harddrive cjagdish69 Linux - Software 1 01-07-2005 06:42 AM
remove folder from command line demmylls Linux - General 3 02-15-2004 10:52 AM


All times are GMT -5. The time now is 11:56 AM.

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