Linux Commands
Here are essential Linux commands and how to use them:
- pwd command
Use the pwd command to find out which directory (folder) you are currently in. The command returns the absolute path of your current location, which typically begins with a slash (/), for example /home/username.
- cd command
Use cd to navigate the Linux filesystem. Depending on your current directory, you can enter either a relative directory name or the full path.
For example, if you are in /home/username/Documents and want to go to the Photos subdirectory, run cd Photos. To jump directly to a different directory such as /home/username/Movies, use cd /home/username/Movies.
There are useful shortcuts: cd .. moves up one level, cd alone returns you to your home directory, and cd – switches back to the previous directory. Note that the shell is case-sensitive, so type directory names exactly.
- ls command
ls lists the contents of a directory. By default it shows the current directory. To view another directory, pass its path, for example: ls /home/username/Documents.
- cat command
cat is commonly used to display a file’s contents to standard output. Use cat filename.txt to print the contents of a text file to the terminal.
- cp command
Use cp to copy files from one location to another. For example, cp sample.jpg /home/username/Pictures copies sample.jpg into the Pictures directory.
- mv command
mv moves files or renames them. Its usage is similar to cp. For example, mv file.txt /home/username/Documents moves a file to Documents. To rename a file, use mv oldname.ext newname.ext.
- mkdir command
mkdir creates a new directory. For example, mkdir Music creates a directory named Music.
- rmdir command
Use rmdir to remove a directory, but note that rmdir only deletes empty directories.
- rm command
rm deletes files and, with options, directories and their contents. To remove a directory and everything inside it, use rm -r (recursive).
- touch command
touch creates new empty files from the command line. For example, to create an HTML file in Documents, run touch /home/username/Documents/Web.html.
- locate command
locate quickly finds files by name, similar to a search tool. Use the -i option for case-insensitive searches. Use wildcards like * for multi-word patterns, e.g. locate -i school*notes will find files that include “school” and “notes” regardless of case.
- find command
Like locate, find searches for files but is used to search within a specific directory tree. For example, find /home/ -name notes.txt searches for a file named notes.txt under /home and its subdirectories.
- grep command
grep searches for text patterns inside files. For example, grep blue notes.txt searches for the word “blue” inside notes.txt and prints matching lines.
- sudo command
sudo stands for “SuperUser Do” and grants elevated (administrator/root) privileges for commands that require them. Use it carefully—incorrect use can cause system errors.
- df command
df reports disk space usage for filesystems in percentages and kilobytes. To display sizes in megabytes, use df -m.
- du command
du (Disk Usage) shows how much space a file or directory consumes. By default it reports in disk blocks; add -h for human-readable sizes (bytes, KB, MB).
- head command
head displays the first lines of a text file. By default it shows the first ten lines. To show a different number, use head -n 5 filename.ext to see the first five lines.
- tail command
tail is similar to head but shows the last lines of a file; by default it displays the last ten lines.
- diff command
diff compares two files line by line and lists differences. Programmers often use it to identify changes without rewriting whole files. Basic usage: diff file1.ext file2.ext.
- tar command
tar archives multiple files into a single tarball. A tarball is an archive similar to zip; compression is optional. tar can create archives, append files, list contents, and extract files—review practical examples to learn specific options.
- chmod command
chmod changes read, write, and execute permissions for files and directories. Its options and numeric modes can be complex; consult a dedicated chmod guide to learn proper usage.
- chown command
Every file has an owner. Use chown to change a file’s owner. For example, chown newuser file.ext assigns ownership of file.ext to newuser.
- jobs command
jobs lists shell-started jobs and their statuses. A job is any process initiated by the shell.
- kill command
If a program is unresponsive, use kill to send it a signal requesting termination. Two common signals are:
- SIGTERM (15) — politely asks a process to stop, allowing it to save state. This is the default signal if none is specified.
- SIGKILL (9) — forcefully and immediately terminates a process; unsaved data may be lost.
To use kill you need the process ID (PID). If you don’t know it, run ps ux to list running processes. Then run kill [signal option] PID, for example kill -9 1234.
- ping command
ping checks connectivity to a server and measures response time. For example, ping google.com tests whether you can reach Google and reports latency.
- wget command
wget downloads files from the Internet. Use wget followed by a file URL to download it from the command line.
- uname command
uname (Unix Name) displays system information such as the machine name, operating system, and kernel version, which can help identify your environment.
- top command
top is similar to Task Manager on Windows: it shows running processes and their CPU usage, making it useful for monitoring system resources and identifying resource-heavy programs.
- history command
The history command shows a list of previously executed commands, which is helpful when you want to repeat or review past actions.
- man command
If you forget a command’s syntax or options, use man to read its manual page from the shell. For example, man tail displays the usage instructions for the tail command.
Author: Samed Gül