Skip to main content

Command Palette

Search for a command to run...

Basic Linux Command

Linux -Day3

Updated
โ€ข4 min readโ€ขView as Markdown
Basic Linux Command

Table of Contents -

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

  2. To change the access permissions of files.

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

  4. To remove a directory/ Folder.

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

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

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

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

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

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

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

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

๐Ÿฑ The cat Command: Displaying File Contents ๐Ÿ“„

  • ๐ŸŒŸ Simplicity: The cat command is straight forward and easy to use.

  • โšก๏ธ Speed: It efficiently displays the entire contents of a file quickly.

  • ๐Ÿ“ Complete Output: It prints the full content of a file without any pagination or truncation.

  • ๐Ÿš€ Versatility: The cat command can handle multiple file arguments, concatenating their contents together.

  • 2- To change the access permissions of files.

  • To change the access permissions of files in Linux, you can use the chmod command. The chmod command allows you to modify the read, write, and execute permissions for the owner, group, and others.

  • ๐Ÿ”’ Changing File Access Permissions ๐Ÿ”‘

    • ๐Ÿ“‚ Identify the File: Locate the file for which you want to modify the permissions.

    • ๐Ÿ“œ Understand Permission Types: There are three types of permissions:

      • ๐Ÿง‘โ€๐Ÿ’ป Owner: The user who owns the file.

      • ๐Ÿ‘ฅ Group: The group to which the file belongs.

      • ๐ŸŒ Others: All other users on the system.

    • ๐Ÿ•ต๏ธโ€โ™€๏ธ Numeric Mode: Assign permissions using numeric values:

      • ๐Ÿ“ Read (r): Assign a value of 4.

      • ๐Ÿ–Š๏ธ Write (w): Assign a value of 2.

      • ๐Ÿƒโ€โ™‚๏ธ Execute (x): Assign a value of 1.

    • โœ๏ธ Example: To give read and write permissions to the owner, read-only permissions to the group, and no permissions to others:

      • The numeric value for the desired permissions is 640.

      • Execute the command: chmod 640 <file_path>

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

    • By using the history command, you can quickly review and reuse previously executed commands, saving time and reducing typing effort in the Linux shell.

    • ๐Ÿ“œ Purpose of the history Command โฒ๏ธ

      • ๐Ÿ•’ Command History: The history command displays the command history of the current shell session.

      • ๐Ÿ”ข Command Numbers: Each command in the history is assigned a unique number, indicating its position in the history list.

      • ๐Ÿ“Š Listing Commands: It presents the command history as a numbered list, showing the command numbers on the left and the corresponding commands on the right.

      • โฌ†๏ธโฌ‡๏ธ Navigation: You can navigate through the command history using the Up and Down arrow keys on your keyboard, making it easy to find and reuse previously executed commands.

    • 4- To remove a directory/ Folder.

    • To remove a directory or folder in Linux, you can use the rm command with the -r option, which stands for "recursive." This option allows you to delete a directory and all its contents. Here's how you can remove a directory:

    • rm -r <directory_path> or rm filename.

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

    • vim fruits.txt

    • cat fruits.txt

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

    • touch devops.txt

    • echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt

    • 7- To Show only top three fruits from the file.

    • head -3 <file_name>

    • 8- To Show only bottom three fruits from the file.

    • tail -3 <file_name>

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

    • touch Colors.txt

    • cat Colors.txt

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

    • echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt

    • 11- To find the difference between fruits.txt and Colors.txt file.

    • diff fruits.txt Colors.txt

  • Thank you for reading this blog! ๐Ÿ˜Š I hope you found the information helpful and engaging. Remember, learning is a never-ending adventure, and discovering new concepts and technologies can be incredibly exciting and rewarding. ๐Ÿš€ Whether you're diving deeper into Linux commands, exploring new programming languages, or embracing the world of DevOps, there's always something new to learn and explore. ๐ŸŒŸ So, stay curious, keep exploring, and never stop expanding your knowledge! ๐Ÿ“š๐ŸŒโœจ Happy learning! ๐ŸŽ‰

More from this blog

Ankit Kumar Jaiswal's blog

38 posts