Bash Commands Cheat Sheet

Basic file manipulation

  • To display file content
  • $ cat fileName

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

  • To change current directory
  • cd

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

    $ cp originalFileName folderName

  • 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 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 fileName

  • 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

    Basic Terminal Navigation

  • To list all files and folders
  • $ ls -a

  • To list files in folder
  • $ ls folderName

  • To change directory
  • $ cd /

    $ cd ..

  • To show disk usage of folders in human readable format
  • $ du -h

  • To print current working directory
  • $ pwd

    Basic Terminal Shortcuts

  • To halt the current command
  • Ctrl + C

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

  • To auto completion of file or command
  • TAB

  • 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 clear the terminal
  • Ctrl + L

  • Cursor to the start of line
  • Ctrl + A

  • Cursor to the end of line
  • Ctrl + E

  • To delete tight of the cursor
  • Ctrl + K

  • To repeat the last command
  • !!

  • To logout of current session
  • exit

    Extract, sort and filter data

  • To cut a part of file
  • $ cut -c 2-5 fileName.txt
    (cut the charaters 2 to 5 of each line)

  • To sort the content of file alphabetically
  • $ sort fileName

  • To search files
  • grep [pattern]

  • To get number of lines in a file
  • $ wc -l fileName

  • To get number of words in a file
  • $ wc -w fileName

  • To get number of characters in a file
  • $ wc -m fileName

    Researching Files

  • 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

    Create and modify user accounts

  • To create a new user
  • $ sudo adduser user_name

  • To change a user's password
  • $ sudo passwd accountName

  • To delete an account
  • $ duso deluser accountName

  • To create a new user group
  • $ addgroup groupName

  • To delete a user group
  • $ delgroup groupName

  • To add user to a group
  • $ usermod -g groupName userName

  • To change account name
  • $ usermod -g bob alice

  • Add groups to the user without loosing the ones he's already in
  • $ usermod -aG groupName userName

    Installing software

  • To install software from repo
  • $ sudo apt-get install nameOfSoftwarePkg

  • To manually install a software
  • $ ./configure

    $ make

    $ su

    # make install
    Ubuntu CheatSheet Home Emacs CheatSheet