50 Linux Commands You Should Know

 ls - list the files and directories in the current directory

ex:-abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1


pwd-print the current working directory

ex:-abhilash@DESKTOP-J286E82:~/harry$ pwd

/home/abhilash/harry


cd - change the current directory

ex:-abhilash@DESKTOP-J286E82:~/harry$ cd harry1

abhilash@DESKTOP-J286E82:~/harry/harry1$


mkdir - create a new directory

ex:-abhilash@DESKTOP-J286E82:~/harry$ mkdir harry2

abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1  harry2


rmdir - remove a directory

ex:-abhilash@DESKTOP-J286E82:~/harry$ rmdir harry2

abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1


cp - copy files or directories

ex:-abhilash@DESKTOP-J286E82:~/harry$ cp main.py main-backup.py

abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1  main-backup.py  main.py

{here escape :wq! is for saving the file while escape :q! is only for discard the changes in that file and it will be back to its original form)


mv - move or rename files or directories

ex:-abhilash@DESKTOP-J286E82:~/harry$ mv main-backup.py main-b.py {used for renaming the file)

abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1  main-b.py  main.py


another ex:-abhilash@DESKTOP-J286E82:~/harry$ mv main-b.py harry1 {used for moving the file main-b.py to harry1 directory}

abhilash@DESKTOP-J286E82:~/harry$ ls

1.txt  2.txt  harry1  main.py

abhilash@DESKTOP-J286E82:~/harry$ cd harry1

abhilash@DESKTOP-J286E82:~/harry/harry1$ ls

main-b.py


rm - remove files or directories

ex:-abhilash@DESKTOP-J286E82:~/harry$ rm 1.txt{removing the file}

abhilash@DESKTOP-J286E82:~/harry$ ls

2.txt  harry1  main.py

abhilash@DESKTOP-J286E82:~/harry$

another ex:-{removing the directory}

abhilash@DESKTOP-J286E82:~/harry$ rm -r harry1

abhilash@DESKTOP-J286E82:~/harry$ ls

2.txt  main.py


touch - create a new empty file {or update the timestamp of an existing file}

ex:-abhilash@DESKTOP-J286E82:~/harry$ touch rohan.txt

abhilash@DESKTOP-J286E82:~/harry$ ls

2.txt  main.py  rohan.txt


cat - concatenate and display files

ex:-

abhilash@DESKTOP-J286E82:~/harry$ cat main.py

import os

print(os.listdir())

another ex:-abhilash@DESKTOP-J286E82:~/harry$ cat >>main.py
hi this is abhilash
from akola

abhilash@DESKTOP-J286E82:~/harry$ cat main.py
import os
print(os.listdir())



hi this is abhilash
from akola

man - manual for a command

htop - an interactive process viewer and system monitor

chmod - change the permissions of a file or directory
The first digit represents the owner of the file/directory
# The second digit represents the group that the file/directory belongs to
# The third digit represents all other users
chmod calculator link:-https://chmod-calculator.com/


chown - change the owner of a file or directory

  • tar - create or extract compressed archive files
    # x: extract files from an archive
    # t: list the contents of an archive
    # r: append files to an existing archive
    # z: use gzip compression
    # j: use bzip2 compression
    # cf: create file
    #xf: extract file
    tar cf archive.tar file1 file2 file3
    

ex:-abhilash@DESKTOP-J286E82:~/harry$ tar cf rohan.tar rohan.txt
abhilash@DESKTOP-J286E82:~/harry$ ls
2.txt  main.py  rohan.tar  rohan.txt



  • gzip - compress files
    gzip file.txt
    

  • gunzip - decompress compressed files
    gunzip file.txt.gz

ex:-
abhilash@DESKTOP-J286E82:~/harry$ gzip 2.txt
abhilash@DESKTOP-J286E82:~/harry$ ls
2.txt.gz  main.py  rohan.tar  rohan.txt
abhilash@DESKTOP-J286E82:~/harry$ gunzip 2.txt.gz
abhilash@DESKTOP-J286E82:~/harry$ ls
2.txt  main.py  rohan.tar  rohan.txt
abhilash@DESKTOP-J286E82:~/harry$


  • ssh - connect to a remote server securely
    ssh username@server_address
    


  • scp - securely copy files between systems
    scp myfile.txt user@remotehost:/home/user/
    
  • ping - test network connectivity
    ping 8.8.8.8
    
  • ifconfig - display or configure network interfaces
    ifconfig
    
  • netstat - display network connection information
    netstat
    
  • ps - display information about running processes
    ps aux
    
  • kill - terminate a process
    kill [PID]
    

Comments