[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

unix/perl simple

Posted on 2013-12-20
9
Medium Priority
?
383 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 27

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 600 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 600 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 27

Accepted Solution

by:
wilcoxon earned 600 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 20

Assisted Solution

by:simon3270
simon3270 earned 400 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 31

Assisted Solution

by:serialband
serialband earned 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

873 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