Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

migrated from Feb 17 '13 at 20:13

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

man find..... – NPE Feb 17 '13 at 15:14
Read this – bmorris591 Feb 17 '13 at 15:19

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

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.

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 "{}" \;`

# 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

# Bring back original line separator value.
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .