Lab 1

Updated 4 Oct 2026

Shell Basics

  • Shell: Program that takes keyboard commands and passes them to the OS
  • Terminal Emulator: Interface to interact with the shell in GUI environment
  • Shell Prompt: username@hostname:directory$ (e.g., student@ubuntu:~$)
    • $ = user-level account
    • # = root/super-user account
    • ~ = home directory (/home/username)

Essential Commands

CommandDescriptionExample Output
pwdPrint working directory - shows current location/home/student
cd <path>Change directory to specified path(no output)
cd ..Go to parent directory(no output)
cd ~ or cdGo to home directory(no output)
cd -Go to previous directory(no output)
lsList files and directories in current directoryDesktop Documents Downloads
exitExit from terminal session(closes terminal)

Listing Options (ls command)

CommandDescriptionUse Case
ls -lLong format (detailed)Shows permissions, owner, size, date
ls -aList all files including hidden (start with .)Shows .bashrc .profile etc.
ls -hHuman-readable file sizesShows 1.5K, 2.3M instead of bytes
ls -tSort by modification timeNewest files first
ls -SSort by file sizeLargest files first
ls -rReverse orderDescending alphabetical
ls -FClassify (append indicator to names)/ for directories, * for executables
ls -dList directory itself, not contentsUsed with -l to see dir details

Example ls -l output:

-rwxr-xr-x 1 root root 1563 May 6 2015 espdiff
  • Field 1 (-rwxr-xr-x): Permissions
  • Field 2 (1): Number of links
  • Field 3 (root): Owner name
  • Field 4 (root): Group name
  • Field 5 (1563): Size in bytes
  • Field 6-8 (May 6 2015): Last modified date
  • Field 9 (espdiff): File/directory name

Pathnames

Absolute Pathname

  • Starts with / (root directory)
  • Works from any location
  • Example: cd /usr/games
  • Analogy: Complete address from country level

Relative Pathname

  • Starts from current directory
  • Uses . (current) and .. (parent)
  • Example: cd ./games or cd games
  • Analogy: Directions from current location

Path Comparison

CommandTypeMeaning
cd /homeAbsoluteGo to /home from root (works anywhere)
cd ./homeRelativeGo to home in current directory
cd homeRelativeSame as cd ./home (shorthand)

Special Symbols

SymbolMeaningExample
/Root directory OR path separator/home/student
~Home directorycd ~ → /home/username
.Current directory./file
..Parent directorycd .. goes up one level
-Previous directorycd - goes back


File Viewing

echo Command

echo "Hello World"                # Print text to terminal
echo "text" > file                # Write text to file (overwrite)
echo "text" >> file               # Append text to file

Output: Prints text directly to terminal

less Command

less filename                     # View file contents (paginated)

Controls in less:

  • Space or f - Next page
  • b - Previous page
  • q - Quit
  • /pattern - Search forward
  • ?pattern - Search backward

File Permissions

Permission Format: rwxrwxrwx

-rwxr-xr--
│└┬┘└┬┘└┬┘
│ │  │  └─ Others permissions (r--)
│ │  └──── Group permissions (r-x)
│ └─────── Owner permissions (rwx)
└───────── File type (- = file, d = directory)

Permission Types

  • r = read (4)
  • w = write (2)
  • x = execute (1)
  • - = no permission (0)

Numeric Permissions

NumberPermissionMeaning
0---No permissions
1--xExecute only
2-w-Write only
3-wxWrite + Execute
4r--Read only
5r-xRead + Execute
6rw-Read + Write
7rwxAll permissions

Common Permission Examples

CodePermissionsUse Case
755rwxr-xr-xStandard executable/directory
644rw-r--r--Standard file
600rw-------Private file (owner only)
777rwxrwxrwxAll permissions (dangerous!)

Changing Permissions

chmod 755 script.sh               # Set rwxr-xr-x
chmod 600 private.txt             # Set rw------- (owner only)
chmod u+x file                    # Add execute for owner
chmod g-w file                    # Remove write for group
chmod o-r file                    # Remove read for others

Format: chmod [ugoa][+-=][rwx] file

  • u = user/owner, g = group, o = others, a = all

Getting Help & History

Documentation

help cd                           # Get help for cd command
man ls                            # Manual page for ls command
man -k keyword                    # Search man pages by keyword

Notes:

  • help works for shell built-ins
  • man works for external commands
  • In man, press q to quit

Command History

history                           # Show all previous commands
!n                                # Execute command number n from history
!!                                # Execute last command
!string                           # Execute most recent command starting with "string"

Keyboard shortcuts:

  • ↑ (Up arrow) - Previous command
  • ↓ (Down arrow) - Next command
  • Ctrl+R - Search command history

Command Structure

General Format

command -options arguments

Example: ls -lh /home

  • ls = command
  • -lh = options (long format + human-readable)
  • /home = argument (what to list)

Common Patterns

command                           # Execute alone
command argument                  # Command with target
command -option                   # Command with modifier
command -option argument          # Command with both
command -opt1 -opt2 arg1 arg2    # Multiple options and arguments

Filesystem Structure

/                               (root directory)
├── bin/                       Binary executables
├── dev/                       Device files
├── etc/                       Configuration files
├── home/                      User home directories
│   └── student/              Your home directory (~)
├── usr/                       User programs
│   ├── bin/                  User binaries
│   ├── lib/                  Libraries
│   └── share/                Shared data
├── var/                       Variable data
│   └── log/                  Log files
└── tmp/                       Temporary files

Key Quiz Topics

1. What does pwd stand for?

Answer: Print Working Directory (shows current location)

2. How to exit terminal?

Answer: exit command

3. Remove directory with contents?

Answer: rm -r DirName (recursive removal)

4. Print text to terminal?

Answer: echo command

5. Go to home directory from anywhere?

Answer: cd ~ or cd or cd - (if home was previous location)

6. Show detailed file info without changing directory?

Answer: ls -l /path (list with path, don't cd first)

7. What does # symbol indicate?

Answer: Root level account (super-user)

8. Absolute vs Relative pathname?

Answer:

  • Absolute: Begins with / (root directory), works from anywhere
  • Relative: Starts from current directory, uses . or ..

9. How to get command documentation?

Answer: man command (manual page)

10. File permission format?

Answer: Access rights for owner, group, and others (read, write, execute)

  • First character: file type
  • Next 9 characters: permissions in groups of 3 (rwx for owner, group, others)

Quick Tips

✓ Tab completion: Press Tab to auto-complete file/directory names
✓ Clear screen: clear or Ctrl+L
✓ Cancel command: Ctrl+C
✓ Case sensitive: File.txt ≠ file.txt
✓ Spaces in names: Use quotes "My File.txt" or escape My\ File.txt
✓ Hidden files: Start with . (e.g., .bashrc)
✓ No undo: Commands are immediate and permanent
✓ Root access: Use with caution - can damage system


Common Command Combinations

ls -lah                          # List all files (including hidden) in long format with human sizes
cd /path && ls                   # Change directory AND list contents
mkdir -p dir1/dir2/dir3         # Create nested directories
cp -r source/ dest/             # Copy directory and all contents
rm -rf directory/               # Force remove directory (dangerous!)
ls -lt | head -10               # Show 10 most recently modified files
history | grep command          # Search command history

Network Commands (Bonus)

ifconfig                         # Show network interface configuration
ping <IP>                        # Test network connectivity
ping 192.168.1.1                # Example: ping router

Ping output: Shows if host is reachable and response time


Remember!

  1. Always double-check before using rm -r
  2. Absolute paths start with /, relative paths don't
  3. Use man or help when unsure about a command
  4. ls -l shows detailed information including permissions
  5. ~ always means your home directory
  6. cd without arguments goes to home directory
  7. Root account (#) has unlimited power - use carefully!