[go: up one dir, main page]

0% found this document useful (0 votes)
15 views5 pages

Practical+Linux+Cmd+Line+2 0+-+Cheat+Sheet

Uploaded by

m.propertycanvas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Practical+Linux+Cmd+Line+2 0+-+Cheat+Sheet

Uploaded by

m.propertycanvas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Shortcuts on Mac:

Command+C = fn+control+C

Terminal Commands - Quick cheat-sheet for the


Practical Linux Command Line 2.0 course
Here is a list of commands to keep on the side when you work with the Linux terminal.

Navigate & search


ls Print the content of a directory

ls -a Same as ls, also shows hidden files

pwd Print the directory where you are now

cd <dir_name> Navigate to directory

cd (no parameter) Navigate to home directory (/user/user_name, or ~)

find <path> List all the files for the path, recursively

find <path> -name “<pattern>” List all the files which correspond to the given pattern

grep <regular_expr> <file_name> Print all lines matching the regular expression

cat <file_name> Print the content of a file

less <file_name> Visualize the content of a file with scrolling capabilities

wc <file_name> Print number of lines, words, and bytes for a file

Manipulate files
touch <file_name> Create a new file

mkdir <dir_name> Create a new directory

mkdir -p <dir1>/<dir2>/<dir3> Create multiple nested directories

mv <file_path> <new_file_path> Move a file/directory and/or rename it

cp <file_path> <new_file_path> Copy a file to a new file

rm <file_name> Remove a file

rm -r <dir_name> Remove a directory and everything inside, recursively


chmod +x <file_name> Make a file executable

./<file_name> Execute a file (if the file is marked as “executable”)

echo “text” Print given text in the terminal

echo “text > <file_name> Truncate file and add given text to it

echo “text” >> <file_name> Add given text at the end of the file

nano <file_name> Open the file in nano editor, also create the file if
doesn’t exist

vim <file_name> Open the file in Vim editor, also create the file if
doesn’t exist

vimtutor Start the Vim tutorial

Permissions
sudo <cmd> Run command with admin privileges

ls -l Same as ls, also shows permissions for files

chown <user_name> <file_name> Change a file’s owner

chmod <mode> <file_name> Change a file’s permissions

Monitor processes & resources


ps List processes running inside the current terminal

ps aux List all processes running on the OS

kill -9 <pid> Kill process with given pid (process ID)

df -h Print currently used and available space on disk

htop Monitor CPU and RAM usage, also list processes

Network
wget <url> Download a file from a URL

hostname Print name of computer/host


Hostname -I Print IP address

ifconfig Print info about available network interfaces

ping <hostname or IP> Check if the hostname/IP is reachable on the network

ssh <user>@<ip> Remotely connect to a machine with SSH

exit Close terminal or SSH connection

Scheduling and automation


crontab -l Display current crontab

crontab -e Edit crontab

crontab -r Remove your crontab

sudo systemctl list-unit-files List all services and see if they are enabled

sudo systemctl enable <service> Enable the service, so it will be run on next boot

sudo systemctl disable <service> Disable the service

sudo systemctl start <service> Start immediately the command in the service

sudo systemctl stop <service> Stop a currently running service

Terminal utils
clear Empty the terminal to have a clear view

history Display previously executed commands

history -c Clear the history

man <command> Display manual for a given command

<command> --help Print a quick help to get started with the command

tree Show files and folders with a tree view

sudo shutdown now Shutdown the OS/computer

sudo reboot Reboot the OS/computer

<cmd1> | <cmd2> Chain 2 commands: pass the output of cmd1 to the


input of cmd2
Install software (Debian, Ubuntu)
sudo apt update Update sources to latest

sudo apt install <package_name> Install a package

sudo apt remove <package_name> Remove a package

sudo apt upgrade Upgrade already installed packages to latest version

sudo apt autoremove Automatically remove unneeded packages

sudo snap install <pkg> Install a package with snap (Ubuntu only)

snap list Print all installed packages with snap (Ubuntu only)

sudo snap refresh Update sources + upgrade packages installed with


snap (Ubuntu only)

sudo snap remove <pkg> Remove a package installed with snap (Ubuntu only)

Install software (CentOS - Fedora)


sudo yum check-update Update sources to latest

sudo yum install <package_name> Install a package

sudo yum remove <package_name> Remove a package

sudo yum update Upgrade already installed packages to latest version

sudo yum autoremove Automatically remove unneeded packages

Install software (MacOS)


brew update Update sources to latest

brew install <package_name> Install a package

brew remove <package_name> Remove a package

brew upgrade Upgrade already installed packages to latest version

brew autoremove Automatically remove unneeded packages


Terminal Shortcuts (some shortcuts are specific to a Linux distribution)
TAB Autocompletion

Ctrl + a Go to beginning of the line

Ctrl + e Go to end of the line

Ctrl + u Remove beginning of the line (before cursor)

Ctrl + k Remove end of the line (after cursor)

Ctrl + r Reverse search in the command line history

Ctrl + Alt + t (Ubuntu) Open terminal

Ctrl + Shift + q (Ubuntu) Close terminal

Ctrl + Shift + t Open new tab in current terminal window

Ctrl + Shift + c Copy from the terminal

Ctrl + Shift + v Paste inside the terminal

Ctrl + c Stop a currently running program in the terminal

Ctrl + s (Nano) Save the file

Ctrl + x (Nano) Quit the file and come back to the terminal

Ctrl + Shift + o (Terminator) Split horizontally

Ctrl + Shift + e (Terminator) Split vertically

Ctrl + Shift + x (Terminator) Put selected terminal in full screen

Alt + L (Terminator) Choose a layout from saved ones

You might also like