Catalog / Linux Command Line Cheat Sheet

Linux Command Line Cheat Sheet

A quick reference guide to essential Linux command line shortcuts and commands for efficient navigation and system management.

Basic Navigation

Essential Navigation Shortcuts

cd

Change directory to home directory.

cd <directory>

Change directory to <directory>.

cd ..

Move one directory up.

cd -

Go to the previous directory.

pwd

Print working directory (current directory path).

ls

List files and directories in the current directory.

ls -l

List files with detailed information (permissions, size, date).

ls -a

List all files, including hidden files (files starting with .).

ls -t

Sort files by modification time (newest first).

File and Directory Management

mkdir <directory>

Create a new directory named <directory>.

rmdir <directory>

Remove an empty directory.

rm -r <directory>

Recursively remove a directory and its contents (use with caution!).

touch <file>

Create an empty file or update the timestamp of an existing file.

cp <source> <destination>

Copy a file or directory from <source> to <destination>.

mv <source> <destination>

Move or rename a file or directory.

rm <file>

Remove a file.

ln -s <source> <link>

Create a symbolic link named <link> pointing to <source>.

find . -name "<filename>"

Finds file with the filename from the current directory.

Shell Shortcuts and Commands

Command Line Editing

Ctrl + A

Move cursor to the beginning of the line.

Ctrl + E

Move cursor to the end of the line.

Ctrl + K

Cut the line from the cursor position to the end.

Ctrl + U

Cut the line from the cursor position to the beginning.

Ctrl + Y

Paste the last cut text (yank).

Ctrl + R

Search command history.

Ctrl + W

Cut the word before the cursor.

Alt + F

Move cursor forward one word.

Alt + B

Move cursor backward one word.

Process Management

Ctrl + C

Terminate the current process.

Ctrl + Z

Suspend the current process (send it to the background).

fg

Bring the last suspended process to the foreground.

bg

Run the last suspended process in the background.

jobs

List all background jobs.

kill %<job_number>

Kill a specific background job.

ps

Display currently running processes.

top

Display dynamic real-time view of running processes.

kill <pid>

Kill a process by its process ID (PID).

System Information and Control

System Information

uname -a

Display kernel information.

uptime

Show how long the system has been running.

df -h

Display disk space usage.

free -m

Display memory usage.

whoami

Display the current username.

date

Display the current date and time.

cal

Display the calendar.

history

Display command history.

echo $<variable>

Display the value of the variable.

System Control

sudo shutdown -h now

Shut down the system immediately (requires sudo).

sudo reboot

Reboot the system (requires sudo).

exit

Close the current terminal.

Ctrl + D

Close the current terminal (alternative to exit).

passwd

Change user password.

clear

Clear the terminal screen.

logout

Logs out the current user.

File Operations and Permissions

File Content Viewing

cat <file>

Display the entire content of a file.

less <file>

View file content page by page. Use arrow keys to navigate, q to quit.

head <file>

Display the first 10 lines of a file.

tail <file>

Display the last 10 lines of a file.

tail -f <file>

Display the last 10 lines and follow the file for new content (useful for log files).

nl <file>

Display file content with line numbers.

File Permissions

chmod <permissions> <file>

Change file permissions. <permissions> can be in octal (e.g., 755) or symbolic (e.g., u+rwx,go+rx).

chown <user>:<group> <file>

Change file ownership. user is the new owner, group is the new group.

umask

Show the current umask value. This determines default file permissions for newly created files and directories.

sudo chmod 777 <file>

Grants read, write, and execute permissions to everyone (use with extreme caution).

sudo chown <user>:<group> <file>

Example to change file owner and group of file.

stat <file>

Displays status and details about the file.