• Post Reply Bookmark Topic Watch Topic
  • New Topic

command not found in Ubuntu  RSS feed

 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

first of all I am using ubuntu 14.04 and recently I decided to learn java by myself through internet tutorials, as a hobby.I follow the tutorial
http://chortle.ccsu.edu/Java5/index.html#21
and I am at chapter 21 now, which is about file redirection. There is a simple exercise there that asks the following

"Write a program that writes ten x's to the screen (modify the HelloWorld.java program). Use file redirection to send the program's output to a text file. Use the DIR command (or in Unix, the ls -l command) to see how many bytes are in the file. Depending on how your operating system implements end of lines, you will see more than 10 bytes."


I can send the output of the program to a .txt file (I have named it ex.txt) but when I try in the terminal the command



I get an error in the terminal



Any ideas of what might be wrong. Is it the command from the tutorial wrong?
 
Claude Moore
Ranch Hand
Posts: 923
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe Ubuntu follows a different sintax for ls command. What if you try with is without NY parameter ?
 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am newbie in ubuntu too, so what do you mean by NY parameter
 
Claude Moore
Ranch Hand
Posts: 923
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a typo, i meant -l param
 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well if I give the command without the -l I get another error
maybe there should be another command to do the job, I'll try to find it out
 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I found a solution. I tried the command and it worked! It prints out (overwrites) the bytes of the ex.txt file in the ex.txt file. Thanks Claude
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claude Moore wrote:Maybe Ubuntu follows a different sintax for ls command.


It doesn't ! will work if the file exists and if it doesn't it will output an error on stderr to the effect


The only thing I can think of is that the OP is actually typing the '>' and does not understand that it is meant to represent the command prompt. If I type

then I get
-l: command not found

Note - using wc will only work for text files and seems an overkill for this problem.
 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard,

I tried the following as well and works OK
It seems that the '>' was in the wrong place in the command

I should have written the 'ls -l' command first and then redirect (>>) the output in the ex.txt file
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike MikeA wrote:I think I found a solution. I tried the command and it worked! It prints out (overwrites) the bytes of the ex.txt file in the ex.txt file. Thanks Claude

Actually, '>>' appends to the target; it doesn't overwrite - at least not in any Unix/Linux I know.

Winston
 
Mike Michalis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston you're right it appends and not overwrites, my mistake I got confused.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File direction is a Java question: moving to a more appropriate forum.

I can confirm that ls is a valid instruction in Ubuntu. Whoever said it was the > that was in the wrong place appears to be correct.
 
Tim Holloway
Saloon Keeper
Posts: 18789
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. I can't believe so much was said on that.

Yes, the ">" is the redirection operator, and the command line ">ls -l ex.txt" makes no more syntactic sense than the arithemetic expression "=x a + b". Unless you're into Polish Notation, anyway.

What that command should do is attempt to execute a command named "-l" with an argument of "ex.txt" and to redirect its output to a file named "ls" in the current directory, which would be created if it did not exist or replaced it it did exist.

Although even that is questionable, since the redirection are expected to follow the command, not preceed it. Some command shells might even attempt to locate a program named ">ls" and execute it instead.

So the correct format would be:



Which would list the contents of the current directory and store the output of the command into a file named "ex.txt" in the current directory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!