2014年3月19日星期三

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

没有评论:

发表评论