Day3 #90DaysOfDevOps Challenge

Basic Linux Commands

Basic Linux Commands

What is a Linux Command:

  • A Linux command is a program or utility that runs on the command line.

  • A command line is an interface that accepts lines of text and processes them into instructions for your computer.

  • Any graphical user interface is just an abstraction of command-line programs.

  • A flag is a way we can pass options to the command we run.

  • An argument is a value that we pass to a command to modify its behavior or provide it with additional information.

Basic Linux Commands:

  1. ls - The most frequently used command in Linux to list directories

  2. pwd - Print working directory

  3. cd - to navigate through directories

  4. mkdir - used to create directories in Linux

  5. mv - Move or rename files

  6. cp - Similar usage as mv but for copying files in Linux

  7. rm - Delete files or directories

  8. touch - Create blank/empty files

  9. ln - Create symbolic links (shortcuts) to other files

  10. cat - Display file contents on the terminal

  11. clear - Clear the terminal display

  12. echo - Print any text that follows the command

  13. man - Access manual pages for all Linux commands

  14. whoami - Get the active username

  15. sudo - Command to escalate privileges in Linux

Tasks:

1. To view what's written in a file.

\>> Use the cat command.

Syntax: cat <file name>

No alt text provided for this image

2. To change the access permissions of files.

\>> Use chmod command -

Syntax: chmod <permission> <file name>

The basic permissions a file can have are:

r (read) - 4

w (write) - 2

x (execute) - 1

Which are defined for Owner(u), group(g), and other users(o).

Ex1. Adding execute permissions to owner and group. And write permissions to other users.

No alt text provided for this image

Ex2. Removing execute permission for owner. (Another way)

No alt text provided for this image

3. To check which commands you have run till now.

\>>Use the history command.

No alt text provided for this image

4. To remove a directory/ Folder.

\>>Use the rm command.

Syntax: rm <filename>

\>>If you want to delete an empty directory, you can use the recursive (-r) flag:

Syntax: rm -r <dirname>

\>>To remove a directory with content inside of it, you need to use the force (-f) and recursive flags:

Syntax: rm -rf <dirname>

5. To create a fruits.txt file and view the content.

No alt text provided for this image

6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

No alt text provided for this image

7. Show only the top three fruits from the file.

\>>Use the Head command with the -n flag.

Syntax: head -n <filename>

No alt text provided for this image

8. Show only the bottom three fruits from the file.

\>>Use the tail command with the -n flag.

Syntax: tail -n <filename>

No alt text provided for this image

9. To create another file Colors.txt and to view the content.

\>> touch Colors.txt and cat Colors.txt

10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.

\>>echo -e "Red \nPing \nWhite \nBlack \nBlue \nOrange \nPurple \nGrey"

11. To find the difference between fruits.txt and Colors.txt files.

\>>Use the diff command.

Syntax: diff <filename1> <filename2>

No alt text provided for this image

Thank you for reading!😀