Basic Terminal Commands
Opening the Terminal
- Press
Ctrl + Alt + Tin most desktop environments. - Or search for "Terminal" in the "applications" menu.
Essential Commands
Navigation
pwd: Print working directory (shows current location)ls: List directory contentsls -l: Long listing formatls -a: Show hidden filesls -h: Human-readable file sizes
cd: Change directorycd /path/to/directory: Absolute pathcd relative/path: Relative pathcd ..: Go up one directorycd ~: Go to home directorycd -: Go to previous directory
File Operations
touch filename: Create an empty filemkdir directory: Create a directorymkdir -p parent/child: Create nested directories
cp source destination: Copy files/directoriescp -r source destination: Recursive copy for directories
mv source destination: Move/rename files/directoriesrm filename: Remove filesrm -r directory: Remove directories recursivelyrm -i: Interactive mode (asks for confirmation)
Viewing Files
cat filename: Display file contentsless filename: View file with paging (press 'q' to quit)head filename: Show first 10 linestail filename: Show last 10 linestail -f filename: Follow file (real-time updates)
System Information
whoami: Show current userid: Show user and group IDsdate: Show current date and timeuptime: Show system uptimedf -h: Show disk usagefree -h: Show memory usage
Help and Manual
command --help: Show help for a commandman command: Show manual page (press 'q' to quit)
Command Structure
Most commands follow this pattern:
command [options] [arguments]
Examples:
- ls -la /home/user
- mkdir -p projects/rails_app
Tab Completion
Use the Tab key for auto-completion of commands, file names, and paths.
Command History
history: Show command historyCtrl + R: Search command history- Up/Down arrows: Navigate history
Practice Exercises
- Navigate to your home directory.
- List the contents of the current directory.
- Create a new directory called "practice".
- Inside "practice", create a file called "hello.txt".
- Write "Hello, Linux!" to the file using
echo "Hello, Linux!" > hello.txt. - View the contents of the file.
- Copy the file to "hello_copy.txt".
- Remove the original file.
Next, we'll dive deeper into file and directory management.
