Skip to main content

Linux Basics

Bash Shell

  • The default user interface for most Linux distributions.
  • Every Linux user has a unique home directory.

Home Directory (~)

  • The ~ symbol represents the home directory of the current user.
    • For example, /home/compsec is equivalent to ~.

Linux Path

Path Representations

There are two ways to represent paths in Linux:

  1. Absolute Path

    • Specifies a location starting from the root directory (/), regardless of the current working directory.
    • Example: /home/user/file1.txt
  2. Relative Path

    • Specifies a location relative to the current working directory.
    • . represents the current working directory.
    • .. represents the parent directory.
    • Example: ./file1.txt or ~/file1.txt

Linux Command List

CommandDescription
pwdPrint current working directory
lsList contents of the current directory
touch [new filename]Create a new empty file
mkdir [new directory name]Create a new directory
cd [location]Change the current directory
cp [source] [destination]Copy source file to destination
cp -r [source] [destination]Copy directories recursively
mv [source] [destination]Move or rename source file to destination
rm [filename]Remove a file
rm -r [directory name]Remove a directory and its contents recursively

Linux Commands in Bash Shell

Examples of Basic Commands

  1. mkdir (make directory)

    Create a new directory named temp:

    user@XXX:~ $ mkdir temp
  2. cd (change directory)

    Change to the newly created temp directory, and then back to the home directory:

    user@XXX:~ $ cd temp
    user@XXX:~/temp $ pwd
    /home/user/temp
    user@XXX:~/temp $ cd ~
    user@XXX:~ $ pwd
    /home/user
  3. ls (list)

    List contents of the current directory and its detailed view:

    user@XXX:~ $ ls
    temp
    user@XXX:~ $ ls -l
    drwxrwxr-x 3 compsec compsec 4096 Jun 1 00:00 temp

  4. touch and rm (create and remove files)

    Create a new file named file and then remove it:

    user@XXX:~ $ touch file
    user@XXX:~ $ ls
    file temp
    user@XXX:~ $ rm file
    user@XXX:~ $ ls
    temp
    user@XXX:~ $ rm -r temp
    user@XXX:~ $ ls

By understanding these basic Linux commands and concepts, you will be better equipped to navigate the Linux environment and manage files effectively.

More to read