Solved

unix/perl simple

Posted on 2013-12-20
9
372 Views
Last Modified: 2014-01-05
Hi,

1.I found a lot of files in directory when i try to delete them i am getting too much argument error.

I tried the below.

rm -rf *.jpg
find -name *.jpg | xargs rm -rf *

2. I have to delete a huge number of sub directories inside a directory which also contains a lot of images there.( my aim is to delete the directories there and leave the images alone).

3.When i do df -k, i see the output in bytes , is it possible to see them in megabytes?

4.Say i am in /var/html folder and want to display files which has more than 500 MB size.
How can i do that.

Thanks,
Magento
0
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39732794
1) ls | grep \.jpg$ | xargs rm
# -rf shouldn't be needed in the above since it is files
-or-
find . -name \*.jpg -exec rm {} \;
2) find /directory -type d -exec rm -fr {} \;
3) Not that I'm aware of.
4) Define display.  You should be able to display them just like any other file provided you are using programs that either don't read the file all at once or can handle file sizes that large (though it will take substantially longer to display than small files would).
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 150 total points
ID: 39732824
3.  You can use -kh options which gives "human readable" format -- MB, GB, TB as appropriate.

4.  find /var/html -size +500M
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 150 total points
ID: 39732835
1.  Can you show argument error message?

Basically, in your command you did not need "*" at the end.  That is wrong.  And your first '*' should be quoted.

find -name '*.jpg' | xargs rm -rf
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 26

Accepted Solution

by:
wilcoxon earned 150 total points
ID: 39732843
I think my answer #2 needs a correction (otherwise it will delete the directory you specify as well as sub-dirs).

If there aren't too many files/dirs, the easiest would be:
find /directory/* -type d -exec rm -fr {} \;

Open in new window


If there are then you'll need to do something like this (think this syntax is right):
find /directory -depth -type d \( -name \. -prune -o -exec rm -fr {} \) \;

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 39732847
Correction in #2 above.

You need -h instead of -k.
Use
df -h
0
 
LVL 5

Author Comment

by:magento
ID: 39732863
Thanks both of you .
0
 
LVL 19

Assisted Solution

by:simon3270
simon3270 earned 100 total points
ID: 39735578
2) Did you way that you wanted to delete directories (I assume, empty ones) in a directory but leave the files alone?

in that case, cd to the directory and:
    find . -depth -type d | xargs rmdir
- the -depth makes it process child before parent directories
- rmdir will only remove empty directories, so any directories with files in will be left alone
0
 
LVL 29

Assisted Solution

by:serialband
serialband earned 100 total points
ID: 39737146
If you specifically want megabytes or gigabytes then you use -m or -g.

df -k --> in kilobytes
df -m --> in megabytes
df -g --> in gigabytes
df -h --> "human readable"
0
 
LVL 5

Author Comment

by:magento
ID: 39747619
Advance happy newyear to all of the experts .

I will close the question on Jan 2nd. Thanks.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Fine Tune your automatic Updates for Ubuntu / Debian
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question