Purpose |
Commands |
Example/Explanation |
Help and Options |
show service options |
man service_name |
man sudo |
Help command or service |
service_name --help |
man --help |
recuresive |
-r |
rm -r example.txt |
force to do something. Ignore any prompt when deleting a write-protected file. |
-f |
rm -f example.txt |
Clear screen |
clear |
|
show command history |
history history | grep ufw history | sort -rn |
|
System, Process and Services |
shutdown the system |
shutdown -r now |
|
reboot /restart |
reboot init 6 |
|
show process for users or all |
ps -option |
ps -u, ps -aux |
To find the IP address |
ip a |
|
see Linux servers resource usage |
top |
top |
Kill process |
kill pid |
kill 16750, kill -9 16750 (by force) |
Show machine date and time |
date |
date |
Set time zone |
sudo timedatectl set-timezone zone_name |
sudo timedatectl set-timezone Asia/Dhaka |
access remote server using SSH |
ssh -p 22 user@IP_ADDRESS |
ssh -p 22 user@10.10.18.215 |
version check |
hostnamectl |
|
show all services |
service --status-all |
|
service status/start/stop |
systemctl status/start/stop service_name |
systemctl status ssh |
show disk space / disk file system |
df -HT |
df -HT |
show FIle and Folder wise space |
du -sh *|less |
du -sh *|less |
exporting environment variables in runtime |
export variable_name=value |
export MY_PROJECT_PATH=/opt/project/techecosys |
Show all environment variable |
env |
show all existing variables |
show individual variable |
echo $VARIABLE_NAME |
echo $MY_PROJECT_PATH |
set another name for a command |
alias lsl="command" |
alias lsl="ls -l", alias dpa="docker ps -a" |
Search location of any command |
whereis command_name |
whereis sudo, whereis ls |
See what a command actually is |
whatis command_name |
whatis sudo, whatis ls |
Unzip zip file |
unzip filename.zip -d /path/ |
unzip website.zip -d /var/www/html/ |
File and Directory - Wildcard |
show present directory |
pwd |
|
|
|
|
create directory |
mkdir folder_name |
mkdir dir1 dir2 |
change directory |
cd dirtory_path |
cd dir1 |
create file |
touch options file_name |
touch -m example1.txt example2.txt index.html |
Create A File With content |
cat filename |
cat foo.txt -> Type content -> press ctrl + d |
To view a file content |
cat filename |
cat foo.txt |
To Append/update Text File content |
cat >>filename |
cat >>foo.txt |
show all files and folders |
ls -l |
ls -l |
show all .txt files using Wildcard |
ls -l *.txt |
* is wildcard which match pattern |
view BIG file content more/less |
cat file_name | more or less |
cat /etc/passwd | more |
copy file/Files in Linux |
cp source destination |
cp dir1/foo.txt dir2 |
move file one directory to another |
mv source destination |
mv dir1/foo.txt dir2 |
remove file |
rm options file_name |
rm -rf test.txt |
remove all files which are .txt |
rm *.txt |
|
Copy or duplicate dir |
cp [options] source destination |
cp [options] source destination |
remove folder |
rm -option folder_name |
rm -d folder_name - empty rm -r folder_name - nonempty |
big file content view |
head file_name or tail file_name |
head foo.txt |
To search for matching patterns in a file |
grep [OPTION...] PATTERNS [FILE...] |
grep -i "UNix" example.txt |
Find file/folder name |
find [path] [options] [expression] |
find /test/ -type f -name "*.txt" find /path/to/search -type d -name "docs" |
Users, Grups and Permission |
Show all users |
awk -F':' '{ print $1}' /etc/passwd |
Awk prints every line of data from the specified file |
add user with home directory |
sudo useradd -m username |
sudo useradd -m saidul |
set/modify password |
passwd username |
passwd saidul |
Switch User |
su - username |
su - username |
show user group |
groups username |
|
Add user to a group |
sudo usermod -aG groupname username |
usermod -aG sudo gkerp |
change file permissions |
sudo chmod options file_name |
chmod +x foo.txt |
granting ownership of files or folders |
chown |
chmod saidul:saidul foo.txt |
|
|
|
vim/vi commands |
view file content |
vi filename |
|
insert |
press i |
|
|
:q - quit, :wq - write and quit |
|
Network |
Display network interfaces and IP addresses |
ifconfig |
this command shows all network info |
Trace all the network hops to reach the destination |
traceroute HOST |
traceroute localhost |
Direct download files from the internet |
wget |
|
Firewall command |
ufw allow/status/disallow |
ufw allow 80 |
Base firewall for all other firewall utilities to interface with |
iptables |
|
|
|
|
Package |
|
|
Update the local package index |
sudo apt update |
|
Install a new package. |
sudo apt install [package] |
sudo apt install traceroute |
Uninstall a package. |
sudo apt remove [package] |
sudo apt remove traceroute |
Upgrade all packages |
sudo apt upgrade |
|
Remove all packages that were installed automatically as dependencies and are no longer required. |
sudo apt autoremove |
|
|
sudo apt autoclean |
|
Purge is identical to remove except that packages are removed and purged (any configuration files are deleted too). |
sudo apt-get remove <package-name> |
|
|
|
|