Solved

unix/perl simple

Posted on 2013-12-20
9
366 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
  • 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
 
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
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.

 
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 28

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now