Linux commands

Here are some common commands used in Unix and Linux. Some platforms may have slightly different syntax, so check for your system.

  • cd dirname  (go to the directory named dirname)
  • cd ~ (go to home directory)
  • cd - (go to previous directory)
  • pwd  (find current working directory)
  • cp srcfile destfile   (copy a file to another file)
  • mv fileorpath newfileorpath   (renames a file or moves file to new location)
  • ls (list files in directory)
    • params: -l (long), -t (time sorted), -r (reverse), -a (all files including hidden)
  • sort filename (sort file)
  • uniq (eliminates identical lines if they are adjacent)
  • cut -fN,M (removes all columns except N and M, and others included)
  • grep regex filename (search for regular expression in a file)
  • chmod flags filename (change permission flags on a file; e.g.   chmod 751 myfile.txt, gives read,write,execute permissions for the user (owner), read and execute for the group members, and only execute for everyone else)
  • diff file1 file2 (shows differences between two files)
  • head -n N   (displays first N lines of a file)
  • tail -n N (displays last N lines of a file)
  • more or less (only displays one page at a time)
  • tar -cxf filename.tgz directory  (bundles and compresses a directory into a single file)
  • md5sum filename   (prints MD5 checksum for a file)
  • man command  (gives help for a command)

Leave a Reply