Basic linux commands

Basic linux commands

Β·

3 min read

Beginning Linux command

Here there are some of the basic linux command :-

  1. pwd - Print Working Directory: Displays the current directory.

  2. ls - List Files and Directories: Lists the files and directories in the current directory.

  3. cd - Change Directory: Changes the current directory to the specified location.

  4. mkdir - Make Directory: Creates a new directory.

  5. rm - Remove: Deletes files or directories.

  6. cp - Copy: Copies files or directories to a specified location.

  7. mv - Move or Rename: Moves files or directories to a new location or renames them.

  8. cat - Concatenate: Displays the contents of a file.

  9. find- used to search for files and directories . It allows you to locate files by their names, types, sizes, modification times, and other attributes.

  10. chmod - Change Mode: Changes the permissions of a file or directory.

diff - To find the difference between two files


What is the Linux command to:

πŸ“Œ Check your current/present working directory. πŸ“‚

  • pwd command is used.

πŸ“Œ List all the files or directories, including hidden files. πŸ”

  • ls is used to list the file and directory.

    ls -a is used to list the hidden files and directories as well.

πŸ“Œ Create a nested directory A/B/C/D/E. πŸ“‚

  • mkdir -p is used for nested directories. Here,-p make parent directories as needed

πŸ“Œ View the contents of a file. πŸ‘€

  • cat <file_name> is used.

πŸ“Œ Change the access permissions of files. πŸ”

  • chmod +rwx <file_name> for adding read, write and execution permissions, and

  • chmod -rwx <file_name> for removing the read , write, and execution permissions.

NOTE :- You may also employ a single flag at a time.

  • +r for giving read permission

  • +w for giving written permission

  • +x for giving execute permission

I have created the hello.txt file using the command touch <file_name>. Initially check the permission using the ls-l

After giving the execution permissions.

use ls -l and see what happens in 😁😁

πŸ“Œ Check the command history to view the commands you have executed so far. ⏳

  • history command is used.

πŸ“Œ Remove a directory/folder. πŸ—‘οΈ

  • rm -r <directory/folder name>

    This command is also capable of removing the files.

πŸ“Œ Create a fruits.txt file and view its content. πŸŽπŸ“„.

  • to create: touch <file_name>

  • to view: cat <file_name>

πŸ“Œ Add content to the file βœοΈπŸ“„.

  • In fruits.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
    To add content, we use the editor. I will use the vim editor.

To activate the vim editor use vim <file_name>.

Note :- To activate the insertion mode press "i" of your keyboard and to save the work press esc + : + wq

  • w for the write and

  • q for quit.

πŸ“Œ Display the specific line in the file.

  • Display only the top three fruits from the file 🍎πŸ₯­πŸŒ.

    head -n <file_name> "n" denotes how many lines you have to display.

  • To Show only the bottom three fruits from the file πŸ₯πŸŠπŸŠ.

πŸ“Œ Create a Colors.txt file and view its content. πŸŽ¨πŸ“„

  • to create:- touch <file_name>

  • to view:- cat <file_name>

πŸ“Œ Add the following content to the Colors.txt file (one color per line)

πŸ“Œ Find the difference between the contents of the fruits.txt and Colors.txt files. 🍎🎨

  • diff file1.txt file2.txt

let's connect❀️:-

Β