Find and touch in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and touch in Shell
# 1  
Old 03-19-2014
Find and touch in Shell

Hello All

Below is code snippet i am using
Code:
find . -name "*.txt" -mtime +5 -exec -touch "*.txt" {} +

The purpose is to make the files with name *.txt to be of size 0 kb if it is older than 5 days.With above code i am unable to do so.I know alternative is to use if/else loop but i would like to do this way only.
Please assist.
# 2  
Old 03-19-2014
Code:
find . -name "*.txt" -mtime +5 -exec rm -f {} \; -exec touch {} \;

# 3  
Old 03-19-2014
the above is not working
Error message as i found :
Quote:
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
# 4  
Old 03-19-2014
Untested:
Code:
for f in $(find . -name "*.txt" -mtime +5 -print); do > $f; done

Probably won't work if there are embeded spaces or other characters in the filenames.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Shell Script to touch a file

our requirement is that we need to create a touch file on 2 4 and 7 th working day of the each month ... If the days falls on saturday/sunday, the touch file should be created on next working day. We are currently on Red hat 6.5 (1 Reply)
Discussion started by: tradingspecial
1 Replies

2. Shell Programming and Scripting

Shell script to check files if exist else touch the file

Hi All, Thanks in Advance I wrote the following code if then echo "version is 1.1" for i in "subscriber promplan mapping dedicatedaccount faflistSub faflistAcc accumulator pam_account" do FILE="SDP_DUMP_$i.csv" echo "$FILE" ... (5 Replies)
Discussion started by: aealexanderraj
5 Replies

3. UNIX for Dummies Questions & Answers

Touch Challenge

I've been given a directory full of subdirectories full of logfiles of the same name: /logfiles/day1/file1/blockednodes.csv day1-14 file1-48 The above is the actual directory structure for 14 days worth of a logfile that is generated every 30 minutes. It's been done this way to preserve the... (15 Replies)
Discussion started by: Cludgie
15 Replies

4. Shell Programming and Scripting

How to find out the shell of the shell script?

Hello My question is: How to find out the shell of the shell script which we are running? I am writing a script, say f1.sh, as below: #!/bin/ksh echo "Sample script" From the first line, we can say this script will run in ksh. But, how can we prove it? Can we print anything inside... (6 Replies)
Discussion started by: guruprasadpr
6 Replies

5. UNIX for Advanced & Expert Users

Help with Touch Command

Hello, I am trying to use touch command to create 1200 .txt files. I am using this, but it is not working. touch `seq 1 1200`.txt Regards, Siddhesh.K (5 Replies)
Discussion started by: Siddheshk
5 Replies

6. Shell Programming and Scripting

Use arrow touch in a script shell without special character

Hello, I have a problem when i execute the script underneath. If i tape azerty 123 and i use the arrow touch, in the file /tmp/test i have the caracter #!/usr/bin/ksh clear echo "Taper l adresse IP de la partition a creer :" tput cup 1 48 read Adress echo $Adress echo "${Adress}" >>... (0 Replies)
Discussion started by: khalidou13
0 Replies

7. Shell Programming and Scripting

touch help

I need to change the modified time to below time , but can't get through using touch Nov 27 10:16 (2 Replies)
Discussion started by: dinjo_jo
2 Replies

8. Shell Programming and Scripting

how to make a log.txt and add date and time when use ls,touch and find

Hey guy, how to make the log.txt file and record date and time when ls, touch and find command run? Thanks Boly (13 Replies)
Discussion started by: chenboly
13 Replies

9. UNIX for Dummies Questions & Answers

Touch all files and subdirectories (recursive touch)

I have a folder with many subdirectories and i need to set the modified date to today for everything in it. Please help, thanks! I tried something i found online, find . -print0 | xargs -r0 touch but I got the error: xargs: illegal option -- r (5 Replies)
Discussion started by: glev2005
5 Replies

10. Shell Programming and Scripting

touch

why am i unable to change the timestamp on a file I'm getting the following error on AIX. touch: cannot change times Any help is appreciated. Regards, Ram. (4 Replies)
Discussion started by: ramky79
4 Replies
Login or Register to Ask a Question