Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have to delete files of yesterday, I am doing something like this

ls -l | grep 'Feb 15'|awk| xargs

I cant use awk, since my file names have spaces in them, so I cant separate them in the output of ls -l.

Can anyone help me with this?

share|improve this question
3  
man find..... –  NPE Feb 17 '13 at 15:14
    
Read this –  bmorris591 Feb 17 '13 at 15:19
add comment

migrated from stackoverflow.com Feb 17 '13 at 20:13

This question came from our site for professional and enthusiast programmers.

2 Answers

first do:


find /path/to/search/ -type f -mtime 1

to make sure you're seeing the proper results -mtime n means n*24 hours ago then use -print0 to work around spaces


find /path/to/search/ -type f -mtime 1 -print0

then to remove add a pipe to xargs


find /path/to/search/ -type f -mtime 1 -print0 |xargs -0 rm

share|improve this answer
add comment

I am basing my answer on the fact that you're having trouble handling file names with spaces in them.

I have a Linux application that has to deal with files whose names contain embedded spaces. The following are extracts from my bash shell script that allow me to use a for loop to find the two files and do something about them.

In my case, it was to pass them off to a Clojure program that would identify what the files were based on their column signatures. Both files are .csv files. The money shot is changing IFS, and then restoring its original value when you are done. That allows $fnam to contain the file name if it has embedded spaces in it.

# $IFS is internal file separator.
# The following little code snippet takes into account space-separated files.
# We set the file separator value to something other than space.

ORIGINAL_IFS=$IFS
IFS=$(echo -en "\n\b")

# You have to fond both types of files .CSV or .csv. 
#This is the way to do it. cmn 11/1/2012

for fnam in `find bene_gic_in -maxdepth 1 \
-type f \( -name \*.csv -o -name \*.CSV \) \
-exec echo "{}" \;`
do

# Please note that $fnam may have embedded spaces in it, at this point, 
# you could check # for the name, and make a decision about what to do 
# with it, like 
# 

if [ "$fnam" = "a file name i expect" ]; then
# do something.
   mv $fnam file_type1
fi

.
.
.
# Bring back original line separator value.
IFS=$ORIGINAL_IFS
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.