LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-20-2015, 11:53 AM   #1
Raakh5
Member
 
Registered: Mar 2012
Posts: 169

Rep: Reputation: Disabled
UNIX shell that supports commands in C/C++ language.


Hello,

I want to write program that run on Unix Shell and execute the following commands:
  1. rm
  2. mv
  3. mkdir
  4. rmdir

What I did so far:
Code:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/syslimits.h>
#include <ftw.h>


/* Call unlink or rmdir on the path, as appropriate. */
int
rm( const char *path, const struct stat *s, int flag, struct FTW *f )
{
    int status;
    int (*rm_func)( const char * );

    switch( flag ) {
    default:     rm_func = unlink; break;
    case FTW_DP: rm_func = rmdir;
    }
    if( status = rm_func( path ), status != 0 )
        perror( path );
    else
        puts( path );
    return status;
}


int
main( int argc, char **argv )
{
    while( *++argv ) {
        if( nftw( *argv, rm, OPEN_MAX, FTW_DEPTH )) {
            perror( *argv );
            return EXIT_FAILURE;
        }
    }
    return EXIT_SUCCESS;
}
Thanks in anticipation
 
Old 11-20-2015, 12:20 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,985

Rep: Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315Reputation: 4315
Quote:
Originally Posted by Raakh5 View Post
Hello,
I want to write program that run on Unix Shell and execute the following commands:
  1. rm
  2. mv
  3. mkdir
  4. rmdir
What I did so far:
Thanks in anticipation
Thanks for WHAT? You haven't actually asked a question...you've just told us what you want to do, and posted some code. Perhaps if you said what isn't working, what error(s)/message(s) you get, maybe we could help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
best way to automate shell commands - shell script or python scripts or something els parangsaraf Linux - Newbie 11 08-08-2012 06:17 PM
[SOLVED] Invoking UNIX shell commands from HTML webpage ixcel87 Programming 8 05-12-2010 03:22 PM
Is it necessary to know ' C ' language to learn Unix Mani76 *BSD 4 02-20-2007 11:55 AM
LXer: 3dconnexion Supports Unix/Linux for SpacePilot LXer Syndicated Linux News 0 05-08-2006 08:54 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration