Linux Basic Commands

Linux Basic Commands

  1. To create file in linux is 'touch'

    The 'touch' command in Linux is used to create an empty file or update the access and modification timestamps of an existing file. The basic syntax is:

    touch [filename]

  2. To write or edit file in linux 'vim' or 'nano' editor is used

    a. vim:

    1. Create or Edit a File: vim [filename]

    2. Type or edit content. // click "i" to enter in insert mode of file

    3. Save: Esc, :w, Enter.

    4. Exit: Esc, :q, Enter. (To save and exit: Esc, :wq, Enter.)

b. nano:

  1. Create or Edit a File: nano [filename]

  2. Type or edit content.

  3. To Save: Ctrl + O, Enter.

  4. Exit: Ctrl + X.

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

    The 'history' command in Linux is used to display a list of previously executed commands in the current shell session

    syntax: history

  2. To remove a directory/ Folder

    rm -r: Recursively removes files and directories. Use with caution, irreversible. rmdir: Removes empty directories.

    syntax: rmdir [dir_name]

    rm -r [dir_name]

  3. To read content of text file.

    The 'cat' command command is used to concatenate and display file content, used for viewing files.

    cat [filename]

  4. To Show only top three lines from the file.

    The 'head' command is used to show only the top 3 lines of a Linux file

    syntax: head -n 3 [filename]

  5. To Show only bottom three lines from the file.

    The 'tail' command is used to show only the bottom three lines of a Linux file

    syntax: tail -n 3 [filename]

  6. To find difference in 2 files of linux.

    The 'diff' command is used to find the differences between two files in Linux

    syntax: diff file1 file2