Linux Fundamentals: 50 Essential Commands

Organized by command type with examples and outputs

File System Navigation

pwd - Print Working Directory

Shows the current directory path

$ pwd
/home/username

ls - List Directory Contents

Lists files and directories

$ ls -la
total 64
drwxr-xr-x 5 user user 4096 Dec 15 10:30 .
drwxr-xr-x 3 root root 4096 Dec 14 09:15 ..
-rw-r--r-- 1 user user 220 Dec 14 09:15 .bash_logout

cd - Change Directory

Moves between directories

$ cd /var/log
$ pwd
/var/log

mkdir - Make Directory

Creates new directories

$ mkdir new_folder
$ ls
new_folder

rmdir - Remove Directory

Removes empty directories

$ rmdir empty_folder
# No output on success

File Operations

touch - Create Empty File

Creates new empty files

$ touch newfile.txt
$ ls -l
-rw-r--r-- 1 user user 0 Dec 15 10:35 newfile.txt

cp - Copy Files/Directories

Copies files and directories

$ cp file.txt file_backup.txt
$ ls
file.txt file_backup.txt

mv - Move/Rename Files

Moves or renames files

$ mv oldname.txt newname.txt
$ mv file.txt /tmp/
# No output on success

rm - Remove Files

Deletes files and directories

$ rm unwanted_file.txt
$ rm -r directory_name # Remove directory recursively
# No output on success

cat - Concatenate Files

Displays file content

$ cat file.txt
Hello, this is file content.
Line 2 of the file.

head - Show Beginning of File

Displays first lines of a file

$ head -5 file.txt
Line 1
Line 2
Line 3
Line 4
Line 5

tail - Show End of File

Displays last lines of a file

$ tail -3 file.txt
Line 8
Line 9
Line 10

File Permissions and Ownership

chmod - Change File Permissions

Modifies file permissions

$ chmod 755 script.sh
$ chmod +x executable_file
# No output on success

chown - Change File Owner

Changes file ownership

$ chown user:group file.txt
# No output on success

chgrp - Change File Group

Changes file group ownership

$ chgrp developers file.txt
# No output on success

Searching and Finding

find - Search for Files

Searches for files and directories

$ find /home -name "*.txt"
/home/user/file1.txt
/home/user/documents/note.txt

grep - Search Text Patterns

Searches for patterns in files

$ grep "error" logfile.txt
ERROR: Connection failed
Error: File not found

locate - Find Files Quickly

Uses database to quickly find files

$ locate httpd.conf
/etc/httpd/conf/httpd.conf

which - Locate Command

Shows full path of commands

$ which python
/usr/bin/python

whereis - Locate Binary, Source, and Manual

Locates binary, source, and manual pages

$ whereis python
python: /usr/bin/python /usr/lib/python2.7 /usr/include/python2.7

System Information

uname - System Information

Shows system information

$ uname -a
Linux server1 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

whoami - Current User

Displays current username

$ whoami
username

id - User Identity

Shows user and group information

$ id
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo)

date - System Date and Time

Shows or sets system date/time

$ date
Mon Dec 15 10:45:30 UTC 2023

uptime - System Uptime

Shows how long system has been running

$ uptime
10:50:30 up 15 days, 3:20, 2 users, load average: 0.05, 0.10, 0.15

Process Management

ps - Process Status

Shows current processes

$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169316 13004 ? Ss Dec14 0:02 /sbin/init

top - Process Monitor

Dynamic real-time process viewer

$ top
# Shows dynamic process list (output truncated)

kill - Terminate Processes

Sends signals to processes

$ kill 1234
$ kill -9 1234 # Force kill
# No output on success

pkill - Kill Processes by Name

Kills processes by name

$ pkill firefox
# No output on success

jobs - List Background Jobs

Shows background jobs

$ jobs
[1]- Running sleep 1000 &
[2]+ Running nano file.txt &

Networking

ping - Network Connectivity Test

Tests network connectivity

$ ping google.com
PING google.com (172.217.16.206) 56(84) bytes of data.
64 bytes from muc11s01-in-f14.1e100.net (172.217.16.206): icmp_seq=1 ttl=117 time=15.4 ms

ifconfig - Network Interface Configuration

Configures network interfaces (older)

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255

wget - Web Downloader

Downloads files from the web

$ wget https://example.com/file.zip
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:443... connected.

curl - URL Transfer Tool

Transfers data from or to a server

$ curl -O https://example.com/file.txt
% Total % Received % Xferd Average Speed Time Time Time Current
                            Dload Upload Total Spent Left Speed
100 312k 100 312k 0 0 1034k 0 --:--:-- --:--:-- --:--:-- 1034k

Compression and Archiving

tar - Tape Archive

Archives files

$ tar -czvf archive.tar.gz folder/
folder/
folder/file1.txt
folder/file2.txt

gzip - File Compression

Compresses files

$ gzip largefile.txt
$ ls
largefile.txt.gz

zip - Package and Compress Files

Creates ZIP archives

$ zip archive.zip file1.txt file2.txt
adding: file1.txt (stored 0%)
adding: file2.txt (stored 0%)

Disk Usage

df - Disk Free Space

Shows disk space usage

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 15G 4.5G 77% /

du - Disk Usage

Estimates file space usage

$ du -sh /home/user/
2.1G /home/user/

Help and Documentation

man - Manual Pages

Shows command manual

$ man ls
# Shows the manual page for ls command

--help - Command Help

Shows command usage information

$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Tips for Learning Linux Commands:

← Back to Fundamentals Index ↑ Back to EXPANDED