Linux Command

来源:互联网 发布:个人大数据征信查询 编辑:程序博客网 时间:2024/04/29 15:46

1. The format of Command: command [option] [file]


     The type of file ( - file ,  d directory ,  l  shortcut )  (right: r w [x execute])
     (3 groups: u user,  g belong,  o other )

 2. File Command


     New Directory: mkdir -p [filename]    //  -p can make file under a file which does not exist.
     Change Directory: cd ~ // return the home directory.
                                   cd - // return the previous directory
                                   cd .. // return the parent directory
                                   cd . // return the current directory

     print working directory:  pwd
     remove directory:  rmdir  // but only the empty file
                                   rm  -rf  [file or directory] // -rf means the system will delete it without asking  (-f false : force to delete)
     Copy directory: cp [-r -p -d -a] (-p -d: will contain the file's property) (-a means all - -pdr)
     Cut directory: mv  (can be used to change the name of files)

      Link directory: ln [-s]  file link_file. // -s refers to soft.(soft link)  like the shortcut in windows (if we delete the original file, the soft link is useless)
                                                              // without -s means hard link. ( these two files can be seen as the same file) (must in the same partition)


3. Search File Command

      locate [file_content],  // find the file in /var/lib/mlocate with file name,   mlocate is a database which is not updated timely. we can use updatedb command to update it.
      whereis [-b -m] [command] : search the command // -m to find the help file
      which [command]  // can also find the command's alias

      find [search_scope] [search_condition]   // search_condition could be [-name file_name] (the name should be the same with your file) (wildcard character : * / ? / [] )
                                                                      // -iname  ignore the case
                                                                     // -mtime +10 : find the files that have been modified 10 days ago(10 without + mean that one day)
                                                                     // -size  +25k : fine the files that are larger than 25k
                                                                    // -a : AND function. match all conditions.   -o : OR function. match one of the condition

     command1  -exec ls -lh {} \;  \\ accept the result from the first command 
     grep  [string]  [file]  // find the string in the file
    


4. Help Command

      man [command]  // describe how to use this [command] (shortage of manual)

      man -f  ==  whatis  // describe the command's function

      apropos [string]// describe all the command containing "string" in the manual file. equivalent to "man -k "

      

       [command]   --help   // -- help is also very useful

       help [command] // this can only get the build-in command's help file. (in shell)

       info [command]   // But very detail. It's somewhat not practical


5. Compress and Uncompress Command

       format :   .zip ,  .gz  ,   .bz2  ,   .tar.gz   ,   .tar.bz2

       %% this zip format is the same to zip in Windows   
       zip  compressed_Name   originFile   // (compressed_Name does not need to write the suffix name (.zip) , but suffix name is recommended)
       zip -r  compressed_name originDirectory  // compress the directory.

       unzip  // Uncompress Command

       %%  .gz  is the exclusive format in Linux
       gzip  originFile
       gzip -r Directory   // compress all the file in the Directory, not the Directory
       
       gunzip   // Uncompress

       %% .bz2
       bzip2   originFile
       bzip2   -k   originFile   // can reserve the original file
             //  Can not compress Directory.

       %%  .tar.gz 
       tar  -cvf  [filename]   [OriginFile]   -c: compress      -v: progress    -f: filename    ;ex: tar -cvf  test.tar  test
       tar  -xvf  // uncompress the file

       tar -zcvf [filename.tar.gz] [originFile]  // compress directly into .tar.gz
       tar -zxvf  [filename.tar.gz]     // uncompress the file
       tar -jzcf  ...      // into .tar.bz2
       tar -jxvf  ...   -C /temp (indicate the location)    // uncompress the .tar.bz2
      














    
0 0
原创粉丝点击