Unix/Linux Commands Cheat Sheet

File Commands

  • To display file content
  • $ cat fileName

  • To place standard input into a file
  • $ cat > myFile

  • To change current directory
  • cd

  • To compare two files
  • cmp

  • To copy a file or a directory
  • $ cp originalFileName newFileName

  • To remove columns or fields from the specified file(s)
  • cut

  • To display line-by-line differences between two text files
  • diff

  • To join two files
  • join

  • To display formatted listing of a current directory content
  • $ ls -l

  • To display directory listing
  • $ ls

  • To display directory listing with hidden files
  • $ ls -al

  • To create a directory dirName
  • $ mkdir dirName

  • To rename or move file
  • $ mv orignalFileName newFileName

  • To put line numbers on a file
  • nl

  • To create a file
  • $ touch fileName

  • To print current working directory
  • $ pwd

  • To remove specified file
  • $ rm fileName

  • To delete directory dirName
  • $ rm -f dirName

  • To display a count of lines, words and characters in a file
  • wc

  • To create symbolic link
  • $ ln -s file link

  • To output the first 10 lines of the file
  • $ head fileName

  • To output the last 10 lines of the file
  • $ tail fileName

  • To output the contents of file as it grows, staring with the last 10 lines
  • $ tail -f file

    SSH & Secure File Copying

  • To securily copy files between hosts on a network
  • $ scp fileName your_username@remotehost.edu:/some/remote/directory

  • An interactive file transfer program
  • sftp

  • To connect to a host as user
  • $ ssh user@host

  • To connect to a host on port portNumber as user
  • $ ssh -p portNumber user@host

  • To enable a keyed or passwordless login for a user
  • $ ssh-copy-id user@host

    Process Management

  • To display all currently active processes
  • $ ps

  • To display all currently running processes
  • $ top

  • To teminate a process with id pid
  • $ kill pid

  • To terminate all process names proc *
  • $ killall proc

  • To list stopped or background jobs
  • $ bg

  • To bring most recent job to the foreground
  • $ fg

  • To bring job 'A' to the foreground
  • $ fg A

  • To alter priority of running processes
  • renice

    File & Group Permissions

  • To change the permission of a file
  • chmod

  • To change the group-ID of the specified files or directories
  • chgrp

  • To group memberships
  • groups

    Searching

  • To search for patterns in files
  • $ grep [pattern] files

  • To search recursively for pattern in dir
  • $ grep -r [pattern] dir

  • To find all instances of file (UNIX)
  • $ find file

  • To find all instances of file
  • $ locate file

  • To construct argument list and invoke utility
  • xargs

    Compression

  • To extract the files from fileName.tar
  • $ tar xf fileName.tar

  • To create a tar named fileName.tar containing files
  • $ tar cf fileName.tar files

  • To create a tar file with Gzip compression
  • $ tar czf fileName.tar.gz files

  • To extract a tar file using Gzip
  • $ tar xzf fileName.tar.gz

  • To create a tar file with Bzip2 compression
  • $ tar cjf fileName.tar.bz2 files

  • To extract a tar file using Bzip2
  • $ tar xjf fileName.tar.bz2

  • Compresses file and renames it to fileName.gz
  • $ gzip fileName

  • Decompresses a file.gz back to file
  • $ gzip -d file.gz

  • Decompresses a file.gz back to file (alternate)
  • $ gunzip file.gz

    System Information

  • To display current date and time
  • $ date

  • To show this month's calender
  • $ cal

  • To display current uptime
  • $ uptime

  • To show who is online
  • $ w

  • To display your current username
  • $ whoami

  • To display info about a user
  • $ finger userName

  • To show kernel info
  • $ uname -a

  • To display CPU info
  • $ cat /proc/cpuinfo

  • To display memory info
  • $ cat /proc/meminfo

  • To display a manual for a command
  • $ man command

  • To display disk usage
  • $ df

  • To display directory space usage
  • $ du

  • To show memory and swap usage
  • $ free

  • To show possible locations of application
  • $ whereis appName

  • To display which app will be run by default
  • $ which app

  • To display the list of recently entered commands
  • $ history

  • To submit a print request
  • $ lpr

  • To display the contents of a print queue
  • $ lpq

  • To print or deny messages
  • mesg

    Compilation & Debugging

  • A graphical front end tool to gdb
  • ddd

  • GNU project C and C++ compiter
  • gcc

  • A front-end tool to gcc to explicitly compile C++ code
  • g++

  • GNU debugger
  • gdb

  • GNU version of make tool
  • gmake

  • A tool to maintain groups of programs
  • make

    Generally Useful Tools

  • Interactive spell checker
  • ispell

  • Convert text file from DOS format to ISO format
  • dos2unix

  • Convert text file from ISO format to DOS format
  • unix2dos

  • To clear the terminal screen
  • $ clear

  • To lock the local X display unti a password is entered
  • $ xlock

    Shortcuts

  • To halt the current command
  • Ctrl + C

  • To stop the current command, resume with fg in the foreground
  • Ctrl + Z

  • To logout the curretn session
  • Ctrl + D

  • To earse one word in the current file
  • Ctrl + W

  • To erase the whole line
  • Ctrl + U

  • Type to bring up a recent command
  • Ctrl + R

  • To repeat the last command
  • !!

  • To logout of current session
  • exit

    Network

  • To ping host and output results
  • $ ping host

  • To get whois info for a domain
  • $ whois domainName

  • To get DNS information for a domain
  • $ dig domainName

  • To perform reverse lookup on a host
  • $ dig -x hostName

  • To download a file
  • $ wget fileName

  • To continue a stopped download
  • $ wget -c file
    Home Ubuntu CheatSheet