![]() |
| Useful commands for administering a linux server |
|
cheryl
|
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
|
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
|
I have just seen the devil. *runs* I'm a nano/pico fan myself, but I also love Windows Great post!!! |
||||||||||||
|
|
|||||||||||||
|
cheryl
|
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
|
<3's notepad/metapad. |
||||||||||||
|
|
|||||||||||||
|
cheryl
|
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
|
||||||||||||
|
|
|||||||||||||
|
pmeserve
HostMySite Tech
|
Cheryl did you just list pine as a text editor?
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
|
oops! Pine should be pico
However, pine does use pico as its text editor if anyone ever did use it |
||||||||||||
|
|
|||||||||||||
|
darrellhyde
Network Administrator
|
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
|
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
|
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:
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:
|
||||||||||||||||
|
|
|||||||||||||||||
|
jmeyers
|
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
|
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 |
|
||
|


