Solved

unix/perl simple

Posted on 2013-12-20
9
368 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

785 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