Linux Basic Commands


Ubuntu uses the Bash shell by default, which provides a range of commands to manage files, navigate directories, and control system settings. Here’s an overview of basic shell commands that are essential for working with Ubuntu.

1. File and Directory Commands

These commands help you manage files and directories on your system.

  • pwd: Prints the working directory (current location).

    pwd

    Example output:

    /home/username
  • ls: Lists files and directories in the current directory.

    ls
    • Use ls -l for a long listing format, showing details like permissions, size, and modification date.
    • Use ls -a to show hidden files (those that start with .).
  • cd: Changes the current directory.

    cd /path/to/directory
    • cd .. takes you up one level in the directory tree.
    • cd ~ or simply cd takes you to your home directory.
  • mkdir: Creates a new directory.

    mkdir new_directory
  • rmdir: Removes an empty directory.

    rmdir directory_name
  • touch: Creates a new empty file.

    touch filename.txt
  • cp: Copies files or directories.

    cp source_file destination
    • Use cp -r to copy directories recursively.
  • mv: Moves or renames files and directories.

    mv source_file destination
  • rm: Removes files or directories.

    rm filename
    • Use rm -r to remove directories and their contents.

2. Viewing and Editing Files

These commands help you view and modify the content of files.

  • cat: Concatenates and displays the content of a file.

    cat filename.txt
  • less: Allows you to scroll through the contents of a file.

    less filename.txt
  • head and tail: Display the beginning or end of a file.

    head filename.txt # Shows the first 10 lines tail filename.txt # Shows the last 10 lines
  • nano: A simple text editor for editing files within the terminal.

    nano filename.txt

3. System Information Commands

These commands give information about your system and its status.

  • uname: Displays system information.

    uname -a
  • df: Shows disk space usage for each file system.

    df -h
  • du: Displays the disk usage of files and directories.

    du -h
  • top: Shows running processes and resource usage in real-time.

    top
  • ps: Lists currently running processes.

    ps aux

4. Network Commands

These commands help you manage network connections and configurations.

  • ping: Checks connectivity to a server.

    ping google.com
  • ifconfig (requires root privileges): Displays network interfaces and their configurations.

    ifconfig
  • wget: Downloads files from the internet.

    wget http://example.com/file

5. Package Management Commands

These commands help you install, update, and manage software on Ubuntu using the APT package manager.

  • sudo apt update: Updates the package lists for upgrades and new packages.

    sudo apt update
  • sudo apt upgrade: Installs the latest versions of all installed packages.

    sudo apt upgrade
  • sudo apt install: Installs a new package.

    sudo apt install package_name
  • sudo apt remove: Removes an installed package.

    sudo apt remove package_name

6. Permissions Commands

These commands manage file and directory permissions.

  • chmod: Changes the permissions of a file or directory.

    chmod 755 filename
  • chown: Changes the ownership of a file or directory.

    sudo chown user:group filename

7. Searching Commands

These commands help you locate files and search content within files.

  • find: Searches for files and directories.

    find /path -name filename
  • grep: Searches for a string within files.

    grep "text_to_find" filename

8. Shortcuts in the Terminal

  • Ctrl + C: Stops the currently running command.
  • Ctrl + Z: Suspends the current command.
  • Tab: Autocompletes the command or file name.
  • Ctrl + R: Searches command history.

Summary

These basic shell commands provide foundational skills to navigate, manage files, install software, and monitor the system in Ubuntu. Mastering these commands can help you efficiently perform tasks and troubleshoot in a Linux environment.