Post

Linux Cheatsheet

Linux Basic Command Line Cheatsheet

This is a cheatsheet of some basic linux commands.

Basic commands

  1. Navigating, go back, list directories, print working directory.
    1
    2
    3
    4
    
    cd /Users/Hello/Documents/
    cd ..
    ls
    pwd
    
  2. Create a file. If already exists, then select that file or directory.
    1
    
    touch example.txt
    
  3. Create a directory.
    1
    
    mkdir example_folder
    
  4. Move file to directory.
    1
    
    mv example.txt ./example_folder/example.txt
    
  5. Remove file, remove directory.
    1
    2
    
    rm example.txt
    rmdir example_folder
    
  6. List User. cat /etc/passwd

  7. Permissioning: change ownership of a folder.
    1
    
    sudo chown stephen ./example_folder
    
  8. Grant permission to execute a file.
    1
    
    chmod 700 example.ch
    
  9. Editing a file using Vim.
    1
    
    vim example.txt
    
  10. Basic Vim commands:
    1
    2
    3
    4
    5
    6
    
    Press i to enter insert mode.
    Press esc to go back to command mode.
    Type :w followed by enter to save.
    Type :q followed by enter to quit.
    Type :q! followed by enter to force quit.
    Type gg dG to delete all.
    
  11. Check if a process is still running:
    1
    
    ps aux | grep <script_name>
    

    Here are the different states:

    • R: Running
    • S: Sleeping
    • T: Stopped
    • Z: Zombie (terminated but not fully cleaned up)
    • D: Uninterruptible sleep (usually related to I/O operations)
  12. To kill a process use the following. Note, in general, you don’t want to kill a process in the S+ state because it is waiting for an event to complete.
    1
    
    kill <Process ID>
    

    To force kill all events associated with your script:

    1
    
    pkill -f <script_name>
    

Ubuntu

  1. Updating Ubuntu.
    1
    2
    3
    
    sudo apt update
    sudo apt full-upgrade
    sudo apt-get dist-upgrade
    
  2. Auto-installing critical updates.
    1
    2
    
    sudo apt-get install unattended-upgrades -y
    sudo dpkg-reconfigure -plow unattended-upgrades
    
  3. Clean system:
    1
    2
    
    su -
    apt autoremove -y && apt autoclean && apt clean
    
This post is licensed under CC BY 4.0 by the author.