Skip to content Skip to footer

The Linux terminal, also known as the command line or shell, is a powerful tool for interacting with your operating system. It allows you to perform various tasks, manage files and directories, and run programs using text commands. Though it might seem intimidating at first, learning to use the terminal can greatly enhance your productivity and give you more control over your system.

Accessing the Terminal

To open the terminal, you usually have a few options:

  1. Using Keyboard Shortcut: Press Ctrl + Alt + T simultaneously. This is the default shortcut in many Linux distributions.
  2. Using the Application Launcher: Click on the Application Launcher icon (commonly represented by a grid or a symbol with four squares) and search for “Terminal.”
  3. Using Right-Click Menu: Right-click on the desktop or in a folder and select “Open in Terminal” or similar option.

Basic Commands

When you open the terminal, you’ll see a command prompt, which typically displays your username, hostname, and the current directory. After the prompt, you can enter commands and press Enter to execute them. Here are some fundamental commands to get you started:

  1. File and Directory Navigation:
    • ls lists files and directories in the current location. ls -l
    • pwd prints the current working directory (full path). pwd
    • cd changes directory. cd /path/to/directory
    • mkdir creates a new directory. mkdir new_directory
    • touch creates a new empty file. touch new_file.txt
    • rm removes/deletes files or directories. rm file.txt rm -r directory/
    • cp copies files or directories. cp file.txt /path/to/destination/ or to copy a directory cp -r directory/ /path/to/destination/
    • mv moves or renames files/directories. mv file.txt new_location/ or mv old_file.txt new_file.txt
  2. File and Text Manipulation:
    • cat concatenates and displays the content of a file. cat file.txt
    • more or less view the contents of a file one page at a time. more large_file.txt or less big_log_file.txt
    • head displays the beginning lines of a file. head file.txt head -n 5 file.txt
    • tail displays the ending lines of a file. tail file.txt tail -n 10 file.txt
    • grep searches for a pattern in a file. grep "search_term" file.txt
    • wc counts lines, words, and characters in a file. wc file.txt
    • echo prints a message or a variable’s value. echo "Hello, World!"
  3. File Permissions:
    • chmod changes file permissions. Each permission uses 3 bits for each group: Read Write Execute.
      Owner-111 (7 in decimal) Group-101 (5 in decimal) Others-101 (5 in decimal) chmod 755 file.txt
    • chown changes file ownership. chown user:group file.txt
    • chgrp changes group ownership. chgrp new_group file.txt
  4. Process Management:
    • ps displays information about running processes. ps ps aux | grep process_name
    • kill terminates processes by sending signals. kill process_id
  5. System Information:
    • uname shows system information (kernel version, etc.). uname -a
    • df displays disk space usage on mounted file systems. df -h
    • du displays the size of a file or directory. du -h file.txt
  6. Archiving and Compression:
    • tar archives files into a tar archive. tar -cvf archive.tar file1.txt file2.txt
    • zip and unzip compress files to zip archive, and decompress zip archives. zip archive.zip file1.txt file2.txt or unzip archive.zip
  7. User Management:
    • who displays information about currently logged-in users. who
    • w shows who is logged in and what they are doing. w
    • users lists users currently logged in. users
    • adduser or useradd adds a new user. adduser new_user
  8. Network:
    • ping is used to check network connectivity to a host. ping google.com
    • ifconfig or ip displays network interface configuration. ifconfig
    • ssh securely logs into a remote server. ssh user@remote_host
  9. Command Help and Manuals:
    • man displays the manual page for a command. man ls
    • --help gets help and usage information for a command. ls --help
  10. Miscellaneous:
    • clear clears the terminal screen. clear
    • history displays a list of recently executed commands. history
    • date displays the current date and time. date
    • Use sudo apt update to update package manager on Debian or Ubuntu
    • install a package on Ubuntu use sudo apt install package_name Click here for list of packages.

Useful Tips

  1. Tab Completion: You can use the Tab key to auto-complete commands and file/directory names. If you type part of a command or name and press Tab, the terminal will try to fill in the rest automatically. If there are multiple matches, pressing Tab twice will show all available options.
  2. Command History: Use the up and down arrow keys to navigate through your command history. This way, you can quickly access previously used commands without retyping them.
  3. Keyboard Shortcuts: Some essential keyboard shortcuts in the terminal include Ctrl + C to abort a running command, Ctrl + D to log out (or close the terminal if no process is running), and Ctrl + L to clear the screen.
  4. Permissions: Be cautious when using commands like rm -r as they can delete files and directories permanently. Also, some commands may require administrative privileges. Use sudo before such commands, but only when necessary, as they can have significant system-wide effects.
0
    Your Cart
    Your cart is empty