Linux Fundamentals

Basic Commands

pwd: Print Working Directory. Shows the current directory path.

$ pwd
/home/user

ls: List directory contents.

$ ls
Desktop  Documents  Downloads  Music  Pictures

cd: Change Directory.

$ cd Documents
$ pwd
/home/user/Documents

Path Types

Absolute Path: Begins from the root directory (/).

$ cd /home/user/Documents

Relative Path: Begins from the current directory.

$ cd ../Downloads

File Operations

Creation

touch: Create an empty file.

$ touch newfile.txt

mkdir: Create a new directory.

$ mkdir newdir

Deletion

rm: Remove a file.

$ rm file.txt

rmdir: Remove an empty directory.

$ rmdir emptydir

rm -r: Remove a directory and its contents recursively.

$ rm -r dir

Moving

mv: Move or rename a file or directory.

$ mv oldname.txt newname.txt
$ mv file.txt /path/to/destination/

Copying

cp: Copy a file.

$ cp file.txt /path/to/destination/

cp -r: Copy a directory and its contents.

$ cp -r sourcedir /path/to/destination/

Logs and Permissions

Logs

  • System logs are usually stored in /var/log/.
  • View logs using cat, less, or tail.
    $ tail /var/log/syslog

TTY and Bash Basics

Bash

  • Bash is the default shell in many Linux distributions.
  • Scripts are executed in the shell using bash scriptname.sh.

Keyboard Shortcuts

  • Ctrl + C: Terminate the current running process.
  • Tab: Autocomplete commands and filenames.

Partitions

  • Partitions divide a hard disk into separate sections.
  • View partitions using lsblk or fdisk -l.
    $ lsblk
    $ sudo fdisk -l

SSH (Secure Shell)

ssh: Connect to a remote machine.

$ ssh user@hostname

curl and wget

curl: Transfer data from or to a server.

$ curl http://example.com

wget: Retrieve files from the web.

$ wget http://example.com/file.zip