How to delete many files in Unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to delete many files in Unix
# 1  
Old 11-19-2007
How to delete many files in Unix

Hi,
I am tryting to delete 3 lakch files using below command.

rm 1000318*
it is showing a message "sh: /usr/bin/rm: The parameter list is too long."

please let me know how can i do this.

Thanks
Senthil
# 2  
Old 11-19-2007
sorry to post again

to add up

ls 1000318* | head -1
sh: /usr/bin/ls: The parameter list is too long

i got this error message even when i tried to do ls.
# 3  
Old 11-19-2007
use find...

confirm with

Code:
find . -name "1000318*"

do the remove with

Code:
find . -name "1000318*" | xargs -n 10 rm

# 4  
Old 11-19-2007
Code:
ls|grep ^1000318|xargs rm

# 5  
Old 11-19-2007
Great to see the reply .

Can you please explain why with ls *xx* it is not listing. and what is the speciality with ls | grep ^ *xx*
# 6  
Old 11-19-2007
Because of the ARG_LIST_MAX limit (the shell tries to expand the glob).
It's like "ls ." vs "ls *"
The first alternative gets an argument with one entry, whereas
the second gets an argument consisting of all names in your directory.
Anyway, the find solution seems much faster (you may need to limit the recursion though).
# 7  
Old 11-19-2007
Thanks for your explanation ..

How can we find the ARG_LIST_MAX .. And who decide this value ..Is it admin or UNIX kernel itself.

i tried to do echo $ARG_LIST_MAX but i ger an error

Thanks,
arun.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Unix shell script to delete files on windows server

Hi experts, can anyone suggest me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (2 Replies)
Discussion started by: chpradeepch
2 Replies

3. Shell Programming and Scripting

Find and delete files and folders which are n days older from one unix server to another unix server

Hi All, Let me know how can i find and delete files from one unix server to another unix server which are 'N' days older. Please note that I need to delete files on remote unix server.So, probably i will need to use sftp, but question is how can i identify files and folders which are 'N'... (2 Replies)
Discussion started by: sachinkl
2 Replies

4. UNIX for Dummies Questions & Answers

Delete folders and files in it - UNIX

I need to delete a folder and files in it of yesterdays and simply put this in cron. Folder name - "2010-03-2010" File name - "eprod_06_23.dmp" and "eprod_06_23.exp" Actually this folder and file is been created by a script which takes a backup of DB everyday.Thats why it creates folder and file... (3 Replies)
Discussion started by: j_panky
3 Replies

5. Shell Programming and Scripting

delete old files thru unix script

I have to delete files older than 60 days from a windows directory. So I tried to include this script FTP_LOG=${DATA_TOP}/data_tmp/logfile FTP_CMDS=${DATA_TOP}/data_tmp/cmdfile echo "open ftp1" > ${FTP_CMDS} echo "user anonymous local" >> ${FTP_CMDS} echo "cd ${SRC_DIR}" >> ${FTP_CMDS} echo... (3 Replies)
Discussion started by: snair001
3 Replies

6. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

7. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

8. Shell Programming and Scripting

using c programming in unix to delete zero-byte files in a specified directory

we were asked to make a program that deletes all zero-byte files in a psecified directory. we need to use sysytem_calls like: scandir(),chdir(),stat() and remove(). (3 Replies)
Discussion started by: sogetsu009
3 Replies

9. Shell Programming and Scripting

Delete files older than 2 days using shell script in Unix

I'm new to shell script.... can any one help... What is the shell script to delete the files older than 2 days ? (3 Replies)
Discussion started by: satishpabba
3 Replies

10. Shell Programming and Scripting

How to delete files in UNIX using shell script

Hi, I have the following task to perform using shell script. The user will provide a directory name along with a date. The script will delete all the files in the specified directory that was created earlier to that date. Also it should display the number of files that has been deleted. ... (7 Replies)
Discussion started by: theguy16
7 Replies
Login or Register to Ask a Question