| BASICS |
--- |
--- |
--- |
| man |
Display the manual page for a specific command |
tldr (*) |
man ls |
| history |
Print a history list of all commands |
|
history |
| clear |
Clear the terminal |
|
clear |
| echo |
Print anything to the terminal output |
|
echo "Hello world!" |
| export |
Set environment variable |
|
export var1="Hello world!" |
| alias |
Set another name for a command that you’ve defined |
|
alias lsl="ls -l" |
|
|
|
|
| SYS INFO |
--- |
--- |
--- |
| date |
Display the current system date and time |
|
date |
| hostnamectl |
Get system information including, operating system, kernel, and release version |
uname, lsb_release, hostname |
hostnamectl && hostname && uname -a |
| free |
Display free and used memory in the system |
|
free -m |
|
|
|
|
| USER MGT |
--- |
--- |
--- |
| sudo |
Escalate privileges (equivalent to logging in as root) |
|
sudo command1 && sudo -i |
| w |
Display all currently logged in users |
|
w |
| whoami |
Display current user’s username |
|
whoami |
| passwd |
Set the password for your own account, or for other accounts if you have the permissions |
|
passwd && passwd -f username1 |
| id |
Display UID and GID of the current user |
|
id |
| last |
Display information of the last login user |
|
last |
| useradd |
Add a new user account |
|
useradd user1 |
| userdel |
Delete a user account |
|
userdel -r user1 |
| usermod |
Change the user account information including, group, home directory, shell, expiration date |
|
usermod [option] user1 && usermod -aG group1 user1 |
| groupadd |
Create a new group |
|
groupadd group1 |
| groupdel |
Remove a group |
|
groupdel group1 |
| groups |
Print the names of the primary and any supplementary groups for each given username, or the current process if no names are given |
|
groups username1 |
|
|
|
|
| FILE MGT |
--- |
--- |
--- |
| ls |
List all files and directories in the current working directory |
|
ls -al |
| pwd |
Print working directory |
|
pwd |
| cd |
Change the current directory |
|
cd && cd .. |
| mkdir |
Create a directory |
|
mkdir dir1 |
| touch |
Creates an empty file or updates the timestamp of an existing file |
|
touch file1 |
| cp |
Copy files |
|
cp oldfile newfile |
| mv |
Move/Rename a file |
|
mv oldfile newfile |
| rm |
Delete a file / directory |
|
rm file1 && rm -rfi dir1 |
| ln |
Create a link to another file |
|
ln -s file1 link1 && ln -l |
| chmod |
Assign (read, write, and execute) permission to files and directories |
|
chmod 777 file1 && chmod -R 777 dir1 && chmod 766 file1 && chmod -x file1 |
| chown |
Change the owner and group ownership of a file or directory |
|
chown user1 file1 && chown user1:group1 file1 && chown -R user1:group1 dir1 |
| rsync |
Transfer and synchronize files between local and remote devices using a delta-transfer algorithm (using ssh) |
|
rsync -a /opt/filename.zip /tmp/ |
| nc |
Transfer data between machines using netcat |
|
ip a && nc -lv 1337 > dest.bin && nc -w 1 192.168.0.91 1337 < src.bin |
| tar |
List/Compress/Uncompress files in/from the Tar archive |
|
tar -tvf file1.tar && tar -cvf file1.tar file2 && tar -xvf file1.tar && tar -xvf file1.tar file2.txt && tar -rvf file1.tar file2.txt |
| zip |
Compress files to a zip |
|
zip file1.zip file2.txt file3.txt file4.txt && zip -u file1.zip file2.txt && zip -d file1.zip file2.txt |
| unzip |
List/Uncompress files in/from a zip archive file |
|
unzip file1.zip && unzip file1.zip -d /dir1 |
| extra: ~ |
Home folder of current user |
|
cd ~ |
| extra: .bashrc |
File with commands to execute each time a new interactive, non-login shell is started |
|
echo 'alias ll="ls -lah"' >> .bashrc |
| extra: .bash_profile |
File with commands to execute when you start a login shell |
|
echo "neofetch" >> .bash_profile && echo ". ~/.bashrc" >> .bash_profile |
|
|
|
|
| FILE VIEWING |
--- |
--- |
--- |
| cat |
Display the content of the file |
|
cat file1 |
| head / tail |
Display the first/last 10 lines of a file |
|
head file1 && tail file2 |
| less, more |
Break down the output and scroll through it using enter or space keys |
|
cat file1 | less -sN |
| diff, cmp, comm |
Compare files: find text/binary/sorted differences, |
|
diff file1 file2 && cmp file1 file2 && comm file1 file2 |
| sort |
Sort lines in a text file or standard input |
|
cat file1 | sort -n |
| grep |
Search for specific patterns or strings in string; "global regular expression print" |
|
cat file1 | grep "Hello" |
| awk |
Powerful search through text files by columns |
|
awk '/manager/ {print}' employee.txt |
| sed |
Powerful stream editor |
gsed |
sed 's/unix/linux/' geekfile.txt |
| cut |
Cut sections from each line of a file, and write the result to the standard output |
|
cut -b 1-3,5-7 state.txt |
| nano, msedit |
Start this text editor using a command line interface |
vim, gedit |
nano file1 && sudo snap install msedit && msedit file1 |
|
|
|
|
| DISK MGT |
--- |
--- |
--- |
| fdisk |
List all disk partitions / Create partition |
|
fdisk -l && fdisk /dev/sda |
| mkfs |
Format a partition |
|
mkfs.ext4 /dev/sda1 |
| fsck |
Check and repair a filesystem for any error |
|
fsck.ext4 /dev/sda1 |
| mount |
Mount any partition to any directory |
|
mount /dev/sda1 /mnt |
| df |
Display free space of mounted file system |
|
df -h |
| du |
Display the size of your current directory |
|
du -hs |
| lsblk |
Display information about block devices |
|
lsblk |
| lsusb |
Display all USB devices |
|
lsusb -tv |
| hdparam |
Perform a read speed test on disk |
|
hdparm -tT /dev/sda |
| badblocks |
Test for unreadable blocks on disk |
|
badblocks -s /dev/sda |
|
|
|
|
| PROCESS MGT |
--- |
--- |
--- |
| which |
Locate the executable file associated with a given command including binaries, scripts, and aliases |
whereis, whatis |
which ls |
| pidof |
Get the PID of any process |
|
pidof processname1 |
| ps |
Display all active processes |
|
ps && ps -ef | grep processname1 && ps -p pid1 |
| pstree |
Display processes in the tree-like diagram |
|
pstree |
| bg |
Display stopped or background jobs |
|
bg |
| top |
Manage and display all processes in realtime |
htop (*) |
top |
| kill |
Kill a specific process using process ID |
|
kill pid1 |
| killall |
Kill all processes by name |
|
killall processname1 |
| shutdown |
Shut down the system |
|
shutdown -h now |
| reboot |
Restart the system |
|
reboot |
| systemctl |
Manage system services and units with commands to start, stop, restart, check status via systemd and service manager |
(prefer over "service") |
systemctl status serviceName1 |
| journalctl |
Allows to filter logs by boot sessions, time ranges, systemd units, process IDs, user IDs, group IDs, and more |
|
journalctl -r |
| service |
Manage system services (long-running processes that are started at boot time and run in background) |
|
serice ssh status && service ssh stop && service ssh start |
| lsof |
List all files opened by running processes |
|
lsof |
| extra: $PATH |
Environmental variable that tells the shell which directories to search for executable files |
|
echo $PATH |
|
|
|
|
| NETWORK MGT |
--- |
--- |
--- |
| ip |
Display the IP and Mac Address of the system |
ifconfig (*) |
ip a && ifconfig && ip addr show |
| netstat |
Display all listening port |
|
netstat -pnltu |
| ping |
Check connectivity between two hosts |
|
ping ip_host1 |
| traceroute |
Trace the route of network packet |
|
traceroute host1 |
| ssh |
Establish a secure shell connection to a remote server |
|
ssh user1@host1 |
| wget |
Download a file |
|
wget linkToFile1 |
|
|
|
|
| PACKAGE MGT |
--- |
--- |
--- |
| apt |
List/Install/Remove the package on Debian based distributions |
apt-get, dpkg |
apt-get install packagename1 && apt-get remove packagename1 && apt-get update && dpkg -l | grep -i installed && dpkg -i packagename1.deb && apt-get upgrade packagename1 && apt-get autoremove |
| yum |
List/Install/Remove a package on RPM-based distributions |
rpm, dnf |
yum install packagename1 && yum remove packagename1 && yum update && yum list --installed && yum list --available |
| nix (*) |
Declative and tranactional package manager for all distros |
|
nix profile install nixpkgs#tmux |
|
|
|
|