Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-07-2014, 08:45 AM   #1
Registered: Jun 2013
Posts: 71

Rep: Reputation: Disabled
Interesting Behavior

Im taking a Linux Essentials class at a local community college. Ive been using the command line for some time in one nix environment or another. Im ok .. but I want to fill in the blanks and LPI cert. Anyway ... this was on a lab. The professor didn't go into detail .. and ironically no other student questioned what was going on...

[popeye bin]$ ls -l > file.txt

[popeye bin]$ cat file.txt
total 8
-rw-rw-r-- 1 popeye popeye 16 Oct 7 07:38 file1.txt
-rw-rw-r-- 1 popeye popeye 17 Oct 7 07:38 file2.txt
-rw-rw-r-- 1 popeye popeye 0 Oct 7 07:38 file.txt
Notice the file size of file.txt

[popeye bin]$ ls -l file.txt
-rw-rw-r-- 1 popeye popeye 178 Oct 7 07:38 file.txt

[popeye bin]$
I had to think about this for a few minutes.

It looks like the file is created and ls is executed, before the file is written to...

Is there some order of operation going on ?
Old 10-07-2014, 09:01 AM   #2
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Your shell is doing this: you are right that creation of the output happens before ls produces the listing.

receive command from user
fork into two (almost identical but nevertheless distinguishable) processes
  child process:
    redirect stdout to file.txt (creating new empty file)
    execute "ls -l" with stdout as defined above
    and end ... nothing follows successful execution (of ls)

  parent process:
    wait for the child process to end (and observe exit status)
    prompt user for next input


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
LXer: Interesting new Ubuntu-derived, OS X-inspired distro, interesting revenue (yes, LXer Syndicated Linux News 0 05-01-2009 09:51 AM
very interesting... kessler961 General 9 04-27-2008 05:15 AM
My server was hacked , interesting behavior spotted byteclock Linux - Security 9 12-20-2005 08:36 AM
strange net config behavior - interesting experience... binchin Red Hat 0 09-05-2005 08:07 PM
interesting gmplayer behavior DJOtaku Linux - Software 2 08-12-2005 10:56 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:51 AM.

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