LinuxQuestions.org
Visit Jeremy's Blog.
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 12-10-2007, 10:56 AM   #1
krs4444
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Rep: Reputation: 0
Post Recursivity


Hello,

I need a script which lists all files in directories (recursively). The root dir will be passed as argument.
I want to compile this script with command: cc <script_filename.c> -o <filename>

Have anyone experience with that?

I appreciate all your answers!
 
Old 12-10-2007, 11:12 AM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Well you don't compile scripts, first of all. What you are talking about it writing something in C/C++.

If you want a recursive listing of files, you can already do that on the command line without writing a program to do it. Or are you just trying to do this for your own knowledge?
 
Old 12-10-2007, 11:41 AM   #3
terrio
LQ Newbie
 
Registered: Jan 2007
Location: Halifax, NS
Distribution: Linux Mint
Posts: 29

Rep: Reputation: 15
Homework perhaps?
 
Old 12-10-2007, 12:16 PM   #4
krs4444
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Original Poster
Rep: Reputation: 0
ou, yes, of course it is not script i'm sorry.

Yes, it is a part of my school project, but I want to know something about that. I can read C/C++ code, but I am newbie in Linux and then I dont know how to do that.

Google found something but it compiled with errors...

Thanks for your replies
 
Old 12-10-2007, 05:00 PM   #5
jlarsen
Member
 
Registered: Jan 2005
Location: Dallas, TX
Distribution: Slackware 14.1
Posts: 80

Rep: Reputation: 15
Can't help you with the C part of it, but try typing the following at a command line:
du
and also
man du
 
Old 12-10-2007, 05:17 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
It would do you a dis-service to just give you code to solve your homework problem. However thank you for being clear that it is homework. I am happy to point you in the right direction.

The function calls you need to know about to get directory listings are:
  • opendir
  • readdir
  • closedir
These are part of the standard C library. You can get detailed documentation on each by looking in section 3 of the manual. e.g. to see the documentation for opendir, open a terminal and enter the command:
Code:
man 3 opendir
You might also need to use access (which is a system call, and as such is documented in section 2 of the manual).

To build a C program, you can use the gcc program (this stands for GNU C Compiler). C++ programs are built using g++. Assuming your program code is all in one file called myprog.c, the command to compile and link is simply:
Code:
gcc -g myprog.c -o myprog
The -g includes debugging symbols in your binary which makes it possible to trace the code using gdb (the GBU DeBugger).
 
Old 12-11-2007, 02:31 PM   #7
krs4444
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Many many THANKS matthewg42,

I am glad of your answer and wish you the best in the future!

Once again, Thank you
 
Old 12-11-2007, 04:10 PM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
No problem. If you have any further questions please ask. People here (me included) are reluctant to post solutions to homework questions, but so long as the questioner shows that they have tried something and ask about specific points, they will get lots of answers.

So if you have problem with a specific build error, or maybe some segment of the code does something inexplicable, post what you have done (code in [code] tags to aide readability), and you will probably get lots of helpful answers
 
  


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



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

All times are GMT -5. The time now is 07:47 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
Open Source Consulting | Domain Registration