2014年3月19日星期三

Linux Commands for Beginners lesson 19 -- expr,let commands

In this part,I will show you how to do some arithmetic calculation in Bash.

1.COMMAND:
      expr
  DESCRIPTION:
       Print  the  value of EXPRESSION to standard output.
  SYNOPSIS:
       expr EXPRESSION
       
Example:
root@piniheaven:~# expr 1 + 1
2
root@piniheaven:~# expr 2 - 1
1
root@piniheaven:~# expr 4 / 2
2
root@piniheaven:~# expr 2 \* 2  #Tip: when you want to do some multiplication,you should use backslash
4



2.COMMAND:
     let
 DESCRIPTION:
     carry out arithmetic operations on variables. 

Example:
root@piniheaven:~# let " val=(1+1)*2"  # will compute 2 times 2 and assign the result to the variable "val".
root@piniheaven:~# echo $val    #print variable val
4

Linux Commands for Beginners lesson 18 -- Finding Files

In this part, I demonstrate how to find files.

1.COMMAND:
      find
DESCRIPTION:
   search for files in a directory hierarchy

SYNOPSIS:
       find <path> <fileName>
OPTION:
     -mtime n   File's data was last modified n*24 hours ago.
     -name      Base of  file  name  

Example:
If you remember the file's name,you can specify a path to find it out.
root@piniheaven:~# find /root/ -name find.txt
/root/tutorial/find.txt


Even you can't remember what the exactly file name is,you still can find it out.
root@piniheaven:~# find /root/ -name fin*
/root/tutorial/find.txt



Find out files that was last modified 24 hours ago.
root@piniheaven:~# find /root/tutorial/ -mtime  -1
/root/tutorial/
/root/tutorial/.find.txt.swp
/root/tutorial/poem.txt
/root/tutorial/find.txt

Linux Commands for Beginners lesson 17 -- Head and Tail Command

In this part, I go over both the head and tail commands.

1.COMMAND:
     head
DESCRIPTION:
     Print  the  first  10 lines of  FILE to standard output. 
SYNOPSIS:
       head [OPTION]... [FILE]...
OPTION:
     -n, --lines
              print  the first n lines instead of the first 10;


2.COMMAND:
    tail
DESCRIPTION:
    Print the last 10 lines of FILE to standard output.
SYNOPSIS:
    tail [OPTION]... [FILE]...
OPTION:
     -n, --lines      output the last K lines, instead of the last 10;


Examples:
root@piniheaven:~/tutorial# ls
poem.txt
root@piniheaven:~/tutorial# head poem.txt   # Print  the  first  10 lines of  poem.txt to standard output.
nt you to know
one thing.

You know how this is:
if I look
at the crystal moon, at the red branch
of the slow autumn at my window,
if I touch
near the fire
the impalpable ash
root@piniheaven:~/tutorial# head -4 poem.txt   # Print  the  first 4 lines of poem.txt to standard output.
nt you to know
one thing.

You know how this is:
root@piniheaven:~/tutorial# tail poem.txt    # Print  the last  10 lines of poem.txt to standard output.
you feel that you are destined for me
with implacable sweetness,
if each day a flower
climbs up to your lips to seek me,
ah my love, ah my own,
in me all that fire is repeated,
in me nothing is extinguished or forgotten,
my love feeds on your love, beloved,
and as long as you live it will be in your arms
without leaving mine
root@piniheaven:~/tutorial# tail -3 poem.txt    # Print  the last 3 lines of poem.txt to standard output.
my love feeds on your love, beloved,
and as long as you live it will be in your arms
without leaving mine

Linux Commands for Beginners lesson 16 -- The Watch Command

In this part, I talk about the watch command.

1.COMMAND :
      watch
  DESCRIPTION :
      execute a program periodically, showing output fullscreen
  SYNOPSIS :
       watch [option] <command>
   OPTION :
       -n :  By default, the program is run every 2 seconds; use -n  to specify a different interval.
   command: any linux command you want to type
Example :
[piniheaven@localhost ~]$ watch -n 10 free -m  #Every 10.0s free -mwill be executed automatically
Every 10.0s: free -m                                    Tue Sep  3 17:48:56 2013


             total       used       free     shared    buffers     cached
Mem:          5690       1388       4301          0         82        620
-/+ buffers/cache:        685       5004
Swap:            0          0          0

Linux Commands for Beginners lesson 15 -- du,df,free commands

 In this part, I talk about viewing system resources.


1.COMMAND :
       df 
DESCRIPTON :
       report file system disk space usage
SYNOPSIS :
       df [OPTION]... [FILE]...
OPTION :
      -h, --human-readable
Example :
[piniheaven@localhost ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1               15G  5.4G  9.0G  38% /
tmpfs                      2.8G  884K  2.8G   1% /dev/shm




2.COMMAND :
     du
DESCRIPTION :
     estimate file space
SYNOPSIS :
     du [OPTION]... [FILE]...
OPTION :
     -s, --summarize
              display only a total for each argument
     -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
Example :
[piniheaven@localhost ~]$ ls
Desktop            Documents  Music     Public        SolftWare  tutorial
distribute-0.6.49  Downloads  Pictures  Python-2.7.3  Templates  Videos
[piniheaven@localhost ~]$ du -sh Videos
254MVideos




3.COMMAND :
      free
DESCRIPTION :
      Display amount of free and used memory in the system
SYNOPSIS :
       free [-m]
OPTION :
      -m switch displays it in megabytmegabytes.
Example :
[piniheaven@localhost ~]$ free-m
             total       used       free     shared    buffers     cached
Mem:          5690       1736       3953          0         74        615
-/+ buffers/cache:       1046       4644
Swap:            0          0          0
Explanation:
Actual Used Physical Memory (Memory Used by Apps) :1046 MB
Actual Free Physical Memory (Memory Available For Apps) :4644 MB


If you want to know more about what is the difference between buffer and cache memory,you can click following link.

Linux Commands for Beginners lesson 14 -- the grep command

In this part,I wil show you the basis of  Regular Expressions and the grep command


1.Command:
     grep
  DESCRIPTION:
     print lines matching a pattern

  SYNOPSIS:
     grep [OPTIONS] PATTERN [FILE...]
  OPTION:
    -n, --line-number         print line number with output lines


Regular expressions made up of anchors,character sets,modifiers
Anchors:specify the position
^ :at the beginnig of a line
$ :at the end of a line
Tips:If ^ is not placed at the beginning ,or $ at the end,the two won't act as anchors anymore

character sets:what is seached


Example:
root@piniheaven:~/tutorial# ls
A Girl.txt
root@piniheaven:~/tutorial# cat -n A\ Girl.txt
     1    the tree has entered my hands
     2    the sap has ascended my arms
     3    the tree has grown in my breast-
     4    downward
     5    the branches grow out of me, like arms
     6  
     7    tree you are
     8    moss you are
     9    you are violets with wind above them
    10    a child - so high - you are
    11    and all this is folly to the world


print lines contain words "tree"   
root@piniheaven:~/tutorial# grep 'tree' A\ Girl.txt
the tree has entered my hands
the tree has grown in my breast-
tree you are

print lines contain word "tree" and print which line they are in
root@piniheaven:~/tutorial# grep -n 'tree' A\ Girl.txt
1:the tree has entered my hands
3:the tree has grown in my breast-
7:tree you are


print lines start with word "tree" and print which line they are in
root@piniheaven:~/tutorial# grep -n ^'tree' A\ Girl.txt
7:tree you are


print lines contain word "are" and print which line they are in
root@piniheaven:~/tutorial# grep -n 'are' A\ Girl.txt
7:tree you are
8:moss you are
9:you are violets with wind above them
10:a child - so high - you are



print lines end with word "are" and print which line they are in
root@piniheaven:~/tutorial# grep -n 'are'$ A\ Girl.txt
7:tree you are
8:moss you are
10:a child - so high - you are



Matching Character Sets
--"abc" finds lines with "abc" in them
--match any character with "."(dot)
--specify a range with []
  [123] - lines that contain 1,2 or 3
  [0-9] - lines that contain at least a number
  [A-Za-z0-9] - lines that contain at leas a letters or a numbers


Example:
Find words start with letter 'm' and follow with a any character
root@piniheaven:~/tutorial# grep -n 'm.' A\ Girl.txt
1:the tree has entered my hands
2:the sap has ascended my arms
3:the tree has grown in my breast-
5:the branches grow out of me, like arms
8:moss you are

Find words start with letter 'a' or 'b'
root@piniheaven:~/tutorial# grep -n ^'[ad]' A\ Girl.txt
4:downward
10:a child - so high - you are
11:and all this is folly to the world


print lines start with a letter range from 'a' to 'm'
root@piniheaven:~/tutorial# grep -n ^'[a-m]' A\ Girl.txt
4:downward
8:moss you are
10:a child - so high - you are
11:and all this is folly to the world

Tips:
If you want to search for "[" or "]",you should use backslash "\
"
Example:
[\]] - search lines with "]" in them



modifiers:specify how many times the previous charater set is repeated
* - matches zero or more copies of the chars
[]\{1,4\} - lines that have between 1 to 4 mathes
\<word\> - searches for a specific and separate word

Example:

root@piniheaven:~/tutorial# ls
A Girl.txt  essay.txt
root@piniheaven:~/tutorial# cat -n essay.txt
     1    a
     2    aa
     3    aaa
     4    aaaa
     5    aaaaa
     6    aaaaaa
     7  
     8    abc
     9    abbc
    10    abcc

print lines contain word that mach [b-c][b-c]
root@piniheaven:~/tutorial# grep -n '[b-c]\{2,3\}' essay.txt
8:abc
9:abbc
10:abcc


If you want to just search specify word,following command failed to work.
root@piniheaven:~/tutorial# grep -n 'aa' essay.txt
2:aa
3:aaa
4:aaaa
5:aaaaa
6:aaaaaa

therefore,you can type command like this
root@piniheaven:~/tutorial# grep -n '\<aa\>' essay.txt
2:aa

Linux Commands for Beginners lesson 13-- which and whatis commands

In this tutorial, I talk about the which and whatis commands.
1.COMMAND:
       which
  DESCRIPTION:
      locate a command


SYNOPSIS
       which  commandName


Example:
piniheaven@fish:~$ which ls
/bin/ls
piniheaven@fish:~$ which nano
/usr/bin/nano


2.COMMAND:
     whatis 
  DESCRIPTION:
     display manual page descriptions


SYNOPSIS
       whatis  commandName


Example:
piniheaven@fish:~$ whatis firefox
firefox (1)          - a free and open source web browser from Mozilla
piniheaven@fish:~$ whatis ls
ls (1)               - list directory contents

Linux Commands for Beginners lesson 12 -- Create Your Own Commands Via alias

In this part, I will show you how to create your own commands via alias




1.COMMAND:
    alias
  DESCRIPTION:
    The alias command can be useful if you want to create a 'shortcut' to a command.
  SYNOPSIS:
    alias name='command'


 TIPS:
    To see a list of aliases set up on your linux, just type alias at the prompt.

Example:
piniheaven@fish:~/Documents$alias    #list aliases set up on your system
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'

alias ls='ls --color=auto'

piniheaven@fish:~/Documents$ aliasMyLs='ls -l'   #create an alias of 'ls -l'
piniheaven@fish:~/Documents$ ls
assemble  C++primer_ex  C++primer_note  Ebook  linux  MyScript  QT_ex  QT_note  tutorial
piniheaven@fish:~/Documents$ MyLs
total 36
drwxrwxr-x  4 piniheaven piniheaven 4096 Aug 22 12:16 assemble
drwxrwxr-x  2 piniheaven piniheaven 4096 Jul 19 14:12 C++primer_ex

......
......
drwxrwxr-x  2 piniheaven piniheaven 4096 Jul 19 00:21 QT_note
dr-xr-xr-x  2 jack       piniheaven 4096 Aug 25 21:42 tutorial



2.COMMAND:
    unalias
  DESCRIPTION:
    unalias command is used to remove an alias (see alias).
  SYNOPSIS:
    unalias commandName


Example:
piniheaven@fish:~/Documents$ unalias MyLs     #unalias Myls command
piniheaven@fish:~/Documents$ MyLs
MyLs: command not found

Linux Commands for Beginners lesson 11 -- Creating Your First Scripting

 In this part, I give you an introduction to scripting.


Example:

Step1: create a scripting
piniheaven@fish:~/Documents$nano MyScript  
piniheaven@fish:~/Documents$ cat MyScript 
#!/bin/bash          
#specify using  bash shell
#you can create any linux command here
  
 ls
 Hello="Hello,my first scripting!"
 echo $Hello



Step 2: give MyScript execute permission
piniheaven@fish:~/Documents$ chmod u+x MyScript   


piniheaven@fish:~/Documents$ ls -l
total 36
drwxrwxr-x  4 piniheaven piniheaven 4096 Aug 22 12:16 assemble
......
......
-rwxrw-r--  1 piniheaven piniheaven  146 Aug 27 17:02 MyScript
dr-xr-xr-x  2 jack       piniheaven 4096 Aug 25 21:42 tutorial


Step 3: execute MyScript
piniheaven@fish:~/Documents$./MyScript      
assemble  C++primer_exC++primer_noteEbook  linux  MyScriptQT_ex  QT_notetutorial
Hello,my first scripting!

Linux Commands for Beginners lesson 10 -- Echo And Creating Variables

In this part, I introduce the echo command as well as creating variables.
 This tutorial is pretty easy,but very important to bash scripting which I will introduce in following tutorials.


1.COMMAND:
     echo
  DESCRIPTION:
     display a line of text
  SYNOPSIS:
     echo string


Example:
piniheaven@fish:~/Documents$ echo"Hello,CSDN"
Hello,CSDN

2.Creating variable and calling variable

Example:
piniheaven@fish:~/Documents$ Hello="Hello,CSDN" #create variable
piniheaven@fish:~/Documents$ echo$Hello         #call variable
Hello,CSDN

Linux Commands for Beginners lesson 9 -- chmod command

  In this part, I go over changing permissions of files and folders.

 
1.COMMAND:
    chmod
  DESCRIPTION:
     change file mode bits
  SYNOPSIS:
     chmod [OPTION] [ugoa][+-=][rwx]  FILE
   
  OPTION:
     -R recursive, include objects in subdirectories
   
   u user the owner of the file
   g groupusers who are members of the file's group
   o othersusers who are neiter the owner of the file nor members of the file's group
   a allall three of the above, same as ugo

   + adds the specified modes to the specified classes
   - removes the specified modes from the specified classes
   = the modes specified are to be made the exact modes for the specified classes


   r read    read a file or list a directory's contents
   w writewrite to a file or directory
   x executeexecute a file or recurse a directory tree



    If you have any problem in reading following example,maybe you need to know more about file permission.Want more information?You can click my previous tutorial File Permission


Example:
 
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rw-rw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents/tutorial$ 
sudo chmod u+x essay.txt #give user the permission to execute essay.txt
[sudo] password for piniheaven: 
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt


piniheaven@fish:~/Documents/tutorial$ sudo chmodu-r essay.txt #remove user's permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
--wxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt


piniheaven@fish:~/Documents/tutorial$ sudochmod uo+r essay.txt#give user and others the permission of reading essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt




piniheaven@fish:~/Documents/tutorial$ sudo chmod a=x essay.txt  #assign user,group and others only the permission to execute essay.txt
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
---x--x--x 1 jack piniheaven 0 Aug 25 21:42 essay.txt


piniheaven@fish:~/Documents/tutorial$sudo chmodugo+rwx essay.txt  #assign user,group and others with the permission of read,write and excute
piniheaven@fish:~/Documents/tutorial$ ls -l
total 0
-rwxrwxrwx 1 jack piniheaven 0 Aug 25 21:42 essay.txt


piniheaven@fish:~/Documents/tutorial$ 
cd ..
piniheaven@fish:~/Documents$sudo chmod -R a=rx tutorial #assign user,group and others with the permission of read and excute, including it's subdirectories

piniheaven@fish:~/Documents$ ls -l
total 32
drwxrwxr-x  4 piniheaven piniheaven 4096 Aug 22 12:16 assemble
......
......
dr-xr-xr-x  2 jack       piniheaven 4096 Aug 25 21:42 tutorial
piniheaven@fish:~/Documents$ ls -l tutorial/
total 0
-r-xr-xr-x 1 jack piniheaven 0 Aug 25 21:42 essay.txt

Linux Commands for Beginners lesson 8 -- chown command

In this part, we'll learn how to change ownership of files and folders.


1.COMMAND:
     chown
 DESCRIPTION:
   change file owner and group


SYNOPSIS
       chown [OPTION]... [OWNER][:[GROUP]] FILE...
OPTION:
   -R, --recursive
          operate on files and directories recursively

Example:
piniheaven@fish:~/Documents$ls
assemble  C++primer_ex  C++primer_note  Ebook  linux  QT_ex  QT_note  tutorial
piniheaven@fish:~/Documents$ ls -l  ./tutorial/
total 0
-rw-rw-r-- 1 piniheaven piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents$ sudochown jack ./tutorial/essay.txt  #change essay.txt's owner
piniheaven@fish:~/Documents$ ls -l  ./tutorial/
total 0
-rw-rw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents$ sudochown piniheaven:Students ./tutorial/essay.txt #change essay.txt's owner and group
piniheaven@fish:~/Documents$ ls -l  ./tutorial/
total 0
-rw-rw-r-- 1 piniheaven Students 0 Aug 25 21:42 essay.txt
piniheaven@fish:~/Documents$ sudochown -R jack:piniheaven ./tutorial  #change all files's owner and group in tutorial directory
piniheaven@fish:~/Documents$ ls -l  ./tutorial/
total 0
-rw-rw-r-- 1 jack piniheaven 0 Aug 25 21:42 essay.txt

Linux Commands for Beginners lesson 7 -- userdel command

In this part, I will show you how to remove users from your Linux system.

1. COMMAND:
     userdel
  DESCRIPTON:
     delete a user account and related files


  SYNOPSIS
       userdel [options] LOGIN


  OPTION:
     -r, --remove
           Files in the user's home directory will be removed along with the
           home directory itself and the user's mail spool.

Example:
piniheaven@fish:~$ ls /home
jack  piniheaven  tom
piniheaven@fish:~$ sudouserdel jack  #delete user account,but not delete files in the user's home directory 
piniheaven@fish:~$ ls /home
jack  piniheaven  tom
piniheaven@fish:~$ sudouserdel -r tom #delete user account,and delete files in the user's home directory 
piniheaven@fish:~$ ls /home
jack  piniheaven

Linux Commands for Beginners lesson 6 -- usseradd,passwd commands

 in this part, I will show you how to add user to your system and how to change user's password


1.COMMAND:
       useradd 
  DESCRIPTION:
       create a new user or update default new user information
 SYNOPSIS:
       useradd [options] LOGIN


 OPTIONS:
      -g, --gid GROUP
           The group name or number of the user's initial login group.
     -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
           A list of supplementary groups which the user is also a member of.
    -m, --create-home
           Create the user's home directory if it does not exist.
   
     -s, --shell SHELL
           The name of the user's login shell.


Example:
piniheaven@fish:~$ ls /home
piniheaven
piniheaven@fish:~$ sudo  useradd jack -m -g users -s /bin/bash   #create home folder for jack, add jack to users group and specify bash shell to jack
[sudo] password for piniheaven: 
piniheaven@fish:~$ ls /home
jack  piniheaven



2.COMMAND:
    passwd
  DESCRIPTION:
    change user password


 SYNOPSIS:
       passwd  [LOGIN]


Example:
piniheaven@fish:~$ sudo passwd jack
Enter new UNIX password:
Retype new UNIX password: 

passwd: password updated successfully

Linux Commands for Beginners lesson5 -- pidof,kill and ps commands

In this part,I will show you how to kill processes.


if you know your application's name,you can use pidof and kill commands to kill it.


1.COMMAND:
      pidof
 DESCRIPTION:
      finds the process id's (pids) of the named  programs.


2.COMMAND:
      kill
 DESCRIPTION:
      Terminate a Process


Example:
piniheaven@fish:~$ pidof firefox
8477
piniheaven@fish:~$ kill 8477




unfortunately,most of the time, we can not remenber what the application's name is exactily.In this case,you can use ps cammand to list processes.


3.COMMAND:
      ps 
  SYNOPSIS
      ps [options]


 DESCRIPTION:
       ps displays information about a selection of the active processes.


 OPTION:
     -a all w/ tty(TeleTYpe) except session leaders
     -U by real user ID (supports names)
     -u by effective user ID (supports names)
      x  processes w/o controlling ttys




example:
piniheaven@fish:~$ ps -ux    #all of your Processes  that are running
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
1000      1923  0.0  0.0 442624  3876 ?        Sl   06:31   0:00 /usr/bin/gnome-keyring-daemon --daemonize --login


......
......
1000     26058 15.1  3.7 963772 224616 ?       Sl   08:50   1:37 /usr/lib/firefox/firefox
1000     26416  9.9  2.0 687044 125308 ?       Sl   08:50   1:02 /usr/lib/firefox/plugin-container /usr/lib/flashplugin-installer
1000     28660  0.0  0.0  22360  1276 pts/2    R+   09:00   0:00 ps -ux




piniheaven@fish:~$ ps -aux    #all uses's processes that are running
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  24592  2500 ?        Ss   06:30   0:00 /sbin/init


......
......
root     25542  0.0  0.0      0     0 ?        S    08:43   0:00 [kworker/0:3]
1000     26058 14.2  3.8 965884 232620 ?       Sl   08:50   2:18 /usr/lib/firefox/firefox
1000     26416  9.0  2.0 687044 125308 ?       Sl   08:50   1:10 /usr/lib/firefo
root     28661  0.1  0.0      0     0 ?        S    09:02   0:00 [kworker/u:1]
1000     28670  0.0  0.0  22360  1272 pts/2    R+   09:03   0:00 ps -aux




piniheaven@fish:~$ps-U piniheaven   #the  specified username's all process that are running
  PID TTY          TIME CMD
 1923 ?        00:00:00 gnome-keyring-d
 1934 ?        00:00:00 gnome-session
 1969 ?        00:00:00 ssh-agent
 ......
 ......
21890 ?        00:00:45 gedit
23530 pts/2    00:00:00 bash
26058 ?        00:02:45 firefox
26416 ?        00:01:31 plugin-containe
28681 pts/2    00:00:00 ps

Linux Commands for Beginners lesson 4 -- locate,updatedb,sudo,file commands

in this Part , I cover searching for files and directories with the locate, updatedb and sudo commands.  I also cover examining file types with the file command.

1.command:
          locate
  description:
          Search for entries in a mlocate database.


2.command:
         updatedb
 description:
        Update a mlocate database.


3.command:
          sudo
   description:
          sudo allows a permitted user to execute a command as the superuser or another user,
          as specified by the security policy.
   option:
       -s :
                   The -s (shell) option runs the shell specified by the SHELL
                   environment variable if it is set or the shell as specified
                   in the password database.  If a command is specified, it is
                   passed to the shell for execution via the shell's -c
                   option.  


4.command:
        file
   description:
       determine file type




Example:
here,let's go to the Documents directory first,for I don't want to put my file system in chaos
piniheaven@fish:~$ cd Documents/
piniheaven@fish:~/Documents$ ls
assemble  C++primer_ex  C++primer_note  Ebook  linux  QT_ex  QT_note  test


show what's in test directory
piniheaven@fish:~/Documents$ ls test/     #nothing is in test directory


let's create some files
piniheaven@fish:~/Documents$ touch test/jackFile.txt
piniheaven@fish:~/Documents$
 touch test/tomFile.txt


if we can't remember where the jackFile.txt is,but we want to find out it.
piniheaven@fish:~/Documents$ locate jackFile.txt   #Unfortunately,nothing was found 

in that case,we need to update database
piniheaven@fish:~/Documents$ updatedb   #pemission deny
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'


so,we need to change user as root temporary
piniheaven@fish:~/Documents$ sudo updatedb
[sudo] password for piniheaven: 
we can alse do it like this
(
 piniheaven@fish:~/Documents$ sudo -s
[sudo] password for piniheaven: 
root@fish:~/Documents# updatedb
root@fish:~/Documents# exit  
exit
)


piniheaven@fish:~/Documents$locate jackFile.txt  
/home/piniheaven/Documents/test/jackFile.txt           #see,it works.

you can find out files,which even you can't remember what it is exactly name
piniheaven@fish:~/Documents$locate *File.tx*
/home/piniheaven/Documents/test/jackFile.txt
/home/piniheaven/Documents/test/tomFile.txt

now,change to test directory
piniheaven@fish:~/Documents$cd test
piniheaven@fish:~/Documents/test$ ls
jackFile.txt  tomFile.txt


there are two files in test directory,but we need more information about these files
piniheaven@fish:~/Documents/test$ filejackFile.txt
jackFile.txt: empty       #wow,it is empty


ok,let's write something into jackFile.txt
piniheaven@fish:~/Documents/test$ nano jackFile.txt


show what's in  jackFile.txt
piniheaven@fish:~/Documents/test$ cat jackFile.txt
hello,I am jackFile


use file command again
piniheaven@fish:~/Documents/test$ filejackFile.txt
jackFile.txt: ASCII text


change to /bin directory
piniheaven@fish:~/Documents/test$ cd /bin


there are lots of executable commands in it
piniheaven@fish:/bin$ ls
bash                  dbus-uuidgen    kbd_mode    netcat            plymouth-upstart-bridge  true
bunzip2               dd              kill        netstat           ps                       ulockmgr_server
busybox               df              less        nisdomainname     pwd                      umount
bzcat                 dir             lessecho    ntfs-3g           rbash                    uname
bzcmp                 dmesg           lessfile    ntfs-3g.probe     readlink                 uncompress
bzdiff                dnsdomainname   lesskey     ntfs-3g.secaudit  rm                       unicode_start
bzegrep               domainname      lesspipe    ntfs-3g.usermap   rmdir                    vdir
......
......




let's test what kind of file it is
piniheaven@fish:/bin$ file pwd
pwd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x5cff3ccc22aeea4fd1d161a76d054d98e333639f, stripped
piniheaven@fish:/bin$ filerm
rm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xc41b59f611884bf5e27498576915db6193387a52, stripped

Linux Commands for Beginners lesson3 -- introduce mv,cp,cat commands

1.command:cat
  DESCRIPTION
       concatenate files and print on the standard output
  SYNOPSIS
       cat [OPTION]... [FILE]...
  Option:
   -n, --number: number all output lines
             
Example:
piniheaven@fish:~/Documents/test$ ls
essay
piniheaven@fish:~/Documents/test$ cat essay  #print essay 's content on the standard output
Hello.
Fine,thanks!
piniheaven@fish:~/Documents/test$ 
cat -n essay #print essay's content on the standard output and number all output lines
     1Hello.
     2Fine,thanks!




2.command:mv
  mv - move (rename) files


  SYNOPSIS:
     mv [OPTION]... SOURCE... DIRECTORY
  DESCRIPTION:
       Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.


Example:
piniheaven@fish:~/Documents/test$ ls
essay
piniheaven@fish:~/Documents/test$ mvessay essay.txt      #rename essay as essay.txt
piniheaven@fish:~/Documents/test$ ls
essay.txt
piniheaven@fish:~/Documents/test$ mv essay.txt ../    #move essay.txt to previous directory
piniheaven@fish:~/Documents/test$ ls
piniheaven@fish:~/Documents/test$ cd ..
piniheaven@fish:~/Documents$ ls
assemble  C++primer_ex  C++primer_note  Ebook  essay.txt  linux  QT_ex  QT_note  test




3.command:cp
     cp - copy files and directories


  SYNOPSIS:
     cp [OPTION]... SOURCE... DIRECTORY
     
  DESCRIPTION:
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.


Example:
piniheaven@fish:~/Documents$ ls test/
piniheaven@fish:~/Documents$ cp essay.txt test/  #copy essay.txt to test directory
piniheaven@fish:~/Documents$ ls test/
essay.txt