Sponsored Content
Top Forums Shell Programming and Scripting To remove file using rm inside c Post 302488675 by derekludwig on Tuesday 18th of January 2011 06:38:44 AM
Old 01-18-2011
The contents of cmd, after the [man]sprintf[/man] would be: /bin/rm -f /usr1/mydir/,1.t,2.t, which is not what is needed to remove a file. This does what you want:
Code:
{
    char path[100];
    char *file[3] = { "1.t", "2.t", "3.t"; }

    for (int i = 0; i < 3; i++) {
        strcpy(path, "/usr1/mydir/");
        strcat(path, file[i]);
        unlink(path);
    }
}

Although there is no error checking what-so-ever.
 

10 More Discussions You Might Find Interesting

1. Linux

How to remove only html tags inside a file?

Hi All, I have following example file i want to remove all html tags only, Input File: <html> <head> <title>Software Solutions Inc., </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor=white leftmargin="0" topmargin="0"... (2 Replies)
Discussion started by: btech_raju
2 Replies

2. Shell Programming and Scripting

remove a whole directory tree WITH files inside?

Assume I want to remove a whole directory tree beginning with /foo/bar/ The directory or sub-directories may contain files. The top directory /foo/bar/ itself should not be deleted. rm -f- r /foo/bar does not work because it requires a directory tree without files. How does it work... (3 Replies)
Discussion started by: pstein
3 Replies

3. Shell Programming and Scripting

Remove \n <newline> character inside the records.

Hi, In my file, I have '\n' characters inside a single record. Because of this, a single records appears in many lines and looks like multiple records. In the below file. File 1 ==== 1,nmae,lctn,da\n t 2,ghjik,o\n ut,de\n fk Expected output after the \n removed File 2 =====... (5 Replies)
Discussion started by: machomaddy
5 Replies

4. Shell Programming and Scripting

How to remove string inside html tag <a>

Does anybody know how i can remove string from <a> tag? There are several hundred posts in a few forums that need to be cleaned up. The precise situation is ---------- <a href="http://mydomain.com/cgi-bin/anyboard.cgi?fvp=/family/sexuality_and_spirituality/&cmd=rA&cG=43"> ------------- my... (6 Replies)
Discussion started by: georgi58
6 Replies

5. Shell Programming and Scripting

How to remove a temporary file inside gawk

Hi- How can I make the temporary file 0 byte , created inside gawk. I am using system("rm -f temp_orders"); It seems system command is deleting file permanently and I am not able to execute below statement. print ORD_HEAD_FULL >> cFILE; (cFile is temp_orders) (2 Replies)
Discussion started by: ashish_kaithi
2 Replies

6. Shell Programming and Scripting

Remove whitespace after pipe symbol but not inside words

I have a file that looks like this: 102| #2 X 1/4-INCH| 30188| EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #2 X 1/4-INCH| 30188| EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #6 X 1/2"| ... (2 Replies)
Discussion started by: djehresmann
2 Replies

7. Shell Programming and Scripting

Remove everything inside of brackets

I need to use something bash related to remove everything inside of brackets. For example. In the following: abc<def>ghi<jkl>mno the result should be: abcghimno (4 Replies)
Discussion started by: locoroco
4 Replies

8. Shell Programming and Scripting

How to remove the values inside the html tags?

Hi, I have a txt file which contain this: <a href="linux">Linux</a> <a href="unix">Unix</a> <a href="oracle">Oracle</a> <a href="perl">Perl</a> I'm trying to extract the text in between these anchor tag and ignoring everything else using grep. I managed to ignore the tags but unable to... (6 Replies)
Discussion started by: KCApple
6 Replies

9. UNIX for Dummies Questions & Answers

Remove all the subdirectories except latest 5 inside any given directory

I Want to remove all the sub-directories except latest five in any given TGTDIR. Is there a way to do so without making a cd to TGTDIR? I have tried the following but not worked. Thank you. rm -rf `ls -t $TGTDIR | awk 'NR>5'` (20 Replies)
Discussion started by: Devendra Hupri
20 Replies

10. Shell Programming and Scripting

Remove bracket including text inside with sed

Hello, I could not remove brackets with text contents myfile: Please remove the bracket with text I wish to remove: I tried: sed 's/\//' myfile It gives: Please remove the bracket with text A1 I expect: Please remove the bracket with text Many thanks Boris (2 Replies)
Discussion started by: baris35
2 Replies
remove(3)						     Library Functions Manual							 remove(3)

NAME
remove - Removes a file LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <stdio.h> int remove( const char *path ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: remove(): POSIX.1, XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the file to be removed. DESCRIPTION
The remove() function causes a file named by the pathname pointed to by path to be no longer accessible by that name. A subsequent attempt to open that file using that name will fail unless it is created anew. If the path parameter names a directory, remove(path) is equivalent to calling the rmdir() function on that directory. If path does not name a directory, remove(path) is equivalent to unlink(path). NOTES
If the file operated upon by the remove() function has multiple hard links, the link count in the file is decremented and only the speci- fied file name is removed. RETURN VALUES
Upon successful completion, the remove() function returns 0 (zero). Otherwise, a nonzero value is returned. Refer to the unlink() function and the rmdir() function for information on return values. ERRORS
Refer to the unlink() function and the rmdir() function for information on error conditions. RELATED INFORMATION
Functions: link(2), rename(2), rmdir(2), unlink(2) Standards: standards(5) delim off remove(3)
All times are GMT -4. The time now is 03:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy