What *nix commands do you want to know more about?

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Here's a quick snippet:

To change my above post (the one with all them thar words) from fusetalk to HTML, you can use something like:
cat doc.txt | sed -e 's/\[b\]/\<b\>/g' -e 's/\[\/b\]/\<\/b\>/g' -e 's/\[i\]/\<i\>/g' -e 's/\[\/i\]/\<\/i\>/g' |
tr '\n' '^'| sed -e 's/\^/\<BR\>/g' >doc2.html


Broken down:
cat doc.txt | - This displays the test of doc.txt (which in this case would be the text of my post with all of the fustalkisms in it). The text will be used as the input for the next part of the command:
sed -e 's/\[b\]/\<b\>/g' -e 's/\[\/b\]/\<\/b\>/g' -e 's/\[i\]/\<i\>/g' -e 's/\[\/i\]/\<\/i\>/g' | \ - This is sed. It's pretty complicated, and I barely understand it. Basically, the 's/something/something_else/g' takes every instance of "something" and switches it with "something_else". The backslashes (\) are there as escape characters, making the shell not interpret < or > as anything but < or >. The pipe makes the output of this command be the input for the next command. The last back slash allows me to hit enter and start the rest of the command on the next line instead of continueing the very long command.
tr '\n' '^'| - This command is new in this thread. tr translates or deletes characters. In this case it should change \n (new line character) to a ^. sed doesn't handle new line characters well, so that is why I chose tr. Unfortunately the second string can only be as long as the first string, or I would switch \n with <br> directly. I chose the ^ character because I hadn't previously used it. If anyone knows a better way to do this, LET ME KNOW! ;) The pipe makes this output of this command be the input of the next command:
sed -e 's/\^/\<BR\>/g' - This just switches the ^ character with <BR>. The results of all of this go to:
> doc2.html - This puts the output of all previous commands into the file doc2.html.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Nothinman
And what would you suggest?
Maybe a well known file location. But I would think that a mechanism to export env variables to a global level would also be useful in general.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: kamper
Originally posted by: Nothinman
And what would you suggest?
Maybe a well known file location. But I would think that a mechanism to export env variables to a global level would also be useful in general.

SSH session information probably shouldn't be universally accessible. It's kind of one of those things that you want to be pretty limited.

Anyways, the source is there. ;)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Maybe a well known file location. But I would think that a mechanism to export env variables to a global level would also be useful in general.

A well known file location that wouldn't conflict when being started by multiple users on the same machine? They already use a pipe at /tmp/ssh-<seemingly-random-string>/agent.pid. Do you think they obvuscated the location and locate it via the environment on purpose?

And how global? Every process? Every process owned just by you? Every process only running under the current X session?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Well, the well known file location would have to be user specific and hidden from everybody else so I was thinking of somewhere in ~ but I'm really just spouting off ideas. I guess if they were going to do that the pipe wouldn't have to be located in /tmp anyways...

I realize changing how the environment works is not really practical just for the sake of a single application. Again, I'm just musing. I just figured there's got to be some better way of having two processes locate eachother.

And when did this turn into a session of grilling the people who are looking for help? :p
SSH session information probably shouldn't be universally accessible. It's kind of one of those things that you want to be pretty limited.
Granted. By 'global' I only mean to one user. Something like storing the new value somewhere and then injecting it into the environment whenever a new shell starts.
Anyways, the source is there.
Yup, and maybe someday I will hack it. No time soon though :)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Granted. By 'global' I only mean to one user. Something like storing the new value somewhere and then injecting it into the environment whenever a new shell starts.

New processes already inherit the environment from their parent, which is why it's usually recommended to run ssh-agent from your X login session.

But like I mentioned, one user doesn't really mean much. A user could have multiple X logins, multiple console logins and shells started under screen via ssh. Forcing that change into all of them would mean you could only run a single ssh-agent session per-user. And if there were an odd situation where you had 2 people logged in with the same user, one of them adding a key to the ssh-agent would also add it to the other login's environment which might not be the desired action.

And when did this turn into a session of grilling the people who are looking for help?

We're not trying to be dicks, but it's usually the easiest way to make someone realize what they're proposing isn't as easy as they think =)
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: n0cmonkey
Here's a quick snippet:

To change my above post (the one with all them thar words) from fusetalk to HTML, you can use something like:
cat doc.txt | sed -e 's/\[b\]/\<b\>/g' -e 's/\[\/b\]/\<\/b\>/g' -e 's/\[i\]/\<i\>/g' -e 's/\[\/i\]/\<\/i\>/g' |
tr '\n' '^'| sed -e 's/\^/\<BR\>/g' >doc2.html


Broken down:
cat doc.txt | - This displays the test of doc.txt (which in this case would be the text of my post with all of the fustalkisms in it). The text will be used as the input for the next part of the command:
sed -e 's/\[b\]/\<b\>/g' -e 's/\[\/b\]/\<\/b\>/g' -e 's/\[i\]/\<i\>/g' -e 's/\[\/i\]/\<\/i\>/g' | \ - This is sed. It's pretty complicated, and I barely understand it. Basically, the 's/something/something_else/g' takes every instance of "something" and switches it with "something_else". The backslashes (\) are there as escape characters, making the shell not interpret < or > as anything but < or >. The pipe makes the output of this command be the input for the next command. The last back slash allows me to hit enter and start the rest of the command on the next line instead of continueing the very long command.
tr '\n' '^'| - This command is new in this thread. tr translates or deletes characters. In this case it should change \n (new line character) to a ^. sed doesn't handle new line characters well, so that is why I chose tr. Unfortunately the second string can only be as long as the first string, or I would switch \n with <br> directly. I chose the ^ character because I hadn't previously used it. If anyone knows a better way to do this, LET ME KNOW! ;) The pipe makes this output of this command be the input of the next command:
sed -e 's/\^/\<BR\>/g' - This just switches the ^ character with <BR>. The results of all of this go to:
> doc2.html - This puts the output of all previous commands into the file doc2.html.

Yeah, I learned greek just as fast.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Nothinman
Granted. By 'global' I only mean to one user. Something like storing the new value somewhere and then injecting it into the environment whenever a new shell starts.
New processes already inherit the environment from their parent, which is why it's usually recommended to run ssh-agent from your X login session.
Ok, now I get why you recommended X.
But like I mentioned, one user doesn't really mean much. A user could have multiple X logins, multiple console logins and shells started under screen via ssh. Forcing that change into all of them would mean you could only run a single ssh-agent session per-user.
That actually sounds somewhat convenient (normally, why would you need more than one?).
And if there were an odd situation where you had 2 people logged in with the same user, one of them adding a key to the ssh-agent would also add it to the other login's environment which might not be the desired action.
Ah, you're correct of course. I'm sorta thinking blindly in desktop mode. Although, if you've got 2 people logged in as the same user, you've basically blown away any hopes at inter-user security anyways, right?
And when did this turn into a session of grilling the people who are looking for help?
We're not trying to be dicks, but it's usually the easiest way to make someone realize what they're proposing isn't as easy as they think =)
I'm well aware that it's either not easy or desirable, otherwise someone obviously would have changed something by now ;) I just want to know why not and the easiest way to do that is to say what I think and have it explained to me why I'm wrong. The comment had a :p for a reason ;)

So, to sum that one up then, you guys, if you're using ssh-agent, basically just make sure that your ssh connection happens from a derivative shell of one where you manually started the agent?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
That actually sounds somewhat convenient (normally, why would you need more than one?).

Actually, I don't know. But I do know that I've seen people do it.

Ah, you're correct of course. I'm sorta thinking blindly in desktop mode. Although, if you've got 2 people logged in as the same user, you've basically blown away any hopes at inter-user security anyways, right?

Generally yes, but it happens.

So, to sum that one up then, you guys, if you're using ssh-agent, basically just make sure that your ssh connection happens from a derivative shell of one where you manually started the agent?

Sure, but you can always manually add the ssh-agent environment variables if you want to use it from another shell.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Here's something I'm doing with pipes right now:

cat infile.txt | sort -gu | head -20 >> outfile.txt

The text of infile.txt gets sent through sort, which sorts by number and makes sure all entries are unique. Then the output of that gets piped through head -20, so I only see the top 20. It all then gets appended to outfile.txt.

While typing this I hit esc twice, thinking I was in vi. :p

I also noticed a mistake with what I'm doing. I should be using sort -gur to reverse the output. I want the bigger numbers, not the smaller ones. :(
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: n0cmonkey
Originally posted by: Brazen
Yeah, I learned greek just as fast.

Is the explanation that bad? :p

hahaha, no. It's actually pretty good. Breaking each command down like that and explaining what is getting passed on I think actually helped. In fact, after giving up and pretty much forgetting about the pipe 6 years ago, I think I may be starting to "get it."

By the way, I never actually learned Greek, but I had picked up a little from my roommate in college. So I guess I lied :p
 

DidlySquat

Banned
Jun 30, 2005
903
0
0
here's a forbidden word for you UNIX. Deal with it. Or call your lawyer. I dont care

anyway, what is this thread supposed to be - a slow man page ?
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: DidlySquat
here's a forbidden word for you UNIX. Deal with it. Or call your lawyer. I dont care

anyway, what is this thread supposed to be - a slow man page ?


UNIX is a trademark, Linux isn't even close to being a Unix. At best it's unix-like, or unixish. *nix is just shorter.

And yes, it's a slow manpage. Your sig is long. :(
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
I'm starting to go through my scripting notes. Every time I do something I think is neat, I copy and paste it into little text files so I can use it again later. Unfortunately, I don't document them well. :eek:

I almost had something for "for loops" finished up for posting, but I got confused and hit escape to save it as I do compulsively, and lost it all. IE and vi work differently. :(
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Sometimes while scripting I come across variables that need to be protected. Sometimes I want to add something to the end of the text the variable stands for, instead of creating a new variable. If I do something like (VARIABLE=file): $VARIABLE.txt, "$VARIABLE.txt" may be interpretted as a new variable instead of "file.txt." So instead I use: ${VARIABLE}.txt. The curly braces ({}) protect the variable from the stuff around it.

You don't have to use the braces every time, but I try to just to keep me in the habit of using them. I also think it's a bit cleaner to pick a standard and stick to it. My standard is to use the braces. ;)


The for loop:
for i in `some command` ; do
STUFF TO DO
done

The for loop is pretty simple, and helps out a lot when dealing with a number of files. If you're transferring a bunch of text files you created on your linux system to a Windows machine and want to add ".txt" to all of them you can do something like (from the directory the text files are in:

for i in `*` ; do
mv ${i} ${i}.txt
done



The while loop with read line:
while read line; do
echo ${line}
done < file

There are many ways to use the while loop, but this is one of the ways I use the most.
while read line ; do - This takes the first line of a file and puts it into the variable $line. It also tells the interpreter to move to the next line.
echo ${line} - This line only displays the $line variable's contents.
done - This part of the line tells the while loop that it's time to go back to the top. It'll continue until the EOF.
< file - This part only feeds the contents of "file" into the loop. So the contents of file will be used for the while loop.

I have a list of servers at work. When I want to push a file to all of the servers I can do something like:
while read line; do
scp file.txt ${line}:/home/ddp
done < server_list.txt
 

Soggys1stBrat

Member
Jan 1, 2005
68
0
0
Ok I'm a total newbie in the *nix area. so when I see instructions like this

1. unpack tarball
2. cd lin-seti-<version>
3. ./configure
4. make
5. make install
6. cd
7. adjust .lin-setirc to suit your needs
8. cd lin-seti
9. Start up your internet connection
10. ./lin-seti -t (this downloads the first work unit)
11. follow the instructions of the seti client and download your first work unit
12. ./lin-seti -C 10 (this brings the cache size to 10 units)
13. ./lin-seti -t (this downloads the remaining 9 units)


I'm totally stumped at the unpack tarball. Am I supposed to type these in as commands? And if so where do I type them? If not then how do I do this stuff?
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Originally posted by: Soggys1stBrat
Ok I'm a total newbie in the *nix area. so when I see instructions like this

1. unpack tarball
2. cd lin-seti-<version>
3. ./configure
4. make
5. make install
6. cd
7. adjust .lin-setirc to suit your needs
8. cd lin-seti
9. Start up your internet connection
10. ./lin-seti -t (this downloads the first work unit)
11. follow the instructions of the seti client and download your first work unit
12. ./lin-seti -C 10 (this brings the cache size to 10 units)
13. ./lin-seti -t (this downloads the remaining 9 units)


I'm totally stumped at the unpack tarball. Am I supposed to type these in as commands? And if so where do I type them? If not then how do I do this stuff?

here's a semi-newbie helping out ;)

unpacking a tar: > tar -xvf <name of the tarball>
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Soggys1stBrat
Ok I'm a total newbie in the *nix area. so when I see instructions like this

1. unpack tarball
2. cd lin-seti-<version>
3. ./configure
4. make
5. make install
6. cd
7. adjust .lin-setirc to suit your needs
8. cd lin-seti
9. Start up your internet connection
10. ./lin-seti -t (this downloads the first work unit)
11. follow the instructions of the seti client and download your first work unit
12. ./lin-seti -C 10 (this brings the cache size to 10 units)
13. ./lin-seti -t (this downloads the remaining 9 units)


I'm totally stumped at the unpack tarball. Am I supposed to type these in as commands? And if so where do I type them? If not then how do I do this stuff?
I bolded the parts you should take literally (type them in at the prompt). screw3d provided the instructions for #1 :)

And since when is there an open source seti client? :Q
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: kamper
Originally posted by: Soggys1stBrat
Ok I'm a total newbie in the *nix area. so when I see instructions like this

1. unpack tarball
2. cd lin-seti-<version>
3. ./configure
4. make
5. make install
6. cd
7. adjust .lin-setirc to suit your needs
8. cd lin-seti
9. Start up your internet connection
10. ./lin-seti -t (this downloads the first work unit)
11. follow the instructions of the seti client and download your first work unit
12. ./lin-seti -C 10 (this brings the cache size to 10 units)
13. ./lin-seti -t (this downloads the remaining 9 units)


I'm totally stumped at the unpack tarball. Am I supposed to type these in as commands? And if so where do I type them? If not then how do I do this stuff?
I bolded the parts you should take literally (type them in at the prompt). screw3d provided the instructions for #1 :)

And since when is there an open source seti client? :Q

I think the BOINC client is open.
 

jamesave

Golden Member
Aug 27, 2000
1,610
0
76
what is the command to list out the hardware on a SUN server? trying to figure out how much memory, what is the processors, etc.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: jamesave
what is the command to list out the hardware on a SUN server? trying to figure out how much memory, what is the processors, etc.

You might be able to get that info from the dmesg, but if there's another one I don't know it. :beer:
 

silverpig

Lifer
Jul 29, 2001
27,703
12
81
Originally posted by: n0cmonkey
Originally posted by: kamper
Originally posted by: Soggys1stBrat
Ok I'm a total newbie in the *nix area. so when I see instructions like this

1. unpack tarball
2. cd lin-seti-<version>
3. ./configure
4. make
5. make install
6. cd
7. adjust .lin-setirc to suit your needs
8. cd lin-seti
9. Start up your internet connection
10. ./lin-seti -t (this downloads the first work unit)
11. follow the instructions of the seti client and download your first work unit
12. ./lin-seti -C 10 (this brings the cache size to 10 units)
13. ./lin-seti -t (this downloads the remaining 9 units)


I'm totally stumped at the unpack tarball. Am I supposed to type these in as commands? And if so where do I type them? If not then how do I do this stuff?
I bolded the parts you should take literally (type them in at the prompt). screw3d provided the instructions for #1 :)

And since when is there an open source seti client? :Q

I think the BOINC client is open.

It's not open source. I use lin-seti myself. It's just a cache manager like seti-driver. The BOINC client is open source, but the program that runs the science is still proprietary (don't want people messing with the science).