General information
cmd> Finger soonlim //print out info about user soonlim
cmd> Date //print date
cmd> Who // who is currently log in to this system
cmd> cat /proc/cpuinfo // view cpu info
cmd> cat /proc/meminfo //view memory info
cmd> hostname // name of hosting machine
cmd> ifconfig // ip info
SH |
.Profile ( login.com,
home dir) |
BASH |
.bashrc |
CSH |
.cshrc |
TCSH |
.tcshrc |
-user info is in /etc/passwd
Back |
Change mode chmod 135
filename //user, group, other ,rwx
User |
Group |
Other |
RW- |
R-- |
--- |
6 |
4 |
0 |
|
Change Directory
cmd> cd .. //back one step
cmd> cd / //back to top of tree
cmd> cd ~ = cd //back to home directory
cmd> cd dir_name // move to directory
|
Cat& Vi
cmd> Cat file // view
cmd> vi file // edit
cmd> Setup emacs,
emacs file
Back |
Making Directory
cmd> mkdir dir_name |
Printing
cmd> Print filename printer
cmd> Setenv Printer Jwb231 //set default printer Jwb231
|
SetEnv
1. pwd //show current position
2. echo $PATH // show path
3. echo $SHELL //view shell
4. echo $PRINTER //view default printer
ECHO // print the value of variable, $ preceded variable as
argument to echo
|
Listing
cmd> ls -aq //list out all file starting with . or /
cmd> ls -R //* listing all directory and its inside file
cmd> ls -L // listing all file infomation
|
Copy
cmd> cp oldfile newfile // copy content of oldfile to newfile
Back |
Move
cmd> mv odlfilename newfilename //
cmd> mv directory1 directory2 // Move A cmd> >B
|
Remove
cmd> rm filename //detele file
cmd> rmdir dir_name |
Search
cmd> less filename.txt /keyword
cmd> grep keyword filename.txt
cmd> grep -i keyword filename.txt // ignore upper&lower
case
|
Head | Tail
cmd> head filename // display first 10 lines (default) of
file
cmd> head -n 20 filename // first 20 lines
cmd> Tail -n 20 index.php //print last 20
, def is 10
cmd> Tail +20 index.php //display 10 lines
starting from line 20th
cmd> tail --help
Back
|
Word Count
cmd> wc -w filename.txt // count # of word in file
cmd> wc -l filename.txt // count # of line in file
|
Tar
cmd> tar tvzf foo.tar.gz // extract directories and files
from compressed archive
cmd> tar xvzf foo.tar.gz // extracts the files NOT directories
create tar file
tar -cvvf file.tar *.* /var/www/*.php // create tar file ( collection
into single file uncompressed)
tar -cvvf file.tar.gz // compressed single file
Extracting from tar file
tar -xvvf myfile.tar
|
Du (Disk Usage)
cmd> du //display disk usage of current directory
cmd> du -s //display only total disk usage
cmd> du -s -k // some versions of Unix need cmd> k to
report kilobytes
Back |
Redirection
cmd> cat > list1 // type in banana, apple, will go to list1
file
Append
cmd> cat list1 list2 >> list3 // catatenate content
list1, list2 append to list3
|
Environment Variable
1. env // listing
current environment variable
home=?
pwd=?
shell=?
mail=?
logname=?
term=?
|
REGULAR EXPRESSION
1: . //any character
2: * //as many char as possiblev /xx.*y/
3: ^ //begining of the line
4: $ // end of the line
5: /[fT]red/ // looking for fred or Fred
/[0cmd> 9]/ // all character range 0 to 9
|
Pipeline
1. who | grep Sue // pipeline [|] , who's output as input of
grep, look for Sue
2. who | wc -l // how many line is printed
3. ls | more
4. grep 'hi there' file //find file containing 'hi there'
Back |
Spell
1. spell filename // print out the words not in dictionary
2. spell filaname > error // those error words will be sent
to error
3. spell filaname >> error // append those wrong spell
word to error
4. spell < file1 > file2 // check spell in file1 and put
in file2
|
Troff
1. $ troff big_file & // formating big file at back ground,
can run
another command , no wait
2. $ $ troff big_file > output &
Back |
Crontab ( schedule job to
execute at specific date/time)
1. crontab cron.txt // install filename as crontab file
2. crontab -l //display content of crontab file
3. crontab -r //remove crontab file
Disabled email
1. put " >/dev/null 2>&1"
at the end of command
eg.
MAILTO=user@domain.com
30 23 * * * /home/username/www/cgi-bin/members.cgi >/dev/null
2>&1
[min , hour , day/month , month , day/week]
Generate logfile
eg
30 18 * * * rm /home/someuser/tmp/* > /home/cronlogs/file.log
Back
|
MySqlAutoBackup
1. Create backup.sh
-mysqlbak.sh
-web.sh
Restore: restoremysql.sh
2. place this file into cron job using following
- create cronjob.sh
- place following line into cronjob.sh
30 2 * * 0-6 /mysqlbak/web.sh
30 23 * * 0-6 /mysqlbak/mysqlbak.sh
- crontab cronjob.sh
//install file as cronjob file
- Crontab -l /
/check if it is installed
Back |
Redirection
1. ls -l > myfile.txt // output to myfile.txt
2. date >> myfile.txt // append to the end of myfile.txt
3. cat < myfile // take input from myfile
stdin =0 keyboard
stdout=1 screen
stderr=2 standard error
$ rm bad_file_name111 2>er.txt // forward error msg to er.txt
standard output (stdout) to standard error (stderr) device.
eg 1 >&2
Back |
Command args
$# = number of args
$0 = script filename
$1 = 1st arg
$2 = 2nd arg
$* = all arguements
Back |
Wildcard
? =1 char
[A-E] = range
[ABC] =match one of those |
Expr
1. expr 3 + 4
2. expr 4 - 2
3. expr 4 \* 6
4. expr 8 / 2
5. expr = , \>= ,\<= , != |
|