Learn the fundamentals of using the Linux terminal, including navigation, commands, and shortcuts, with this beginner-friendly guide. By following the steps below, you'll master essential commands like ls, cd, cat, grep, and understand navigation, file management, and process control in Linux.
Prerequisites for Getting Started
To start, ensure you have access to a Linux environment (physical machine, virtual machine, or WSL). You'll also need a terminal emulator such as Bash or Zsh to input commands.
prerequisites
- Access to a Linux environment such as:
- A Linux desktop or laptop.
- A virtual machine running Linux.
- Windows Subsystem for Linux (WSL).
- SSH access to a Linux server.
- Installed terminal emulator (e.g., Bash, Zsh, or equivalent).
- Basic understanding of keyboard navigation.
Basic Navigation Commands
Get started with Linux terminal navigation by mastering the following commands.
steps
Print the current working directory using:
bashpwdThis shows where you are in the file system.
List the files and directories in the current directory:
bashlsAdd
-lfor detailed information or-ato include hidden files:bashls -laNavigate to a directory with:
bashcd directorynameMove up one level:
bashcd ..Return to the home directory:
bashcd ~Clear the terminal screen:
bashclear
File Management Essentials
Learn to create and manage files and folders effectively.
steps
Create a new file:
bashtouch filenameDisplay file content:
bashcat filenameCopy a file:
bashcp source destinationMove or rename a file:
bashmv source destinationRemove a file:
bashrm filenameCreate a new directory:
bashmkdir directorynameDelete a directory and its content:
bashrm -r directoryname
Using Editors for File Management
Directly edit files within the terminal using vim or nano. Both tools allow text editing, but their usage differs.
steps
Open a file in vim:
bashvim filename- Press
ito enter INSERT mode. - Use
Escfollowed by:wqto save and quit.
- Press
Open a file in nano:
bashnano filename- Use
Ctrl+Oto save andCtrl+Xto exit.
- Use
Tips:
- Vim requires a learning curve but is powerful for advanced users.
- Nano is more beginner-friendly with instructions displayed at the bottom.
Managing Permissions
Modify file and directory permissions as needed.
steps
Check file permissions using:
bashls -lChange permissions with
chmod:bashchmod 777 filenameReplace
777to control read, write, execute permissions for owner, group, and others.Change file ownership:
bashsudo chown user:group filenameUse
sudoto run commands with superuser privileges:bashsudo command
Using Processes and Commands Efficiently
Manage processes and make better use of the terminal through the following commands.
steps
List active processes:
bashps auxKill a process by ID:
bashkill PIDSuspend a process with
Ctrl+Zand bring it to the foreground:bashfgRedirect command outputs: Standard output:
bashcommand > file.txtAppend to an existing file:
bashcommand >> file.txtRedirect errors:
bashcommand 2> error.log
Additional Concepts and Utilities
Expand your knowledge with these advanced but helpful commands.
steps
Set environment variables:
bashexport VAR=valueAccess the variable:
bashecho $VARInspect and mount block devices:
bashlsblk mount /dev/device_name /mnt/mount_pointUnmount devices:
bashumount /mnt/mount_pointRedirect unwanted output to null:
bashcommand > /dev/null
FAQ
What is the Linux terminal used for?
The Linux terminal allows users to interact directly with the operating system through text-based commands to perform tasks such as file management, software installation, and process control.
What's the difference between Ctrl+C and Ctrl+Shift+C?
Ctrl+Cinterrupts a running command or process in the terminal.Ctrl+Shift+Cis used to copy highlighted text from the terminal.
How do I check my current directory in Linux?
Use the pwd command to display your current working directory.
How can I see file permissions in Linux?
Run ls -l to view detailed file information, including the permissions.
Official reference: GNU Bash manual.