Linux Basic Commands

Linux Basic Commands

#90 Days of DevOps Challenge - Day 3

Dear friends, this blog is about basic Linux commands. Please take a look and gain some knowledge of Linux commands.

1. Basic Commands

#pwd -> It shows the present working directory.

#ls -> It shows the available file and directory list in the present working directory.

#uname -> It shows the name of the kernel (OS).

#uname -r ->It shows the version of the kernel (OS).

#cd -> it uses to change the directory.

#clear -> It uses to clear the screen.

#whoami ->it shows the current login user name.

#history -> It shows the list of previous commands.

#date -> It shows the time and date.

2. How to Create the directory.

1. To create a single directory. - #mkdir (file_name1)

  1. To create multiple directories.

    # mkdir guru devops engineer

  2. To Create the directory with path.

    #mkdir -p guru/devops/engineer

  3. To Create the number of directories at a single time.

    #mkdir gurudath{1..10}

    Now that we have learned how to create a directory, let's move on to how to delete it."

3. How to Create the File?

We are using 4 major commands to create the file.

  1. cat

    "cat" is a command that is used to concatenate and display the contents of files on the terminal. It can also be used to create, modify, or combine files. The name "cat" is short for "concatenate".

    #cat file_name

    • After writing the content, press Ctrl+D to exit. The content 'Hello, people how are you' will be saved in the file named 'file_name'.

      If you want to see what you have written in the file, use the following command.

      cat file_name -> it will display the content.

    • Note: The "cat" command can be used to write new content, but it cannot be used to edit existing content. However, you can concatenate or combine the contents of two or more files into a new file using the "cat" command.

  1. touch

    The 'touch' command is used to create empty files or multiple files, and it is often used to create placeholder files or update timestamps. It is also a quick way to modify file metadata. Additionally, the touch command can be used to modify the timestamps of multiple files at once.

    I know you feel so many things in the touch. Let me clear :

    placeholder: A placeholder file is a file that is created to reserve space for data or to represent data that is expected to be available in the future. It is also known as a dummy file or a stub file.

    timestamp: A timestamp is a piece of metadata that records the date and time of certain events, such as when a file was last modified, accessed, or changed. The touch command in Linux allows users to modify the timestamps of files and directories. Specifically, the touch command can be used to update the access time (-a), modification time (-m), or both (-c) of a file. This can be useful for keeping track of when files were last accessed or modified, or for ensuring that files have the correct timestamp information.

     touch myfile.txt
     for creating the empty file.
    
     touch myfile.txt anothermyfile.txt
     for creating multiple files.
    
     my_file.txt using the touch command - to update the timestamp:
     touch my_file.txt
     ls -l my_file.txt
     This will display detailed information about the file, including the timestamp of when it was last modified.
    
  2. Vi or Vim: This is a powerful text editor used by programmers to edit all kinds of plain text, including code. It's especially useful for manual program editing.

    Use the cat command to see the content.

  3. nano: is a text editor command in Linux that is similar to Vi.

So we are finally coming to end of the today's blog.

Now we will check for the assignment section.

Day 3 Task: Basic Linux Commands

Task: 1. What is the Linux command to view what's written in a file.

cat file_name -> is used to view the content of the file
  1. To change the access permissions of files.
The command to change the access permissions of files in Linux is "chmod".

To check which commands you have run till now.

history command shows a numbered list of the commands we have run, along with their command numbers, so you can easily repeat or edit a command by entering its number.

To remove a directory/ Folder.

To remove an empty directory: rmdir
To remove a non-empty directory: rm -r directory_name

To create a fruits.txt file and to view the content. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

1. Command to open the file in nano text editor: nano fruits.txt
2.Type in the content - one fruit per line.
3.Save the file and exit by pressing Ctrl + X, then Y, and finally Enter.

To Show only top three fruits from the file.

Command to display the top three fruits: head -3 fruits.txt

To Show only bottom three fruits from the file.

Command to display the bottom three fruits: tail -3 fruits.txt

To create another file Colors.txt and to view the content. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

To find the difference between fruits.txt and Colors.txt file.