[solved]Locked output file from a Linux command

Archived topics about LMDE 1
Forum rules
User avatar
James_patageul
Level 1
Level 1
Posts: 4
Joined: Tue May 14, 2013 3:40 pm

[solved]Locked output file from a Linux command

Postby James_patageul » Tue May 14, 2013 3:52 pm

Hi people,

I want the content result of a command line output to a file, I have found the solution not too complicated.

so here is my command ->

Code: Select all

su
netsat -lnp | grep citserver | >/var/tmp/output.txt


but when I go to the location var\tmp\output.txt I see that ->
Image
so it seem the file is locked and the content seem empty.

did I must launch caja (the file browser) as SuperUser ?

thx
Last edited by James_patageul on Wed May 15, 2013 11:27 am, edited 1 time in total.
Linux Mint \ Debian \ 201303 MATE 64-bit

User avatar
xenopeek
Level 23
Level 23
Posts: 19376
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Locked output file from a Linux command

Postby xenopeek » Tue May 14, 2013 3:58 pm

Because you first run su, you are running the netstat command as the root user. Hence the file you create is owned by root.

Either change ownership of the file back to yourself, which you also need to do as root (with the chown command), or instead of using su use sudo. As in:

Code: Select all

sudo netstat -lnp | grep citserver > /var/tmp/output.txt

The redirection of the output is done by your shell, before the sudo command is executed. So redirection of output is done as yourself.
Image

User avatar
DrHu
Level 17
Level 17
Posts: 7560
Joined: Wed Jun 17, 2009 8:20 pm

Re: Locked output file from a Linux command

Postby DrHu » Tue May 14, 2013 4:00 pm

/var is a system directory and the output is there except you need root mode (su or sudo) to see it

Or you could simply dump the data to your /home directory, or even /tmp (instead of /var/tmp) you have access to /tmp

Linux FHS..
http://www.meabi.com/linux-fhs-filesyst ... -standard/
https://www.linux.com/learn/tutorials/4 ... tandard-30

User avatar
James_patageul
Level 1
Level 1
Posts: 4
Joined: Tue May 14, 2013 3:40 pm

Re: Locked output file from a Linux command

Postby James_patageul » Tue May 14, 2013 4:20 pm

thank for your fast reply !

DrHu I have try to export either inside /home or even /home/myself

but owner stay root and therefore I cannot delet it (normaly) and the content seem empty
what is strange is inside /home the file of not the lock and under
/home/myself he have the lock !?

xenopeek Yeah with sudo the owner is myself ! but what is weird is that the text file is still empty ! and with out the > /home/myself/output.txt I have a result on the terminal !
Linux Mint \ Debian \ 201303 MATE 64-bit

User avatar
xenopeek
Level 23
Level 23
Posts: 19376
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Locked output file from a Linux command

Postby xenopeek » Tue May 14, 2013 4:25 pm

It will be empty if the grep command returns no matches.
Image

User avatar
James_patageul
Level 1
Level 1
Posts: 4
Joined: Tue May 14, 2013 3:40 pm

Re: Locked output file from a Linux command

Postby James_patageul » Tue May 14, 2013 4:30 pm

but it return results ->
Image

EDIT: OK I found why ! -> next post
Linux Mint \ Debian \ 201303 MATE 64-bit

User avatar
James_patageul
Level 1
Level 1
Posts: 4
Joined: Tue May 14, 2013 3:40 pm

Re: Locked output file from a Linux command

Postby James_patageul » Tue May 14, 2013 4:36 pm

OK When I enter this command

sudo netstat -lnp | grep citserver | > /home/virtua/output.txt

I have a empty file

but when I enter

sudo netstat -lnp | grep citserver > /home/virtua/output.txt (without the second | )

then is working :roll: damnn I'm such a noob :mrgreen:

could you explain me what do exactly the | ?

(I'm new the linux system (normally I admin windows server :oops: )
Linux Mint \ Debian \ 201303 MATE 64-bit

User avatar
xenopeek
Level 23
Level 23
Posts: 19376
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Locked output file from a Linux command

Postby xenopeek » Tue May 14, 2013 4:39 pm

The '|', aka pipe operator, attaches the stdout of the left process to the stdin of the right process. So what one prints as output, the other will read as input. The '>', aka redirection operator, redirects the output to a file. Combining them might indeed not work :wink:

Perhaps a good resource for catching up a bit on the terminal: http://www.flossmanuals.net/command-line/. It covers both redirecting and piping commands.
Image


Return to “Archive”

Who is online

Users browsing this forum: No registered users and 13 guests