Reply to topic
Useful commands for administering a linux server
cheryl


Joined: 17 Apr 2004
Posts: 84
Location: Newark, DE
Reply with quote
If anyone is new to administering a linux server, here are some useful commands to keep in mind:
ls - lists files in the specified directory - if one is not listed, then the current working directory
top - shows processes in order of how much CPU they are using
ps - shows a list of processes running on the server
tail - shows the last 10 lines in a file
head - shows the first 10 lines in a file
cat - shows a whole file
grep - displays all the lines of a file that contain your search phrase
find - can be used to locate files based on certain criteria
less / more - used to read through a file
vi / pine / emacs - useful text editors

You can find a list of all linux commands and more information about their arguments at http://www.ss64.com/bash/
Useful Links for VI
rj


Joined: 17 Jun 2004
Posts: 34
Reply with quote
As Cheryl mentioned its important to learn the basic commands to make your way around Linux. It is also equally important to learn to make your way around a text editor as well for changes to files/ scripts you'll be making. I personally prefer to use VI because of its simple layout yet powerful features.
From what I found an excellant resource here is:
The VI Lovers Homepage
http://thomer.com/vi/vi.html

Enjoy!
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
Shocked

I have just seen the devil. *runs*

I'm a nano/pico fan myself, but I also love Windows Wink Still, with a great resource like that I'm not lost with VI. The trouble with VI comes, for me, with the lack of readily available documentation.

Great post!!!
cheryl


Joined: 17 Apr 2004
Posts: 84
Location: Newark, DE
Reply with quote
Josh, I made up a quick list of all the most useful commands I have used in vi - just remember to go to edit mode from command mode, hit the i button and to leave edit mode and go back to command mode, hit the esc button.

CTRL F Page down
CTRL B Page up

0 Moves to the beginning of a line
$ Moves to the end of a line
xG Moves the cursor to the beginning of line x
/pattern Searches down from current position to pattern
?pattern Searches up from current position to pattern

a appends text after cursor
A appends text at end of line
o creates a blank line beneath current line
O creates a blank line above current line

x Deletes the character the cursor is on
dd cuts a line
dw deletes a word
d$ deletes from cursor to end of line

cw Changes a word
c$ Changes from current cursor point to end of line
~ Changes case of current character
J Joins two lines
. redo last command
u undo last command
rx Replaces current character with x
yy copies current line
p pastes current cut/copied line beneath current line

Rfile Insert filename after current cursor position
w saves a file
q exits a session, do q! to exit without saving changes
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
Shocked see that whole command/edit mode hurts my head

<3's notepad/metapad. Wink
cheryl


Joined: 17 Apr 2004
Posts: 84
Location: Newark, DE
Reply with quote
I used to feel the same way, but after time, it became second nature..now when I use notepad and homesite instead of ctrl-s to save, I occasionally hit :w Laughing
pmeserve
HostMySite Tech

Joined: 19 Mar 2004
Posts: 178
Reply with quote
Cheryl did you just list pine as a text editor? Laughing

Anyway, the command I like is lsof, which gives a list of all open files and who's using them. What I like best is that I know of no Windows equivelent, and its usually Windows thats getting the "file in use" errors to begin with.
cheryl


Joined: 17 Apr 2004
Posts: 84
Location: Newark, DE
Reply with quote
oops! Pine should be pico Embarassed
However, pine does use pico as its text editor if anyone ever did use it Smile
darrellhyde
Network Administrator

Joined: 25 Mar 2004
Posts: 8
Reply with quote
Since we're on the subject, I guess I'll throw in a few of my command-line goodies.

First off, there's ps auxwf - this is a argument combo for ps. It gives you the full list of system processes, along with their full command-line path and arguments, and it shows you a nice parent / child process heirarchy.

Next there's cut. cut rules - particularly because I've always been too lazy to learn sed or awk. With cut, you take a line of text, desingate a delimiter, and tell cut which portion, as defined by the delimiter that you specified, to print out. For example, if you wanted to split a line of text on the -'s and print out the second chunk, you'd pipe the text to:

cut -d "-" -f 2

Its a beautiful thing.
cheryl


Joined: 17 Apr 2004
Posts: 84
Location: Newark, DE
Reply with quote
I have to admit, one of my favorite commands is cat, because it has so many uses than just displaying the contents of a file. Many, many, many times when I try to copy and paste information using vi, all of my formatting is completely lost or messed up. However, with using cat, I can just do:
cat > <filename>
paste my contents into the prompt, and hit ctrl-d, and stuff is instantly inserted into the file.
The same goes for adding to the end of the file, using >> instead of >
darrellhyde
Network Administrator

Joined: 25 Mar 2004
Posts: 8
Reply with quote
Netstat is another gem. Infinitely useful for determining what ports a machine is listening on, and what is listening on those ports. For example, let's say you wanted to know what was listening on port 123. - you'd do something like this:

Code:

[root@kenobi root]# netstat -pan | grep 123
udp        0      0 192.168.8.67:123        0.0.0.0:* 1944/ntpd

And voila - you'd know that ntpd was listening on port 123.

Another useful argument is -s. You can use netstat -s to give a report detailing the total number of ICMP and UDP packets recieved, as well as the total number of TCP sessions both past and currently active. A snippet from the output looks like this:

Code:

[root@kenobi root]# netstat -s
Ip:
    137819 total packets received
    0 forwarded
    0 incoming packets discarded
    136488 incoming packets delivered
    36974 requests sent out
Icmp:
    12 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 4
        echo replies: 8
    65 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 65
jmeyers


Joined: 11 Nov 2004
Posts: 6
Reply with quote
Another usful comman is awk

you can use it in many variations to grab information from files....especially logs

here is an example

cat log_file | awk {'print $1'} | sort | uniq

the will cut out the first secution...for example an ip address.... then sort puts them in order.....then uniq gets rid a duplicates

try grabbing different character sets by changing print $#.

you can also obtain very specific information by using multiple command in one...for example

cat log_file | awk {'print $1'} | cut -f1 -d "." | sort| uniq

This would be used if for some reason you wanted to display only the first octect of a list of ips

This takes some time to master so go have fun with it......
rvandegrift
HostMySite Tech

Joined: 17 Jan 2005
Posts: 13
Reply with quote
jmeyers wrote:
Another usful comman is awk


While you're at it, a little bit of sed can be very powerful as well. All you need is the search and replace command:

$ echo "testing" | sed s/testing/TESTING/g
TESTING

That form will replace all occurances of the first word with the second. If you leave off the "g" at the end, it'll only replace the first. This lets you do useful things like batch renaming a bunch of files:

$ ls
myfile1 myfile2 myfile3 myfile4 myfile 5
$ for i in *; do mv $i `echo $i | sed s/myfile/image/g`.jpg; done
$ ls
image1.jpg image2.jpg image3.jpg image4.jpg image5.jpg


This goes crazy places quickly!
Useful commands for administering a linux server
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic