Linux Cheat Sheet with Examples
πFile and Directory Operations:
ls: List files and directories in the current location. ππ
Example:
ls
cd: Change directory to a specified location. πͺπ
Example:
cd /path/to/directory
pwd: Print the current working directory. πΊοΈπ
Example:
pwd
mkdir: Create a new directory. ππ
Example:
mkdir new_directory
rm: Remove files and directories. ποΈπ
Example:
rm file.txt
,rm -r directory
cp: Copy files and directories. ππ
Example:
cp file.txt destination_folder
mv: Move or rename files and directories. πβ‘οΈπ
Example:
mv file.txt new_location
,mv old_name.txt new_name.txt
πFile Content and Editing:
cat: Display the contents of a file. ππ
Example:
cat file.txt
less: View a file interactively. ππ
Example:
less file.txt
head: Display the first few lines of a file. ππ
Example:
head file.txt
tail: Display the last few lines of a file. ππ
Example:
tail file.txt
touch: Create an empty file or update the timestamp of an existing file. πβ¨
Example:
touch new_file.txt
nano: Basic text editor πβ¨
Example:
nano new_file.txt
vim: Advanced text editorπβ¨
Example:
vim new_file.txt
πFile Permissions:
chmod: Change the permissions of a file or directory. ππ§
Example:
chmod 755
file.sh
chown: Change the owner of a file or directory. π€π§
Example:
chown user_name file.txt
chgrp: Change group ownership.π€π§
Example:
chgrp [option] groupfile.txt
πProcess Management:
ps: Display running processes. ππ
Example:
ps aux
ππtop: Monitor system processes and resource usage. ππ
Example:
top
ππkill: Terminate a process. βπ
Example:
kill PID
βπ (Replace PID with the Process ID of the process you want to terminate.)killall: Terminate processes by name. βππ₯
Example:
killall process_name
βππ₯ (Replace process_name with the name of the process you want to terminate.)
πΎDisk and Memory Usage:
df - Show disk space usage. πΎ
Example:
df -h
free - Display system memory usage. π§
Example:
free -h
du - Show file and directory disk usage. π§ Example:
du filename
πNetwork and Connectivity:
ping - Check network connectivity to a specific hostπ
Example:
ping
google.com
ifconfig or ip - Display network interface informationπ
Example:
ifconfig
orip address
ssh - Connect to a remote server using Secure Shellπ
Example:
ssh username@remote_server
scp - Securely copy files between local and remote systemsπ₯π€
Example:
scp file.txt username@remote_server:/path/to/destination
wget or curl - Download files from the internetππΎ
Example:
wget
http://example.com/file.zip
orcurl -O
http://example.com/file.zip
πUser and Permission Management:
whoami: Print the current username. π
Example:
whoami
Output:
john_doe
π passwd: Change the password for the current user. π
Example:
passwd
Output:
Changing password for user john_doe.
π€ useradd: Add a new user. π€β
Example:
useradd new_user
Output: A new user "new_user" is added.
π€ usermod: Modify user settings. π€π§
Example:
usermod -aG developers john_doe
Output: User "john_doe" is added to the "developers" group.
π₯ groupadd: Create a new group. π₯β
Example:
groupadd new_group
Output: A new group "new_group" is created.
β userdel: Delete a user. π€ποΈ
Example:
userdel old_user
Output: User "old_user" is deleted.
π»Package Management:
apt
orapt-get
: Package manager for Debian-based systems.yum
: Package manager for Red Hat-based systems.dnf
: Package manager for newer Fedora systems.
πConclusion:
In conclusion, this comprehensive Linux commands cheat sheet equips you with essential tools for managing processes and user permissions. π§π With examples, you can easily grasp the power of commands. Empower yourself to navigate and control your Linux system with confidence, ensuring efficient resource management and secure user access. Remember to use these commands with caution, especially those that can modify or delete files and directories. Always double-check before executing potentially dangerous commands. Happy Linux command-line exploring! π§π»