Getting Started with Linux
Essential First Commands
pwd
Print Working Directory - shows where you are currently located
whoami
Display your current username
uname -a
Show system information
date
Display current date and time
Getting Help
man [command]
Display manual page for a command (e.g., man ls)
[command] --help
Quick help for most commands (e.g., ls --help)
which [command]
Show the full path of a command
💡 Tip: Use the TAB key for auto-completion! Type the first few letters and press TAB to complete file/directory names. Press TAB twice to see all possibilities.
File Management
Creating & Editing
touch filename.txt
Create an empty file or update timestamp
mkdir directory_name
Create a new directory
mkdir -p parent/child/grandchild
Create nested directories
nano filename.txt
Edit file with nano (beginner-friendly editor)
vim filename.txt
Edit file with vim (more powerful, steeper learning curve)
Viewing Files
cat filename.txt
Display entire file content
cat file1.txt file2.txt
Display multiple files in sequence
cat file1.txt file2.txt > combined.txt
Combine multiple files into one
cat > newfile.txt
Create file and type content (Ctrl+D to save and exit)
less filename.txt
View file with pagination (q to quit)
head filename.txt
Show first 10 lines
head -n 20 filename.txt
Show first 20 lines
tail filename.txt
Show last 10 lines
tail -f logfile.log
Follow file in real-time (great for logs!)
Editing with Nano (Beginner-Friendly)
nano filename.txt
Open file in nano editor
💡 Nano Keyboard Shortcuts:
• Ctrl + O - Save file (WriteOut)
• Ctrl + X - Exit nano
• Ctrl + K - Cut line
• Ctrl + U - Paste line
• Ctrl + W - Search in file
• Ctrl + \ - Search and replace
• Ctrl + G - Show help
The shortcuts are shown at the bottom of nano. The ^ symbol means Ctrl key.
• Ctrl + O - Save file (WriteOut)
• Ctrl + X - Exit nano
• Ctrl + K - Cut line
• Ctrl + U - Paste line
• Ctrl + W - Search in file
• Ctrl + \ - Search and replace
• Ctrl + G - Show help
The shortcuts are shown at the bottom of nano. The ^ symbol means Ctrl key.
Practice with Nano:
1. Create a new file: nano test.txt
2. Type some text
3. Press Ctrl+O, then Enter to save
4. Press Ctrl+X to exit
5. View your file: cat test.txt
Copying & Moving
cp source.txt destination.txt
Copy file
cp -r source_dir/ destination_dir/
Copy directory recursively
mv oldname.txt newname.txt
Rename or move file
mv file.txt /path/to/directory/
Move file to different directory
Deleting
rm filename.txt
Delete file
rm -r directory_name/
Delete directory and contents
rm -rf directory_name/
Force delete without prompts
⚠️ Warning: rm -rf is very powerful and dangerous! There's no recycle bin in Linux. Deleted files are gone forever. Always double-check before using this command.
Searching
find . -name "*.js"
Find all JavaScript files in current directory and subdirectories
grep "search_term" filename.txt
Search for text within a file
grep -r "search_term" /path/to/directory/
Recursively search in all files in directory
locate filename
Quickly find files by name (uses database)
SSH & File Transfer
Connecting via SSH
ssh username@server_ip
Connect to remote server
ssh -p 2222 username@server_ip
Connect using specific port
ssh -i /path/to/key.pem username@server_ip
Connect using SSH key file
exit
Disconnect from SSH session
Transferring Files with SCP
scp local_file.txt username@server:/remote/path/
Upload file to server
scp username@server:/remote/file.txt /local/path/
Download file from server
scp -r local_folder/ username@server:/remote/path/
Upload entire directory
scp -P 2222 file.txt username@server:/path/
Transfer using specific port (note: capital P)
Transferring Files with SFTP
sftp username@server_ip
Start SFTP session
put local_file.txt
Upload file (within SFTP session)
get remote_file.txt
Download file (within SFTP session)
mput *.txt
Upload multiple files matching pattern
lcd /local/path
Change local directory (within SFTP)
lpwd
Show local directory (within SFTP)
Rsync - Advanced Sync
rsync -avz local_folder/ username@server:/remote/path/
Sync folder to server (only transfers changes)
rsync -avz --delete local/ username@server:/remote/
Sync and delete files that don't exist locally
rsync -avz --progress local/ username@server:/remote/
Show progress during transfer
💡 Best Practice: For large deployments, use rsync instead of scp. It's much faster for repeated transfers because it only sends changed files.
Common Workflow:
1. Connect to server: ssh user@server
2. Navigate to app directory: cd /var/www/myapp
3. Create backup: cp -r . ../myapp_backup
4. Exit SSH: exit
5. Upload new files: rsync -avz --delete ./dist/ user@server:/var/www/myapp/
File Permissions
Understanding Permissions
When you run
This breaks down as:
• First character: file type (- = file, d = directory)
• Next 3: owner permissions (rwx)
• Next 3: group permissions (rwx)
• Last 3: others permissions (rwx)
r = read (4), w = write (2), x = execute (1)
ls -l, you see something like: -rw-r--r--This breaks down as:
• First character: file type (- = file, d = directory)
• Next 3: owner permissions (rwx)
• Next 3: group permissions (rwx)
• Last 3: others permissions (rwx)
r = read (4), w = write (2), x = execute (1)
Changing Permissions
chmod 755 script.sh
Owner: read+write+execute, Others: read+execute
chmod 644 file.txt
Owner: read+write, Others: read only
chmod +x script.sh
Add execute permission for all
chmod -R 755 directory/
Recursively change permissions
Changing Ownership
chown username file.txt
Change file owner
chown username:groupname file.txt
Change owner and group
chown -R username directory/
Recursively change ownership
sudo chown www-data:www-data /var/www/html/
Common for web server files (requires sudo)
💡 Common Permission Patterns:
• 755 - Executable scripts and directories
• 644 - Regular files (HTML, CSS, JS)
• 600 - Private files (config with passwords)
• 777 - All permissions (avoid unless necessary - security risk!)
• 755 - Executable scripts and directories
• 644 - Regular files (HTML, CSS, JS)
• 600 - Private files (config with passwords)
• 777 - All permissions (avoid unless necessary - security risk!)
Process Management
Viewing Processes
ps aux
Show all running processes
ps aux | grep node
Find specific processes (e.g., Node.js)
top
Real-time process monitor (press q to quit)
htop
Better version of top (may need to install)
Managing Processes
kill 1234
Terminate process with ID 1234
kill -9 1234
Force kill process
killall node
Kill all processes named "node"
nohup command &
Run command in background, keeps running after logout
System Resources
df -h
Show disk space usage (human readable)
du -sh *
Show size of directories in current location
free -h
Show memory usage
uptime
Show how long system has been running
Service Management (systemd)
sudo systemctl status nginx
Check service status
sudo systemctl start nginx
Start a service
sudo systemctl stop nginx
Stop a service
sudo systemctl restart nginx
Restart a service
sudo systemctl enable nginx
Enable service to start on boot
Windows vs Linux Commands
| Windows (CMD/PowerShell) | Linux | Description |
|---|---|---|
| dir | ls | List directory contents |
| cd | cd | Change directory (same!) |
| cd | pwd | Show current directory |
| copy | cp | Copy files |
| move | mv | Move/rename files |
| del | rm | Delete files |
| rmdir /s | rm -r | Delete directory |
| mkdir | mkdir | Create directory (same!) |
| type | cat | Display file content |
| find | grep | Search text in files |
| cls | clear | Clear screen |
| echo | echo | Print text (same!) |
| tasklist | ps | List processes |
| taskkill | kill | Kill process |
| ipconfig | ifconfig / ip addr | Network configuration |
| ping | ping | Test connectivity (same!) |
| notepad | nano / vim | Text editor |
| \ (backslash) | / (forward slash) | Path separator |
| C:\, D:\ | / (root) | File system root |
💡 Key Differences:
• Linux is case-sensitive (File.txt ≠ file.txt)
• Use forward slashes / not backslashes \
• No drive letters (C:, D:) - everything starts from /
• Hidden files start with a dot (.bashrc)
• Executable files need execute permission, no .exe extension needed
• Linux is case-sensitive (File.txt ≠ file.txt)
• Use forward slashes / not backslashes \
• No drive letters (C:, D:) - everything starts from /
• Hidden files start with a dot (.bashrc)
• Executable files need execute permission, no .exe extension needed