
The Linux command line for beginners
Overview
The Linux command line, also known as the terminal or shell, is a powerful tool that allows users to interact directly with the operating system. While it might seem intimidating at first, mastering a few basic commands can significantly enhance your efficiency and ability to manage your system. This overview introduces some essential commands that will help beginners navigate the Linux command line with confidence.![]() |
File and Directory Operations
Listing Files
- ls : Lists files and directories in the current directory.
- ls -l : Lists files and directories with detailed information.
- ls -a : Lists all files, including hidden files.
Changing Directories
- cd [directory] : Changes the current directory to the specified directory.
- cd .. : Moves up one directory level.
- cd ~ : Changes to the home directory.
Creating Directories
- mkdir [directory] : Creates a new directory.
Removing Directories
- rmdir [directory] : Removes an empty directory.
- rm -r [directory] : Removes a directory and its contents recursively.
Copying Files and Directories
- cp [source] [destination] : Copies a file.
- cp -r [source_directory] [destination_directory] : Copies a directory and its contents.
- Moving/Renaming Files and Directories
- mv [source] [destination] : Moves or renames a file or directory.
Removing Files
- rm [file] : Removes a file.
- rm -r [directory] : Removes a directory and its contents.
Viewing and Editing Files
Viewing File Contents
- cat [file] : Displays the contents of a file.
- more [file] : Displays file contents one screen at a time.
- less [file] : Similar to more, but with backward navigation.
- head [file] : Displays the first 10 lines of a file.
- tail [file] : Displays the last 10 lines of a file.
- tail -f [file] : Displays the last 10 lines of a file and updates in real-time.
Editing Files
- nano [file] : Opens a file in the Nano text editor.
- vi [file] or vim [file] : Opens a file in the Vi/Vim text editor.
File Permissions
Changing File Permissions
chmod [permissions] [file] : Changes the permissions of a file or directory.Example: chmod 755 [file] : Sets read, write, and execute permissions for the owner, and read and execute permissions for others.
Changing File Ownership
chown [owner]:[group] [file] : Changes the owner and group of a file or directory.Example: chown user:group [file] : Changes the owner to 'user' and the group to 'group'.
System Information
Current Directory
pwd : Prints the current working directory.Disk Usage
- df : Displays disk space usage.
- du : Shows disk usage of files and directories.
- du -h [directory] : Shows disk usage in human-readable format.
System Information
uname -a : Displays all system information.top : Displays running processes and system resource usage.
ps : Displays current processes.
ps aux : Shows detailed information about all running processes.
Networking
Checking Network Connectivity
ping [host] : Checks connectivity to a host.ifconfig or ip a : Displays network interfaces and configurations.
netstat : Displays network connections, routing tables, and more.
ssh [user]@[host] : Connects to a remote host via SSH.
These commands are just the basics, but they cover many of the common tasks you'll need to perform in a Linux environment.