Basic Linux Commands

Basic Linux Commands

Here are some basic linux commands which can get you started.

  1. View contents of a file.

    Command: cat <filename>

    for eg. cat day3.sh

  2. Change access permissions of file.

    1. To understand file permissions we need to understand what all groups are present in Linux and what file permissions we can assign to them.

      We have three groups in Linux:

      1. users: permissions will be applied to all users

      2. groups: permissions will be applied to a group of users

      3. others: any users that are not part of users and groups

Linux File Permissions:

  1. Read: this will provide read permission to the file

  2. Write: this will provide write permission to the file

  3. Execute: this will provide execution permission to the file

As shown in the image above Users has rwx which means read, write, and execute permissions.

Groups have access to execute the file whereas others have access to read and execute.

Command : chmod <filepermission> <filename>

for eg. chmod 766 day3.sh

  1. Check history of commands:

    To check list of commands you previously ran use history command as shown below:

    This will give you a list of commands.

  2. Remove a directory/folder:

    To remove a directory use rm command as shown below:

    The -rf flag will ensure the forceful deletion of files in recursive format.

  3. Create a text file and add contents.

    To create a text file use vim command as shown below:

    vim <filename>

    To add content to this file click and which will open vim editor mode.

    Type contents in the file as shown below:

    Enter "i" which will enable insert mode.

    After entering the content, save your work using " wq! "

  4. Check the top/bottom contents of the file.

    To check top contents use the head command.

    head -n <filename>

    e.g head -3 fruits.text

    To check bottom contents use the tail command.

    tail -n <filename>

    e.g tail -3 fruits.txt

    1. Check the difference between the two files.

      diff command will show you difference between two files.

      diff <filename1.txt> <filename2.txt>

      for eg. diff fruits.txt color.txt