Introduction to Linux commands
Introduction to Linux Commands
This guide introduces some of the most essential Linux commands. Understanding the Linux command line (also called the shell or terminal) is useful when setting up configurations, installing software manually, or simply gaining deeper insight into how your website operates.
Note:
This article assumes you already know how to access your account using SSH (Secure Shell). If not, please review the related article on how to connect via SSH first.
The Command Line Environment
Section titled “The Command Line Environment”When you log in to your account using SSH, you’ll see the Linux command prompt:
username@example.com [~]#The tilde symbol ~ indicates you’re in your home directory, usually /home/username. From here, you can run commands to navigate, view, and manage files.
Listing Files and Directories
Section titled “Listing Files and Directories”To see what’s inside your current directory, type:
lsThis command lists all files and directories. For a detailed view (including permissions, size, and modification date), use:
ls -lNavigating the Directory Tree
Section titled “Navigating the Directory Tree”To display your current directory:
pwdThis shows your present working directory.
To move into another directory, for example, public_html:
cd public_htmlTo return to your home directory:
cd ~- Use
cd ..to go up one level (to the parent directory). - Use
.to refer to the current directory.
Finding Files
Section titled “Finding Files”To search for files in your current directory and its subdirectories, use the find command.
Example — find all .html files:
find . -name '*.html'Tip:
For help with any Linux command, use the man command to read its manual page:
man findUse Page Up/Page Down to scroll and q to quit.
Finding the Path to a Program
Section titled “Finding the Path to a Program”To locate where a program is installed, use whereis.
Example:
whereis -b grepThis shows the executable path. To include help files as well, omit the -b option:
whereis grepCreating and Removing Directories
Section titled “Creating and Removing Directories”Create a directory:
mkdir backupRemove an empty directory:
rmdir backupNote:
rmdir only removes empty directories. Delete files inside before using it.
Copying, Moving, and Deleting Files
Section titled “Copying, Moving, and Deleting Files”Copy a file:
cp index.html backupIf backup is a directory, the file will be copied into it. Otherwise, a new file named backup is created in the same directory.
Move or rename a file:
mv index.html backupIf backup is a directory, the file moves there; otherwise, it renames the file to backup.
Delete a file:
rm old.htmlChecking Disk Usage and Free Space
Section titled “Checking Disk Usage and Free Space”To see how much space a directory uses:
du -hThis displays human-readable disk usage statistics.
To check free disk space:
df -hNote:
df is most useful on VPS or dedicated servers where you manage the entire disk. On shared hosting, disk space is managed by the provider.
More Information
Section titled “More Information”This guide covers only basic Linux commands. There are many more powerful tools and tutorials available.
For deeper learning, visit linuxcommand.org, which offers detailed guides and a free downloadable book on mastering the command line.