BASH implements a command-line interface through kernel system calls, providing text-based control over operating system functions. The shell executes commands through process spawning, file descriptor manipulation, and signal handling while maintaining an interactive command history buffer and terminal state management.
_10ls # List directory contents_10ls -l # Long format listing with permissions_10ls -la # Include hidden files_10cd dir # Change current directory_10cd .. # Move to parent directory_10cd ~/ # Access home directory_10cd / # Access root directory_10pwd # Print working directory path
_10# Create a temporary workspace and move into it_10mkdir -p ~/tmp-bash-demo && cd ~/tmp-bash-demo_10_10# Show it's initially empty, then create a couple of items and navigate_10ls -la_10mkdir notes && touch README.txt_10cd notes && pwd && cd ..
_10mkdir dir # Create directory structure_10rm file # Remove file reference_10rm -f file # Force file deletion_10rm -rf dir # Recursive directory removal_10cp file1 file2 # Copy file data_10mv file1 file2 # Move/rename file_10touch file # Update file timestamp
_16# Stay inside ~/tmp-bash-demo from the previous step_16pwd_16_16# Download a small, stable text file to work with_16# W3C provides a tiny test file that is safe to fetch_16curl -L https://www.w3.org/TR/PNG/iso_8859-1.txt -o sample.txt_16_16# Duplicate and rename files_16cp sample.txt copy-of-sample.txt_16mv copy-of-sample.txt notes/renamed-sample.txt_16_16# Create and remove directories/files_16mkdir -p archives_16touch empty.log_16rm empty.log_16rm -rf archives
_10cat file # Output file contents_10cat > file # Write stdin to file_10cat >> file # Append stdin to file
_14# View the first few lines of the downloaded file_14head -n 5 sample.txt_14_14# Create a quick note file via stdin redirection_14cat > notes/todo.txt <<'EOF'_14- read the downloaded sample_14- write a short summary_14EOF_14_14# Append another line_14echo "- archive when done" >> notes/todo.txt_14_14# Display results_14cat notes/todo.txt
_10cat /proc/cpuinfo # CPU architecture data_10cat /proc/meminfo # Memory allocation status_10free # Memory utilization_10df # Filesystem usage_10uname -a # Kernel configuration
_10date # System time_10uptime # Runtime statistics_10whoami # Current user context_10w # Active user sessions
_10ping host # ICMP echo request_10dig domain # DNS query execution_10whois domain # Domain registration data
_10wget file # HTTP/FTP file retrieval_10curl url # URL data transfer_10ssh user@host # Secure shell connection_10ssh -p port user@host # Custom port connection
_10tar cf archive.tar files # Create archive_10tar xf archive.tar # Extract contents_10tar tf archive.tar # List archive contents
_10grep pattern files # Pattern matching_10grep -r pattern dir # Recursive search_10locate file # Database file search_10whereis app # Binary location search
_10man command # Display documentation_10info command # GNU documentation_10command --help # Usage information
_10# Absolute vs relative paths_10cd /usr/bin # absolute path (starts with /)_10cd .. # relative path (parent directory)_10pwd # print current directory_10_10# Special directories_10echo ". is" $(pwd) # current directory_10echo ".. is" $(cd ..; pwd) # parent directory
_10ls -a # show entries starting with ._10touch .hidden # create a hidden file_10ls -la # verify it exists
_10ls -l sample.txt # view permissions like rw-r--r--_10chmod u+x sample.txt # give owner execute (beginner note: rarely needed for plain text)_10ls -l sample.txt
_10rm -i sample.txt # interactive prompt before deleting_10# Avoid using sudo and rm -rf until later lessons
_10less sample.txt # scroll with arrows/PageUp/PageDown; press q to quit_10cat sample.txt # prints entire file at once (fine for small files)
_10whoami # your username_10id # uid, groups_10ls -l # check file owner and group
_10df -h # disk usage by filesystem (human-readable)_10du -sh . # size of current directory_10free -h # memory (if not available, try: cat /proc/meminfo)
_10ping -c 2 example.com # test connectivity (Ctrl+C to stop early)_10curl -I https://example.com # fetch only HTTP headers
_10ps aux | head # list running processes (first lines)_10top # interactive process viewer (q to quit)
_10man ls # manual page (q to quit)_10ls --help # quick usage summary_10tldr ls # concise examples (if tldr is installed)
_10# Check if a known binary is executable (read-only example)_10ls -l /bin/ls_10test -x /bin/ls && echo "ls is executable"_10_10# Prefer explicit relative/absolute paths when running your own programs_10# Avoid adding '.' (current directory) to PATH to reduce accidental execution
_10# Inspect PATH and how a command is resolved_10echo "$PATH"_10command -v ls # Shows the path that will be used for 'ls'_10_10# Keep untrusted locations (like '.') out of PATH
_10FILENAME="My File With Spaces.txt"_10echo "demo" > "$FILENAME" # Correct: file name preserved_10cat $FILENAME 2>/dev/null # Incorrect: will try to read 5 separate tokens_10cat "$FILENAME" # Correct
_10# Create a file literally named * (asterisk)_10touch '\*'_10# Correctly reference it with quoting_10ls -l "*"_10# When using regex-like characters in grep, quote to prevent the shell from expanding_10grep "main()" sample.txt
_10history | tail -n 5 # View recent commands_10!! # Re-run last command_10!curl # Re-run last command that started with 'curl'_10Ctrl+R # Interactive reverse search (press in a real shell)
_10# In an interactive shell, type:_10# cat sam<Tab>_10# It should complete to 'sample.txt' if present in the current directory
_10alias ll='ls -lah'_10ll | head_10_10# Persist aliases by adding them to ~/.bashrc or ~/.bash_profile
_19# View PATH and see where commands come from_19echo "$PATH"_19command -v ls_19_19# Temporarily add a directory to PATH for this shell only_19TEMP_DIR="$HOME/tmp-bin"; mkdir -p "$TEMP_DIR"_19PATH="$TEMP_DIR:$PATH"; export PATH_19echo "$PATH" | tr ':' '\n' | head_19_19# Local vs exported variables_19FOO="not exported"_19BAR="exported"; export BAR_19_19# Child processes inherit only exported variables_19bash -c 'printf "FOO=%s\nBAR=%s\n" "$FOO" "$BAR"'_19_19# Subshell scope (parent remains unchanged)_19(BAZ=subshell_only; echo "Inside subshell BAZ=$BAZ")_19echo "Outside subshell BAZ=$BAZ" # likely empty
_24# Start a 30-second sleep in the foreground, then stop it with Ctrl+Z to suspend_24sleep 30_24# Press Ctrl+Z now to suspend the job_24_24# List jobs, resume in background, then bring to foreground_24jobs_24bg %1_24fg %1_24_24# Run directly in background with & and disown if desired_24sleep 20 &_24jobs_24_24# Lower priority (positive nice value means lower priority)_24nice -n 10 sleep 25 &_24ps aux | grep sleep | head_24_24# Send a gentle termination signal to the first job (replace %1 with correct job id if needed)_24jobs_24kill -TERM %1_24_24# If a process ignores TERM, use INT or KILL as last resort_24# kill -INT %1 # like pressing Ctrl+C_24# kill -KILL %1 # force kill
_10ls | wc -l # count directory entries_10curl -s https://example.com | head -n 5 # preview first 5 lines of output_10echo "error: something" | grep error # filter lines containing a word_10_10# Redirect stdout and stderr_10echo "hello" > out.txt # overwrite_10echo "again" >> out.txt # append_10ls not_a_file 2> errors.log # send errors to a file
_10# From your demo folder_10cd ~/tmp-bash-demo_10_10find . -type f -name "*.txt" # find text files_10find . -type f -size -10k # smaller than 10 KB_10find . -type f -mtime -1 # modified in last 24 hours_10find . -type f -name "*sample*" -print # print matched paths
BASH command line operations provide system administration capabilities through a text-based interface. Understanding command syntax and shell behavior enables efficient system management and automation implementation.