Sponsored Content
Full Discussion: Delete directory conditioned
Top Forums UNIX for Dummies Questions & Answers Delete directory conditioned Post 302625077 by zaxxon on Tuesday 17th of April 2012 08:48:31 AM
Old 04-17-2012
No, you are right, sorry. I was drifting away while testing out and thought about having additional levels etc.Smilie not seeing the wood for the trees...
Didn't think about much easier ls -t which does it all for us:
Code:
cd /sdcard/backup; ls -t1 | awk 'NR>1 {system("rm -r "$1)}'

Keep in mind that both solutions are looking for files in that directory, not only directories. So with rm -r you will get an error when encountering non-directory files.

Last edited by zaxxon; 04-17-2012 at 10:02 AM..
This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. HP-UX

Can't delete a directory on HP-UX

Hi, I am having hard time to delete a directory: $ rm -r testoxdwdw rm: testoxdwdw non-existent $ rmdir testoxdwdw rmdir: testoxdwdw: No such file or directory $ rm -rf testoxdwdw Thanks! (2 Replies)
Discussion started by: oradbus
2 Replies

2. UNIX for Dummies Questions & Answers

delete a directory

Hi all, I have an empty directory "-ltr". How to delete it ? Thanks (4 Replies)
Discussion started by: madmat
4 Replies

3. Solaris

Can't delete directory

Hi, I have a problem on Solaris 10 regarding deletion of files when I try to recursively delete the directory /opt/Tivoli as root, I get the following error message: rm: Unable to remove directory Tivoli/lcf/dat/1/no-del/bin/solaris2/TME: File exists rm: Unable to remove directory... (4 Replies)
Discussion started by: funksen
4 Replies

4. Solaris

Directory cannot delete

Dear All, I have problem at T5220 server, when I enter at my server as oracle user and make directory ex. directory test then I will delete directory test with command : rm -rf, what happenned...?? that directory cannot deleted. What's wrong with my server...? Note: my server T5220 with... (3 Replies)
Discussion started by: mbah_jiman
3 Replies

5. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

6. UNIX for Dummies Questions & Answers

Cannot Delete Directory

Hello, I am trying to delete a directory but cannot. Can anyone assist? See attached. Many thanks. (6 Replies)
Discussion started by: dixer
6 Replies

7. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

8. UNIX for Dummies Questions & Answers

awk file subtracted by a fix value - conditioned

Hi all... i have been trying to make this work but I have been failing for 6 hours .. I know it should be something simple that I am missing to it would be great if you can help me ... I want to subtract a fixed value (lets set 1) from any value >=1 from the whole file my file looks like ... (4 Replies)
Discussion started by: A-V
4 Replies

9. UNIX for Dummies Questions & Answers

Why can't I delete this directory ?

Oracle Linux 6.4 bash shell I am trying to remove the directory named OPatch. I am trying to run rm and rmdir commands while logged in as grid user, the owner of the directory. But I keep getting "Permission denied" error. It is an empty directory. Any idea why I am getting 'Permission denied'... (5 Replies)
Discussion started by: kraljic
5 Replies

10. Shell Programming and Scripting

Delete directory

Can we force delete the directories despite having files in it? Because I need to delete multiple directories which has multiple files. As of now, I'm deleting the files before deleting the directory. Can't we delete the directory with files? (3 Replies)
Discussion started by: Ram Kumar_BE
3 Replies
Cone(C)

MAILTOOL(1)						  Cone: COnsole Newsreader And E					       MAILTOOL(1)

NAME
mailtool - Process mailboxes SYNOPSIS
mailtool [options...] USAGE
mailtool is a diagnostic utility for handling various operations on mailboxes. mailtool's main uses include: display the list of folders in a mailbox; displaying list of messages in a mailbox; and copying mailboxes. The following mailboxes can be accessed by mailtool: imap://userid@server[/options] An IMAP account. mailtool will prompt for the login password. imaps://userid@server[/options] An IMAP account accessed via an encrypted SSL connection. pop3://userid@server[/options] A POP3 account. mailtool will prompt for the login password. pop3s://userid@server[/options] A POP3 account accessed via an encrypted SSL connection. maildir:path A local maildir mailbox. path specifies the maildir's location relative to the home directory (NOT the current directory). mbox:path Local mbox mail folders. path specifies the path to an mbox folder file, or a directory containing mbox folders, relative to the home directory (NOT the current directory). inbox:path Local mbox mail folders, like "mbox:path"; additionally, the system spool mailbox is automatically copied to $HOME/Inbox, which is accessible as folder INBOX. The name of a remote IMAP or POP3 server may be followed by one or more options that control various settings of the IMAP or POP3 connection: /cram Do not open the account unless the server supports secure password authentication. Secure password authentication verifies the account's password using a challenge/response authentication mechanism (where the label "cram" comes from). The actual password is never actually transmitted to the server, and therefore cannot be intercepted while in transit over an untrusted network. Secure password authentication is not supported by all servers. This option may not work with some servers. This option does not enable secure password authentication, it only mandates its use. If the server supports secure password authentication, it will be used even without the /cram option. Traditional userid/password authentication will be used only if the server does not implement secure password authentication. The /cram option makes secure password authentication mandatory. The /cram option is marginally useful even with encrypted server connections. The secure password authentication never sends the explicit password to the server. Encryption makes it theoretically impossible to recover the password from an encrypted data connection; but with secure authentication the password is never sent over the connection in the first place (the password's validity is certified by exchanging certain mathematical calculations between the server and the client). If the server is compromised, the compromised server will not receive the account password (unless the password is recovered from the server in other ways). /imap Do not use the SMAP if the server claims the availability of this experimental mail access protocol, and fall back to IMAP compatibility mode (this option is meaningful only with "imap://" and "imaps://" URLs). /notls Do not upgrade a plain connection to an encrypted one. This option is primarily used for testing and debugging purposes. Sometimes this option might be useful with servers that claim to offer encryption, but are unable to do so when taken up on their offer. /novalidate-cert Do not validate the server's SSL certificate when using an encrypted connection. Normally the mail server's SSL certificate must be validate when using an encrypted connection. The certificate's name must match the server's name, and the certificate must be signed by a trusted certificate authority. The encrypted connection normally fails if the certificate cannot be validate. Validation requires that a list of trusted certificate authorities must be known and configured. It's simply impossible to know which certificate authorities are valid without an explicit list of valid, known, trusted, certificate authorities. If a trusted authority list is not configured, no certificate can be validated. If the server's certificate is a self-signed certificate (this is often used for testing purposes), or if it's not signed by a known authority, the encrypted connection fails. This /novalidate-cert option disables certificate validation. The encrypted connection will be established even if the server's certificate would otherwise be rejected. Note This option is applicable even when an encrypted IMAP or POP3 connection is not explicitly requested. Many mail servers are capable of automatically upgrading unencrypted connections to a fully-encrypted connection. If a mail server claims to be able to use encryption, then there's no reason not to use it. The result is that all encryption certification requirements still apply even when encryption is not explicitly requested. Displaying mailbox contents mailtool -tree | -list account -tree shows a hierarchical representation of mail folders in account. -list generates a simple folder listing, one folder name per line. -tree shows folder names, while -list shows the actual mail folder path in account. mailtool -tree imap://jsmith@mail.example.com/novalidate-cert/cram Creating folders mailtool -create | -createdir folder name account -create creates a new subfolder of folder in account. The new subfolder's name is name. -createdir creates a new folder directory (a folder that contains other folders). mailtool -create INBOX.lists announcements maildir:Maildir This command creates a new folder "announcements" as a subfolders of "INBOX.lists" in the local maildir. Deleting folders mailtool -delete | -deletedir folder account -delete deletes an existing folder in account. -deletedir deletes a folder directory. mailtool -delete INBOX.lists.announcements maildir:Maildir Renaming folders mailtool -rename oldfolder folder name account -renames renames an existing oldfolder. The folder is renamed as name, as a subfolder of folder. folder may be an empty string if the folder should be moved to the top level of account's folder hierarchy. mailtool -rename INBOX.lists.announcements INBOX.lists Announcements maildir:Maildir The folder "INBOX.lists.announcements" is renamed to "INBOX.lists.Announcements". This slightly unusual way to rename folder allows folders to be relocated in the mail account's folder hierarchy. Reading folder's index mailtool -index folder account -index downloads and prints a summary of all messages in folder, in account. The summary shows the sender's and recipients' address, the message's subject, and size. mailtool -index INBOX imap://john@mail.example.com/novalidate-cert Removing a message from a folder mailtool -remove folder n account -remove removes message #n (ranging from 1 to the number of messages in the folder) in folder, in account. The message numbers may be obtained by using -index. n may be a comma-separated list of message numbers, in strictly numerically increasing order. -remove confirms the list of messages to remove and issues a "Ready:" prompt. Press ENTER to remove the messages. mailtool -remove INBOX 28,31 imap://john@mail.example.com/novalidate-cert Filtering messages mailtool -filter folder account -filter is a combination of -index and -remove. folder's index is downloaded, and the summary of each message is shown, one message at a time. Each message's summary is followed by a prompt: "Delete, Skip, or Exit". Pressing D removes the message, S leaves the message unchanged, and E leaves the remaining messages unchanged. mailtool -filter INBOX pop3://john@mail.example.com/novalidate-cert Note -filter is not meant to be used with large folders. Unless messages are removed quickly, the connection to the server may be disconnected for inactivity. Copying folders mailtool [-recurse] -tofolder tofolder -copyto toaccount -fromfolder fromfolder fromaccount This command copies an entire folder, fromfolder in fromaccount to a new folder, tofolder (which will be created, if necessary) in toaccount. Optionally, -recurse specifies that all subfolders of fromfolder should also be copied. mailtool -tofolder INBOX -copyto maildir:Maildir -fromfolder "INBOX" imap://mbox100@mail.example.com/novalidate-cert mailtool -recurse -tofolder INBOX.converted_mail -copyto maildir:Maildir -fromfolder "mail" imap://mbox100@mail.example.com/novalidate-cert This example first copies the INBOX on the IMAP server to $HOME/Maildir, then copies subfolders of "mail" on the IMAP server to the "converted_mail" subfolder in the maildir. mailtool -tofolder INBOX -copyto maildir:Maildir -fromfolder "INBOX" inbox:mail mailtool -recurse -tofolder INBOX.converted_mail -copyto maildir:Maildir -fromfolder "" mbox:mail This example first copies $HOME/Inbox (accessed as the INBOX folder in inbox:mail) to $HOME/Maildir, then copies mbox folders from $HOME/mail to the "converted_mail" subfolder in the maildir. Note Mail accounts that contain hybrid folders (folders that contain both messages and subfolders) can only be copied to account types that also support hybrid folders: either local maildirs, or to remote servers that support hybrid folders. SEE ALSO
cone(1). AUTHOR
Sam Varshavchik Cone(C) 04/04/2011 MAILTOOL(1)
All times are GMT -4. The time now is 02:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy