Difference between revisions of "Shell Tips"

From WikiDLXTV
Jump to: navigation, search
(Added Shell Tips)
Line 38: Line 38:
 
|7 || align="center" | RWX ||Read, write and execute
 
|7 || align="center" | RWX ||Read, write and execute
 
|}
 
|}
:* The permission is a set of 3 numbers in this order from left to right: USER - GROUP - EVERONE. The three digits can be 0-7 as shown in the table on the right:
+
:* <code>'''permission'''</code> is a set of 3 numbers in this order from left to right: USER - GROUP - EVERONE. The three digits can be 0-7 as shown in the table on the right:
 
+
 
:: ex: <code>chmod 000 file1</code> means '''No one''' can access file1, <code>chmod 777 file2</code> means '''Anyone''' can access /write to/execute file2
 
:: ex: <code>chmod 000 file1</code> means '''No one''' can access file1, <code>chmod 777 file2</code> means '''Anyone''' can access /write to/execute file2
 
 
:* '''''chown''' : changes file ownership permissions. The permission set is of 2 parameters going from left to right: USER.GROUP (ex: <code>chown root myfile.txt</code> : Changes the owner of the file to root, <code>chown root.root myfile.txt</code> : Changes the owner and group of the file to root)''
 
:* '''''chown''' : changes file ownership permissions. The permission set is of 2 parameters going from left to right: USER.GROUP (ex: <code>chown root myfile.txt</code> : Changes the owner of the file to root, <code>chown root.root myfile.txt</code> : Changes the owner and group of the file to root)''
 +
* '''nano''' : friendly, easy to use file editor (''ex:'' <code>pico /conf/S00user-script</code> '': edit the custom options user file'')
 +
:* '''vi''' : another editor, tons of features, harder to use at first than nano, read [http://www.washington.edu/computing/unix/vi.html more info here].
 +
* '''grep''' : looks for patterns in files, ex:
 +
: <code>'''grep root /etc/passwd'''</code> : shows all lines with the string '''root''' in file '''/etc/passwd'''
 +
: <code>'''grep -v root /etc/passwd'''</code> : shows all lines that do not match string '''root'''
 +
 +
 +
 +
 +
 +
 +
 +
* '''ln''' : create's "links" between files and directories, ''ex:'' <code>'''ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf'''</code> '': Now you can edit /etc/httpd.conf rather than the original. Changes will affect the original, however you can delete the link and it will not delete the original.''
 +
* last : shows who logged in and when, ex:
 +
: <code>'''last -20'''</code> : shows only the last 20 logins
 +
: <code>'''last -20 -a'''</code> : shows last 20 logins, with the hostname in the last field

Revision as of 04:19, 20 March 2010

<<Page in construction>>

Common Shell Commands

I've put together some of the useful shell commands that are available under WDLXTV (using SSH or Telnet). They're organized alphabetically, so you can easily find a command, their description and how to use it. This guide will continue to be updated and if you would like to add to this guide, please edit after checking the command yourself.

  • ls : list files/directories in a directory, comparable to dir in windows/dos.
ls -al : shows all files (including ones that start with a period), directories, and details attributes for each file.
  • cd : change directory (ex: cd /usr/local/apache will go to /usr/local/apache/)
cd ~ : go to your home directory
cd - : go to the last directory you were in
cd .. : go up a directory
  • cat : print file contents to the screen (ex: cat filename.txt : cat the contents of filename.txt to your screen)
more : like cat, but opens the file one screen at a time rather than all at once (browse through the file, hit Space to go to the next page, q to quit)
tail : like cat, but only reads the end of the file. ex:
tail /var/log/messages : see the last 20 (by default) lines of /var/log/messages
tail -f /var/log/messages : watch the file continuously, while it's being updated
tail -200 /var/log/messages : print the last 200 lines of the file to the screen
  • chmod : changes file access permissions. (usage: chmod permissions filename)
Permission Table
# permission meaning
0 --- No permission
1 --X Execute only
2 -W- Write only
3 -WX Write and execute
4 R-- Read only
5 R-X Read and execute
6 RW- Read and write
7 RWX Read, write and execute
  • permission is a set of 3 numbers in this order from left to right: USER - GROUP - EVERONE. The three digits can be 0-7 as shown in the table on the right:
ex: chmod 000 file1 means No one can access file1, chmod 777 file2 means Anyone can access /write to/execute file2
  • chown : changes file ownership permissions. The permission set is of 2 parameters going from left to right: USER.GROUP (ex: chown root myfile.txt : Changes the owner of the file to root, chown root.root myfile.txt : Changes the owner and group of the file to root)
  • nano : friendly, easy to use file editor (ex: pico /conf/S00user-script : edit the custom options user file)
  • vi : another editor, tons of features, harder to use at first than nano, read more info here.
  • grep : looks for patterns in files, ex:
grep root /etc/passwd : shows all lines with the string root in file /etc/passwd
grep -v root /etc/passwd : shows all lines that do not match string root




  • ln : create's "links" between files and directories, ex: ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf : Now you can edit /etc/httpd.conf rather than the original. Changes will affect the original, however you can delete the link and it will not delete the original.
  • last : shows who logged in and when, ex:
last -20 : shows only the last 20 logins
last -20 -a : shows last 20 logins, with the hostname in the last field