Monday, 10 April 2017

Linux Basic Commands Cheat Sheet: A Quick Reference Guide

Standard

Cheat Sheet in Image Format





Essential Linux Commands with Examples

Linux commands are the backbone of managing and interacting with a Linux-based operating system. Whether you're a beginner or an advanced user, mastering these commands can greatly enhance your productivity. Below is a list of essential commands categorized with their descriptions and examples.


1. File and Directory Commands

ls – List Files and Directories

Displays the files and directories in the current directory.

ls # Basic listing ls -l # Detailed listing with permissions ls -a # Include hidden files

Example:
If you run ls -l in /home/user, it might display:

-rw-r--r-- 1 user user 1234 Jan 25 10:00 file.txt drwxr-xr-x 2 user user 4096 Jan 25 09:30 my_folder

cd – Change Directory

Moves to a specified directory.

cd /home/user/documents # Go to 'documents' folder cd .. # Move one level up cd ~ # Go to the home directory

Example:

cd /var/log pwd # Output: /var/log

mkdir – Create a Directory

Creates a new folder.


mkdir new_folder

Example:
Running mkdir projects creates a folder named projects in the current directory.


pwd – Print Working Directory

Displays the full path of your current directory.


pwd

Example:
If you're in /home/user, the output will be:


/home/user

2. File Operations

touch – Create a File

Creates an empty file.


touch myfile.txt

Example:
Running touch report.txt creates an empty file named report.txt in the current directory.


cp – Copy Files

Copies files or directories.


cp source.txt destination.txt # Copy file cp -r source_folder/ dest_folder/ # Copy directory

Example:

cp file.txt backup/ # Copies file.txt into the backup folder

mv – Move or Rename Files

Renames or moves a file or directory.

mv oldname.txt newname.txt # Rename file mv file.txt /destination/ # Move file

Example:


mv report.txt ~/documents/ # Moves report.txt to the documents folder

rm – Remove Files

Deletes files or directories.


rm file.txt # Remove a file rm -r folder_name # Remove a folder

Example:


rm old_file.txt # Deletes the file named old_file.txt

3. Viewing File Contents

cat – Display File Contents

Shows the content of a file.


cat file.txt

Example:
If file.txt contains "Hello, World!", running cat file.txt will display:


Hello, World!

grep – Search Within Files

Searches for specific patterns in a file.


grep "text" file.txt # Case-sensitive search grep -i "text" file.txt # Case-insensitive search

Example:


grep "error" log.txt # Searches for the word "error" in log.txt

4. User Management

whoami – Display Current User

Shows the username of the logged-in user.

whoami

Example:
Running whoami might output:


john

5. Process Management

ps – Display Running Processes

Lists active processes.


ps ps aux # Displays all processes in detail

Example:

ps aux | grep firefox # Finds all processes related to Firefox

kill – Terminate Processes

Stops a process by its process ID (PID).


kill PID

Example:


kill 12345 # Terminates the process with PID 12345

6. Disk and System Information

df – Display Disk Usage

Shows how much disk space is used and available.


df -h # Human-readable format

Example:


Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 30G 40% /

uname – System Information

Displays details about the operating system.


uname -a

Example:


Linux mypc 5.15.0-50-generic #55~20.04.1-Ubuntu SMP x86_64 GNU/Linux

7. Networking Commands

ping – Test Network Connectivity

Checks the connection to a host.


ping google.com

Example:


PING google.com (142.250.182.14): 56 data bytes 64 bytes from 142.250.182.14: icmp_seq=0 ttl=115 time=22.3 ms

curl – Fetch Data from a URL

Transfers data from or to a server.


curl https://example.com

Example:
Running curl https://api.github.com fetches API data from GitHub.


Conclusion

This cheat sheet provides a handy reference to commonly used Linux commands. With these commands, you can easily manage files, processes, users, and networks on your Linux system. Bookmark this for quick access, and let me know if you’d like more commands or tips!

2 comments:

  1. Before studying at the university, they said that it would be so difficult, and in order to somehow help myself in my studies, I began to use the fact that there are master papers reviews, it helps me in doing any written work

    ReplyDelete
  2. ทางเข้า pg slot 88 แล้วกรอกข้อมูลส่วนตัวของคุณลงในฟอร์มการสมัคร หลังจากนั้นก็เสร็จสิ้นขั้นตอนการสมัครแล้ว pg slot คุณจะได้รับชื่อผู้ใช้งานและรหัสผ่านเข้าสู่ระบบจากนั้นคุณก็สามารถเลือกเกมสล็อต

    ReplyDelete