LinuxQuestions.org
Help answer threads with 0 replies.
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 03-25-2012, 11:21 PM   #1
lsteacke
Member
 
Registered: Jul 2007
Distribution: Ubuntu
Posts: 99

Rep: Reputation: 16
What happens when you type 'ls'


Hey all,
So I was recently asked a question and couldn't really come up with a technical answer to it. What exactly happens, in terms of the shell and the operating system when you type the command 'ls'. Answers would be appreciated or links to appropriate reading materials. I suggested stracing it, but does anyone know, in a point by point break down, what happens?

Thanks
 
Old 03-25-2012, 11:30 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Bash fork()s a new subprocess and exec()'s the ls executable. The ls executable is built from the Coreutils sources found here:

http://ftp.gnu.org/gnu/coreutils/coreutils-8.15.tar.xz

My suggestion would be to have a look around that code base. Look for the main() function in the ls-* files, and start from there.

I did write an ls implementation once upon a time for college; I think it was mostly based on stat(), readdir() and friends.

Last edited by jhwilliams; 03-25-2012 at 11:31 PM.
 
Old 03-25-2012, 11:30 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,326

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
Off the top of my head, I'd mention inodes.
If I remember, there's no such thing as files/dirs really, all the metadata is stored in the inodes and then ptrs point to the relevant data blocks ...

https://en.wikipedia.org/wiki/Inode
 
Old 03-25-2012, 11:37 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
After the command is typed and enter pressed (and assuming no variables or patterns to expand in the command), bash goes through aliases, functions, hash table and PATH to determine which executable to run.
 
  


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
mandriva dual boot filesystem type unknown,partition type 0x7 llearner Linux - Newbie 2 01-24-2010 02:03 PM
Dual Boot Vista Suse 10.2 error setting type of partition to type 82 jmp559 Linux - General 1 05-15-2008 06:40 PM
Warning ___ specifies undefined mime type/service type mbvpixies78 Linux - Software 0 12-29-2007 10:25 PM
installing redhat 8.0 when text login in I cannot type password?? I type root scrist Linux - General 4 04-22-2006 02:20 AM


All times are GMT -5. The time now is 10:02 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