Linux Cheat Sheet with Examples

Β·

3 min read

πŸ“‚File and Directory Operations:

  1. ls: List files and directories in the current location. πŸ“‚πŸ‘€

    Example: ls

  2. cd: Change directory to a specified location. πŸšͺπŸ“

    Example: cd /path/to/directory

  3. pwd: Print the current working directory. πŸ—ΊοΈπŸ 

    Example: pwd

  4. mkdir: Create a new directory. πŸ“πŸ†•

    Example: mkdir new_directory

  5. rm: Remove files and directories. πŸ—‘οΈπŸ“‚

    Example: rm file.txt, rm -r directory

  6. cp: Copy files and directories. πŸ“‹πŸ“

    Example: cp file.txt destination_folder

  7. mv: Move or rename files and directories. πŸ“‚βž‘οΈπŸ“‚

    Example: mv file.txt new_location, mv old_name.txt new_name.txt

πŸ“„File Content and Editing:

  1. cat: Display the contents of a file. πŸ“„πŸ‘€

    Example: cat file.txt

  2. less: View a file interactively. πŸ“„πŸ”Ž

    Example: less file.txt

  3. head: Display the first few lines of a file. πŸ“„πŸ”

    Example: head file.txt

  4. tail: Display the last few lines of a file. πŸ“„πŸ”š

    Example: tail file.txt

  5. touch: Create an empty file or update the timestamp of an existing file. πŸ“„βœ¨

    Example: touch new_file.txt

  6. nano: Basic text editor πŸ“„βœ¨

    Example: nano new_file.txt

  7. vim: Advanced text editorπŸ“„βœ¨

    Example: vim new_file.txt

πŸ”File Permissions:

  1. chmod: Change the permissions of a file or directory. πŸ”πŸ”§

    Example: chmod 755 file.sh

  2. chown: Change the owner of a file or directory. πŸ‘€πŸ”§

    Example: chown user_name file.txt

  3. chgrp: Change group ownership.πŸ‘€πŸ”§

    Example: chgrp [option] groupfile.txt

πŸ”„Process Management:

  1. ps: Display running processes. πŸ”„πŸ“

    Example: ps aux πŸ”„πŸ“

  2. top: Monitor system processes and resource usage. πŸ”„πŸ”

    Example: top πŸ”„πŸ”

  3. kill: Terminate a process. β›”πŸ”„

    Example: kill PID β›”πŸ”„ (Replace PID with the Process ID of the process you want to terminate.)

  4. killall: Terminate processes by name. β›”πŸ”„πŸ‘₯

    Example: killall process_name β›”πŸ”„πŸ‘₯ (Replace process_name with the name of the process you want to terminate.)

πŸ’ΎDisk and Memory Usage:

  1. df - Show disk space usage. πŸ’Ύ

    Example: df -h

  2. free - Display system memory usage. 🧠

    Example: free -h

  3. du - Show file and directory disk usage. 🧠 Example: du filename

🌐Network and Connectivity:

  1. ping - Check network connectivity to a specific host🌐

    Example: ping google.com

  2. ifconfig or ip - Display network interface information🌐

    Example: ifconfig or ip address

  3. ssh - Connect to a remote server using Secure ShellπŸš€

    Example: ssh username@remote_server

  4. scp - Securely copy files between local and remote systemsπŸ“₯πŸ“€

    Example: scp file.txt username@remote_server:/path/to/destination

  5. wget or curl - Download files from the internetπŸŒπŸ’Ύ

    Example: wget http://example.com/file.zip or curl -O http://example.com/file.zip

πŸ”‘User and Permission Management:

  1. whoami: Print the current username. πŸ”

    • Example: whoami

    • Output: john_doe

  2. πŸ”’ passwd: Change the password for the current user. πŸ”‘

    • Example: passwd

    • Output: Changing password for user john_doe.

  3. πŸ‘€ useradd: Add a new user. πŸ‘€βž•

    • Example: useradd new_user

    • Output: A new user "new_user" is added.

  4. πŸ‘€ usermod: Modify user settings. πŸ‘€πŸ”§

    • Example: usermod -aG developers john_doe

    • Output: User "john_doe" is added to the "developers" group.

  5. πŸ‘₯ groupadd: Create a new group. πŸ‘₯βž•

    • Example: groupadd new_group

    • Output: A new group "new_group" is created.

  6. ❌ userdel: Delete a user. πŸ‘€πŸ—‘οΈ

    • Example: userdel old_user

    • Output: User "old_user" is deleted.

πŸ’»Package Management:

  • apt or apt-get: Package manager for Debian-based systems.

  • yum: Package manager for Red Hat-based systems.

  • dnf: Package manager for newer Fedora systems.

🌟Conclusion:

In conclusion, this comprehensive Linux commands cheat sheet equips you with essential tools for managing processes and user permissions. πŸ§πŸ” With examples, you can easily grasp the power of commands. Empower yourself to navigate and control your Linux system with confidence, ensuring efficient resource management and secure user access. Remember to use these commands with caution, especially those that can modify or delete files and directories. Always double-check before executing potentially dangerous commands. Happy Linux command-line exploring! πŸ§πŸ’»

Β