Lecture # 7 - Basic Linux Commands

Lecture # 7 - Basic Linux Commands

Basic Commands used in Linux

  • whoami: The whoami command is used in Linux to display the username of the current user.

  • pwd: The pwd command in Linux is used to print the current working directory.

  • ls: The ls command in Linux is used to list directory contents.

    The ls command has many options. Some are as under:

    -> ls -a: ls-a lists all files including hidden files.

    -> ls -l: ls-l displays detailed information about each file or directory.

    -> ls -lh: ls -lh displays sizes in a human-readable format.

  • man: The man command in Linux is used to display the manual pages for other commands. This command is written as man [options] [command] .

    When we run the command man tar , this manual will be shown and we can scroll it to read the whole manual. To close the manual simply press the key 'q'.

  • clear: The clear command in Linux is used to clear the terminal screen by removing all previous commands.

  • echo: The echo command in Linux is used to display a line of text or a string of characters in the terminal. This command is written as echo [options] [command] .

    The echo command has some options. They are as under:

    -> echo -n: echo -n [command] suppresses the trailing newline, so no newline character is output after the string.

    -> echo -e: echo -e [command] Enables interpretation of backslash escapes. For example, \n will be interpreted as a newline character.

  • date: The date command in Linux is used to display or set the current system date and time.

    -> To display the current date and time in the default format:

    -> To display the date and time in a specific format: We will use date [+FORMAT] to display the date and time in a specific format.

    Y: Year, m: month, d: day, H: hours, M: minutes, S: seconds

    -> To set the system date and time: We will use sudo date MMDDhhmm[[CC]YY][.ss] to change the date and time.

    You can see the last command and this command. In the last command the time is changed because I only changed the time.

    MM: Month, DD: day, hh: hour, mm: minute, [[CC]YY]: year i.e '24' or '2024',

    ss: seconds. And remember to add a dot(.) before giving the seconds, also add sudo before the command. Sudo is used for giving permission. We will learn about sudo in our next lectures.

  • cal: The cal command in Linux is used to display a calendar. You'll have to first install the package. For this run the following command in your terminal:

    sudo apt install ncal . This command is written as cal [options] [month] [year] . Some options of this command are as under:

    -> cal -3: To display the previous, current, and next month's calendars.

    -> cal -y: To display a calendar for the entire year.

    -> To display calendars for month and year of your choice: This command is written as cal [month] [year] .

  • history: The history command in Linux is used to display the list of commands that have been previously executed in the current shell session.

  • alias: The alias command in Linux is used to create shortcuts or alternate names for longer commands. This command is written as:

    alias alternate_name='command' .

    whoami command is used to display the username of the current user. I changed this command and gave it an alternative name username.

  • unalias: The unalias command in Linux is used to remove aliases previously defined for commands.

    -> To remove the alias for a specific command: unalias [alternate_name]

    -> To remove multiple aliases at once: unalias [alternate_name1] [alternate_name2]

    -> To remove all aliases: unalias -a

  • reboot: The reboot command in Linux is used to reboot the system. It restarts the operating system and brings the system back to its initial state.

  • shutdown: The shutdown command in Linux is used to shut down or reboot the system. This command is written as: shutdown [OPTIONS] [TIME] [MESSAGE] .

    -> To shutdown the system immediately: shutdown -h now

    -> To shutdown the system in specific time: shutdown -h [+TIME]

    -> To cancel a pending shutdown: shutdown -c