Skip to main content

Command Palette

Search for a command to run...

Linux Basic Commands

Published
•3 min read•View as Markdown
Linux Basic Commands

Basic commands of Linux was given below:

Directory means folder which contains n no of files. To practice these commands first go to the Linux operating system of flavor(version) Ubuntu's Terminal.

mkdir- make a directory. This command creates a directory.

mkdir Achyut

here Achyut is a directory or folder.

cd-change directory. It is used to change the directory.

cd Achyut

touch-This command is used to create an empty file. In this empty file, we can not write data inside the file. we can not save or edit this empty file.

cd Achyut

touch ex.txt

here ex.txt is an empty file that is created inside the Achyut directory.

ls- List of files. It shows a file list present in a directory.

cd Achyut

touch ex.txt

ls

output is-:ex.txt

pwd- It stands for present working Directory. This command gives information about which directory you are in.

cd Achyut

pwd

output is-:/home/dell/Downloads/Achyut

clear-it is used to clear the terminal or screen.

history-it shows the list of commands previously perform in the terminal.

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

    command is-:cat <filename>

    ex-:vim ex2.txt

    dell@dell-Inspiron-3576:~/Downloads/Achyut$ cat ex2.txt

    hi good morning.iam a good boy.

    here vim is a text editor. It creates the file and in this file, we can perform tasks like editing data, inserting data, and saving the data.

  2. To change the access permissions of files.

    the command is-: chmod u+r <file name>

    ex-:chmod u+r ex2.txt

    ls -l

    in numerical method-:

    chmod 400 ex2.txt

    r-------- 1 dell dell 32 Jul 18 11:41 ex2.txt

    the numerical value of read is 4, write-2, execute-1, no permission -0.

    here permission was given to the user to read that file.

    chmod 777 ex2.txt

    ls -l

    -rwxrwxrwx 1 dell dell 32 Jul 18 11:41 ex2.txt

    all permission was given to the user, group, and others.

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

    command is- history.

    dell@dell-Inspiron-3576:~$ history

    1 cd Downloads/

    2 ls

    3 sudo dpkg -i google-chrome-stable_current_amd64.deb

    4 sudo apt install -f

  4. To remove a directory/ Folder.

    the command is- rm filename

    ex-:dell@dell-Inspiron-3576:~/Downloads/Achyut$ rm ex2.txt

    dell@dell-Inspiron-3576:~/Downloads/Achyut$ ls

    here the file was removed from the folder Achyut.

    dell@dell-Inspiron-3576:~/Downloads$ rmdir Achyut/

    dell@dell-Inspiron-3576:~/Downloads$ ls

    here the directory or folder Achyut was removed.

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ vim fruits.txt

    dell@dell-Inspiron-3576:~/Downloads/ad$ cat fruits.txt

    Apple

    mango

    banana

    Tomato

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ vim devops.txt

    output is-

    Apple

    Mango

    Banana

    Cherry

    Kiwi

    Orange

    Guava

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ head -3 fruits.txt

    output is-

    Apple

    mango

    banana

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ vim fruits.txt

    this is data inside the fruits.txt

    Apple

    mango

    banana

    Tomato

    orange

    Show only the bottom three fruits from the file-:

    dell@dell-Inspiron-3576:~/Downloads/ad$ tail +3 fruits.txt

    output is-

    banana

    Tomato

    orange

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ vim Colors.txt

    dell@dell-Inspiron-3576:~/Downloads/ad$ cat Colors.txt

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

    dell@dell-Inspiron-3576:~/Downloads/ad$ vim Colors.txt

    dell@dell-Inspiron-3576:~/Downloads/ad$ cat Colors.txt

    Output is-:

    Red

    Pink

    White

    Black

    Blue

    Orange

    Purple

    Grey

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

    diff fruits.txt Colors.tx

More from this blog

Achyut Das

34 posts