Solved

unix/perl simple

Posted on 2013-12-20
9
365 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 27

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

12 Experts available now in Live!

Get 1:1 Help Now