본문 바로가기

OS/Linux

Common Commands

  • pwd will show your current directory
  • cd is used to change current directory, eg. cd directory-name
  • ls - lists information about files and directories
    • ls -a - all files (including hidden)
    • ls -l - long form, gives more information about files
    • ls -d - gives information about the directory itself, not contained files
    • these options can be mixed and matched, eg. ls -ld
  • mkdir - to create directories
    • mkdir -p - to create a directory & any parent directories not already existing
  • rmdir - to delete empty directories, eg. rmdir directory-list
  • mv existing-file new-file - to rename or move files & directories
  • cp source-file destination-file - to copy files (careful, overwrites destination with no warning)
  • rm - to delete files, eg. rm file-list
    • rm -r  - to delete directories including files and subdirectories
    • rm -ir - to delete directories including files and subdirectories, with prompt to confirm removal
  • cat filename - display contents of file
  • more or less - displays file contents one page at a time
    • <space bar> - will go to next page
    • b - will go to previous page
    • /string - will search for string within document being viewed
    • q - will quit
  • touch - creates a new file, or updates stats on an existing file
  • file filename - gives info about the contents of the file
  • date - gives date and time
  • man command - online help for command, uses more to display information
    • man -k keyword - eg. man -k calendar - searches through all man sections for keyword
  • diff file1 file2 - displays differences between 2 files
  • echo text or $variable (eg. $USER)
  • printf - similar to echo but can use C-style formatting
    • allows escapes: eg. \n (newline) \t (tab)
    • eg. printf "This is a menu\n\t1. Item 1\n\t2. Item2\n\t3. Item3\nEnter choice: "
  • head -n filename - displays first n lines, 10 is default
  • tail -n filename - displays last n lines, 10 is default
  • grep 'string' file - print lines in file that contain the string
    • grep will be revisited in the lecture about regular expressions
  • whereis utility - lists all pathnames in standard libraries with this utility name
  • which utility - lists pathname that would be used to access this utility