×
Post thumbnail

Linux most commonly used commands in daily practice..

` ls `

Description: Lists directory contents.

  • When to use: To view files and directories in the current directory.
  • When not to use: N/A
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    ls
    ls -l  # long listing format
    ls -a  # include hidden files

` cd `

Description: Changes the current directory.

  • When to use: To navigate to different directories.
  • When not to use: When you don't need to change directories.
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    cd /path/to/directory
    cd ..  # go up one directory level
    cd ~   # go to the home directory
    

` cp `

Description: Copies files or directories.

  • When to use: To duplicate files or directories.
  • When not to use: When you want to move instead of copy.
  • Consequences: Could overwrite files if not used with caution.
  • Example( bash command ):
    cp file1.txt /path/to/destination/
    cp -r dir1 /path/to/destination/  # copy directory recursively
    cp file1.txt file2.txt  # copy file1.txt to file2.txt
    

` mv `

Description: Moves or renames files or directories.

  • When to use: To move files or directories to a new location or to rename them.
  • When not to use: When you need a copy instead of moving.
  • Consequences: Could overwrite files if not used with caution.
  • Example( bash command ):
    mv file1.txt /path/to/destination/
    mv file1.txt file2.txt  # rename file1.txt to file2.txt
    

` rm `

Description: Removes files or directories.

  • When to use: To delete files or directories.
  • When not to use: When you need to keep the files or directories.
  • Consequences: Irrecoverable data loss if not used with caution.
  • Example( bash command ):
    rm file1.txt
    rm -r dir1  # remove directory recursively
    rm -f file1.txt  # force remove file without prompt
    

` touch `

Description: Creates an empty file or updates the timestamp of an existing file.

  • When to use: To create an empty file or update a file's timestamp.
  • When not to use: When you don't need a new file or timestamp update.
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    touch newfile.txt
    

` chmod `

Description: Changes file permissions.

  • When to use: To modify file access permissions.
  • When not to use: When you don't need to change permissions.
  • Consequences: Improper use can make files inaccessible.
  • Example( bash command ):
    chmod 755 script.sh
    chmod +x script.sh  # make a script executable
    

` chown `

Description: Changes file owner and group.

  • When to use: To change the owner or group of a file or directory.
  • When not to use: When ownership doesn't need to be changed.
  • Consequences: Can affect file access for users.
  • Example( bash command ):
    chown user:group file.txt
    chown -R user:group dir/  # change owner recursively
    

` ps `

Description: Displays currently running processes.

  • When to use: To monitor running processes.
  • When not to use: N/A
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    ps
    ps aux  # detailed information about all processes
    

` kill `

Description: Terminates processes by PID.

  • When to use: To stop a running process.
  • When not to use: When you don't need to stop any processes.
  • Consequences: Can terminate important processes if not used carefully.
  • Example( bash command ):
    kill 1234  # terminate process with PID 1234
    kill -9 1234  # forcefully terminate process with PID 1234
    

` df `

Description: Reports file system disk space usage.

  • When to use: To check disk space usage.
  • When not to use: N/A
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    df
    df -h  # human-readable format
    

` du `

Description: Estimates file space usage.

  • When to use: To check directory space usage.
  • When not to use: N/A
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    du
    du -h  # human-readable format
    du -sh *  # summarize and show human-readable format for all items
    

` grep `

Description: Searches for patterns in files.

  • When to use: To find specific text within files.
  • When not to use: When you don't need to search within files.
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    grep 'pattern' file.txt
    grep -r 'pattern' /path/to/search/  # recursive search
    

` find `

Description: Searches for files in a directory hierarchy.

  • When to use: To locate files and directories based on conditions.
  • When not to use: When you don't need to search for files.
  • Consequences: None, it's a safe command.
  • Example( bash command ):
    find /path/to/search/ -name 'filename'
    find /path/to/search/ -type f -name '*.txt'  # find all .txt files
    

` tar `

Description: Archives files.

  • When to use: To create or extract archive files.
  • When not to use: When you don't need to archive or extract files.
  • Consequences: Incorrect options can result in unintentional overwriting.
  • Example( bash command ):
    tar -cvf archive.tar file1 file2 dir1  # create archive
    tar -xvf archive.tar  # extract archive
    tar -czvf archive.tar.gz dir1/  # create compressed archive
    

` ssh `

Description: Connects to a remote machine via SSH.

  • When to use: To access and manage a remote machine securely.
  • When not to use: When you don't need remote access.
  • Consequences: Misuse can expose your system to security risks.
  • Example( bash command ):
    ssh user@remotehost
    ssh -i /path/to/keyfile user@remotehost  # using a specific key file

     


Make sure to use these commands carefully,

Especially those that modify or delete files (rm, mv, chmod, chown, etc.), as they can lead to data loss or system issues if misused. Always double-check your commands before executing them to avoid unintended consequences.

I have covered 🪣 almost often used in my daily life. If you feel like that it still missing any command then you can add your opinion 🛜.

• • •

Latest Opinions

No Opinion so far...

End.

No internet connection

Trying to reconnect...

Loading...