Basic Linux Commands overview

#day3/90 : What will the Linux command to

Table of contents

No heading

No headings in the article.

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

    Use the 'cat' command to see what's written in the file

     cat <filename>
    
  2. To change the access permissions of files.

'chmod' is the command used to change the permissions of the file.

chmod <options permissions> <file>
PermissionSymbolDescription
ReadrAllows reading and viewing the contents of a file or folder.
WritewAllows modifying or deleting the contents of a file or folder.
ExecutexAllows executing a file (for executable programs or scripts) or accessing a directory.

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

     history
    
  2. To remove a directory/ Folder.

    The Linux command to remove a directory or folder is rm. However, when you want to remove a directory, you need to use the -r or -rf option, which stands for "recursive" and allows the removal of directories and their contents.

     rm -r <directory>
    
    • rm: The command for removing files and directories.

    • -r: The option to remove directories and their contents recursively.

    • <directory>: The name or path of the directory you want to remove.

  3. To create a fruits.txt file and to view the content.

    Create a new file:

     touch filename.txt
    

    Viewing the contents of the file:

     cat fruits.txt
    

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

    Vim (Vi IMproved) is a highly configurable text editor that is available on most Linux distributions. It is an enhanced version of the original Vi editor, which is a standard text editor in Unix-like systems.

    Add data to the file:

     vim <filename.txt>
    

    Click 'i' to enter the insert mode
    Click 'ESC' to exit to the insert mode
    Then type ':wq ' to save and exit the file editor.

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

    To show only the top three fruits from a file in Linux, you can use the head command with the -n (number) option. Here's the command you can use:

     head -n 3 fruits.txt
    

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

    To display only the bottom three fruits from a file in Linux, you can use the tail command with the -n option.

     tail -n 3 fruits.txt
    

  7. 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, and Grey.

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

    1. diff command: The diff command shows the line-by-line differences between two files. Here's the syntax:

       diff fruits.txt colours.txt
      

    2. cmp command: The cmp command compares two files byte by byte and displays the first differing byte and its offset. Here's the syntax:

       cmp colours.txt fruits.txt
      

    3. The vimdiff command allows you to open two files in Vim and highlights the differences between them. Here's the syntax:

       vimdiff fruits.txt colours.txt
      

To exit follow these steps: 'ESC' and then ':qa '.