Skip to content

A concise guide to essential Linux commands with examples and screenshots. Covers navigation, file management, system configuration, and more for efficient Linux usage.

Notifications You must be signed in to change notification settings

panwar100/linux-command-cheat-sheet1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

linux-command-cheat-sheet1

This repository contains a comprehensive guide to common Linux commands with examples and screenshots. It's designed to help users quickly reference essential commands for navigating, managing files, and configuring the system in a Linux environment.

Table of Contents

  1. User Prompt
  2. PWD
  3. CD
  4. Date and Cal
  5. Hostnamectl
  6. LS Command
  7. Mkdir and Rmdir
  8. Init Commands
  9. Create File
  10. Overwrite or Create File (cat >)

1) User prompt

root@localhost ~# Explanation

This prompt represents the following:

  • root: You are logged in as the root user, which has full administrative privileges.
  • localhost: The hostname is set to localhost, the default for systems without a unique name.
  • ~: The home directory of the root user (/root).
  • #: Indicates you are logged in as the root user (a $ would indicate a non-root user).

Screenshot from 2024-11-27 19-06-29

2) pwd Command

The pwd command prints the current working directory.

Screenshot from 2024-11-27 19-10-32

3) cd Command

The cd command allows you to change directories.

Screenshot from 2024-11-27 19-14-03

Going Up One Level:

The cd .. command takes you to the parent directory.

Screenshot from 2024-11-27 19-17-09

4) date and cal Commands

  • date: Displays the current system date and time.

Screenshot from 2024-11-27 19-19-18

  • Example variants: +%a, +%A, +%x, +%X, +%h, +%H for various formats.

Screenshot from 2024-11-27 19-36-15

  • cal: Displays a calendar in the terminal.

Screenshot from 2024-11-27 19-22-16 Screenshot from 2024-11-27 19-23-23

  • View calendar for a specific year or past/future months.

Screenshot from 2024-11-27 19-25-59

5) hostnamectl Command

Use hostnamectl to manage the system's hostname and related settings.

Screenshot from 2024-11-27 19-42-31

To set a new hostname, use hostnamectl set-hostname <hostname>.

Screenshot from 2024-11-27 19-50-00

then type bash or rebot system for refresh

6) ls Command

The ls command lists directory contents.

Screenshot from 2024-11-27 19-51-22

Long Format:

The ls -l command shows detailed information about files and directories:

  • File Permissions
  • Number of Links
  • Owner and Group
  • File Size
  • Last Modification Time
  • File/Directory Name

Screenshot from 2024-11-27 19-55-12

Hidden Files: To list hidden files, use ls -a.

Screenshot from 2024-11-27 20-01-11

7) mkdir and rmdir Commands

  • mkdir: Creates directories.

    • Example: mkdir -p j/k/l creates nested directories j/k/l.
    • Example: mkdir ab{1..10} creates directories ab1, ab2, ..., ab10.
  • rmdir: Removes directories (only empty directories).

Screenshot from 2024-11-27 20-29-41 Screenshot from 2024-11-27 20-31-30 Screenshot from 2024-11-27 20-44-46

where cd ../.. command in Linux is used to move up two levels in the directory structure from your current location

Screenshot from 2024-11-27 20-47-44

  • remove the directory j and all its contents (including subdirectories and files)

Screenshot from 2024-11-27 20-50-32

where

  • -r: This option stands for recursive removal. It tells rm to delete directories and their contents recursively, including all files and subdirectories inside j.
  • -v: This option stands for verbose. It tells rm to display what it's doing, printing each file and directory it removes.
  • -f: This option stands for force. It forces rm to remove files and directories without prompting for confirmation, even if the files are write-protected or if the directory is not empty.

-Remove all files and directories (including hidden ones, if .* is used) in the current directory.

Screenshot from 2024-11-27 20-55-04

8) init Commands

  • init 0: Shuts down the system.
  • init 6: Reboots the system.

9) Create File

Use commands to create files in Linux.

Screenshot from 2024-11-27 21-09-58

10) cat > Command

The cat > command allows you to create or overwrite a file and input text interactively.

  • To exit and save, press Ctrl+D.
  • note: use cat and less for read the content inside the file

Screenshot from 2024-11-27 21-12-15

Conclusion

This cheat sheet covers some of the most essential Linux commands to navigate the file system, manage files, and configure your system. For more advanced usage, consider exploring additional command-line resources and man pages.

About

A concise guide to essential Linux commands with examples and screenshots. Covers navigation, file management, system configuration, and more for efficient Linux usage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published