Operating System - HP-UX
1822147 Members
4147 Online
109640 Solutions
New Discussion юеВ

'ls' command to show the full path name

 
Chris Fung
Frequent Advisor

'ls' command to show the full path name

Hi all,

I am writing a find script to remove the ".log" files found on the system. However, I have difficulties on getting the full path name of the files before piping to "rm" command. Any idea?

Many thanks,

Chris,
4 REPLIES 4
S.K. Chan
Honored Contributor

Re: 'ls' command to show the full path name

Use "find" for your purpose .. for example ..

# cd /var/tmp
# find . -type f -name "*.log" -exec ll {} \;

It'll list any files with .log extension in /var/tmp in its relative path. So to remove them do ..

# find . -type f -name "*.log" -exec rm {} \;
Michael Tully
Honored Contributor

Re: 'ls' command to show the full path name

Hi,

You don't need to worry about the long name of the files, the find command takes care of that for you.

# find /myfilesystem -type f -name "*.log" -print -exec rm {} \;

You could also put this into cron to do it automatically should you wish. The example I've shown here is to run the command at 5AM every Sunday. Have a look at the man page on 'cron' for further info.

0 5 * * 0 find /myfilesystem -type f -name "*.log" -print -exec rm {} \;

Cheers
~Michael~
Anyone for a Mutiny ?
T G Manikandan
Honored Contributor

Re: 'ls' command to show the full path name

Hello,
As our Pharoahs mentioned it is really good to see the list of files.

For example all my oracle redologfiles have a ".log" extension.
I am to remove without knowing is going to be hard.

Thanks
Michael Tully
Honored Contributor

Re: 'ls' command to show the full path name

Hi,

Of course we restrict the search and subsequent removal of files to only filesystems that we wish to actually remove the files from. From my example it doesn't choose '/' but a filesystem name of your choice.
Cheers
Michael
Anyone for a Mutiny ?