Linux: Basic Shell Commands

By Xah Lee. Date: . Last updated: .

This is a list of most frequently used linux commands. These are essential commands. Most of them are used everyday by every linux user.

this is generate by artificial intelligence.

ls
Lists directory contents. Common options: ls -l (long format)

Example: ls -a (show hidden files)

Example: ls -lh (human-readable sizes)

Example: ls -la

cd
Changes the current directory.

Example: cd /path/to/directory

Example: cd .. (go up one directory)

Example: cd ~ (home directory)

pwd
Prints the current working directory.

Example: pwd

cp
Copies files or directories. Common options: cp -r (recursive for directories)

Example: cp -v (verbose)

Example: cp file1.txt file2.txt

Example: cp -r dir1 dir2

mv
Moves or renames files or directories. Common options: mv -v (verbose)

Example: mv -i (prompt before overwrite)

Example: mv file1.txt /new/path/

Example: mv oldname.txt newname.txt

rm
Removes files or directories. Common options: rm -r (recursive for directories)

Example: rm -f (force)

Example: rm -i (interactive)

Example: rm file.txt

Example: rm -r directory

mkdir
Creates a new directory. Common options: mkdir -p (create parent directories if needed).

Example: mkdir new_folder

Example: mkdir -p path/to/new_folder

touch
Creates an empty file or updates a file’s timestamp.

Example: touch newfile.txt

cat
Displays file contents • concatenates files • or creates files. Common options: cat -n (line numbers).

Example: cat file.txt

Example: cat file1.txt file2.txt > combined.txt

grep
Searches text for patterns. Common options: grep -i (case-insensitive)

Example: grep -r (recursive)

Example: grep -v (invert match)

Example: grep "pattern" file.txt

Example: grep -r "error" /var/log

find
Searches for files or directories in a directory hierarchy. Common options: find -name

Example: find -type f (files only)

Example: find -type d (directories)

Example: find / -name "file.txt"

Example: find . -type f -name "*.log"

chmod
Changes file or directory permissions. Common options: chmod -R (recursive).

Example: chmod 755 script.sh

Example: chmod u+x file.sh

chown
Changes file or directory ownership. Common options: chown -R (recursive).

Example: chown user:group file.txt

Example: chown -R user:group /directory

man
Displays the manual page for a command.

Example: man ls

Example: man grep

ps
Lists running processes. Common options: ps aux (all processes)

Example: ps -ef (detailed)

Example: ps aux | grep python

top
Displays real-time system processes and resource usage.

Example: top (interactive interface)

htop
An enhanced

Example: interactive version of top (if installed)

Example: htop

kill
Terminates processes by PID. Common options: kill -9 (force kill).

Example: kill 1234

Example: kill -9 1234

df
Reports disk space usage. Common options: df -h (human-readable).

Example: df -h

du
Estimates file and directory space usage. Common options: du -sh (summary • human-readable).

Example: du -sh /path/to/directory

tar
Archives files or directories. Common options: tar -cvf (create)

Example: tar -xvf (extract)

Example: tar -z (gzip)

Example: tar -cvf archive.tar /directory

Example: tar -xzvf archive.tar.gz

wget
Downloads files from the web. Common options: wget -O (specify output file)

Example: wget -c (resume download)

Example: wget http://example.com/file.zip

curl
Transfers data to or from a server. Common options: curl -O (save file)

Example: curl -L (follow redirects)

Example: curl -O http://example.com/file.txt

sudo
Executes a command with superuser privileges.

Example: sudo apt update

Example: sudo systemctl restart service

apt yum dnf)
Package management. Common options: apt update • apt install • apt upgrade.

Example: sudo apt install vim

systemctl
Manages system services. Common options: start, stop, enable, disable, status.

Example: systemctl start nginx

Example: systemctl status sshd

nano, vim, or vi
Text editors for editing files.

Example: nano file.txt

Example: vim config.conf

history
Displays command history.

Example: history

Example: history | grep ssh

whoami
Displays the current user.

Example: whoami

ping
Tests network connectivity. Common options: ping -c (count).

Example: ping -c 4 google.com