Monday, June 21, 2010

Linux File Commond

  • Display the absolutly path of the current directory
    pwd
  • Display the contained files and sub directories in the current directory
    ls [option] [filenamePattern]
    Most used options include -a for displaying all files, -l for displaying all the informations for each file,
  • Create one/more files
    touch file name or file name pattern
    eg: touch {report,draft}_{AUG,SEP,NOV}{1,2,3}
  • Create directory
    mkdir
  • Remove directory
    rmdir
  • Copy files
    cp
  • Move files
    mv
  • Link files
    ln -s originalFile linkFile
    ln originalFile linkFile
  • Display information, display all the matches of the wildcard pattern, that usefull to avoid operation on wrong files when use echo before use wildcard pattern delete or move files.
    echo [wildcard pattern]
  • Change the file permissions
    chmod permission fileName
    Owner                     Group                    Others
    execute write read    execute write read   execute write read
             1      2     4             1      2     4            1      2     4
  • Change the file owner
    chown username filename
  • Change the file owner group
    chown username:groupName fileName
  • Search files
  • wildcard * ? ~
  • Display file content
    • cat filename display the contents of the file
    • less fileName1 [fileName 2 …fileName n] view one or more files at the same time :n(to view next page) :p(to view previous page) to navigate from pages and automaticaly paginates the file.
    • head -number fileName  view the fist number of lines in the file
    • tail -number fileName  view the last number of lines in the file

No comments: