Basic Linux Commands

Basic Linux Commands

1. pwd – Print Working Directory

What it does: Shows the full path of your current directory.

pwd

Example Output:

/home/yourname/projects

2. ls – List Directory Contents

What it does: Lists files and folders in the current directory.

ls

Variants:

  • ls -l – long format (detailed)

  • ls -a – shows hidden files

  • ls -lh – human-readable sizes

Example:

ls -lah

3. cd – Change Directory

What it does: Navigate to a different directory.

cd folder_name

Examples:

cd Documents cd .. # Go one level up cd / # Go to root directory cd ~ # Go to home directory

4. mkdir – Make Directory

What it does: Creates a new folder.

mkdir new_folder

5. touch – Create an Empty File

What it does: Creates a new, empty file.

touch file.txt

You can also create multiple:

touch file1.txt file2.txt

6. rm – Remove Files or Folders

What it does: Deletes files or directories.

⚠️ Be careful with this one!

rm file.txt # Delete a file rm -r folder_name # Delete a folder and its contents

7. cp – Copy Files or Folders

cp file1.txt file2.txt # Copy file1 to file2 cp -r dir1 dir2 # Copy entire folder

8. mv – Move or Rename Files

mv oldname.txt newname.txt # Rename file mv file.txt /path/to/folder/ # Move file to a folder

9. cat – View File Contents

cat file.txt

To create and write a file:

cat > file.txt

10. nano or vim – Edit Files

nano file.txt # Easy text editor vim file.txt # Advanced (but steeper learning curve)

11. clear – Clear the Terminal

clear

Shortcut: Ctrl + L

12. history – Show Command History

history

You can re-run a command:

!123 # Run command number 123

13. man – Manual (Help) for a Command

man ls

To quit the manual: press q.

14. df -h – Show Disk Space Usage

df -h

-h means human-readable (MB, GB, etc.)

15. top – Show Running Processes (Live Monitor)

top

Press q to exit.

Bonus: Combine Commands

You can chain commands with &&:

mkdir test && cd test

Would you like this turned into a cheat sheet PDF, or should I explain more advanced commands like permissions (chmod), searching (grep), or networking tools?

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
Ad