*** This repository contains some of the important often used Linux commands anyone interested in learning Linux should know. ***
ssh \<username>@\<serverIP>
List all the files in the directory
ls -l
gives list files with permissions
ls -al
gives hidden files as well
Be able to print the current directory
Changing directory
cd \<path>
navigate to the respective directory
cd ..
jump back directory
cd
naviagate to home
touch \<filename>
create a new file
touch \<filename1> <filename2>
create several files
touch \<filename>{1..10}
create 10 files
echo \<message>
print the message
echo \<message> \> \<filename>
Add message to the file
nano \<filename>
edit a file
To save use ctrl + X and Y and Enter to save
vim \<filename>
edit a file
Hit I to start editing When done use hit ESC and :wq
cat \<filename>
Read content of a file
shred \<filename>
Don't let anyone to read the file.
mkdir \<directory name>
create a new directory
cp \<file name> \<path where to copy>
Copy file to a given pathmv \<file name> \<path where to move>
Move file to the given path
rm \<file name>
Remove a file
rmdir \<directory name>
For an empty directory removalrm -r \<directory name>
To remove a directory with files in it
ln -s \<file name> <link>
Can create a link to a file with -s switch for soft
Clear the terminal
Tells who you are😄 (returns the username)
useradd \<name>
Create a new user
sudo \<command which needs permission>
Uses when asked for permission Need to enter the password for user
Can reverse the command useradd
su <username>
Can switch user
Exit temparary user. (can use in several occasions)
passwd <username>
Can change the password of the user
sudo apt update
Needs to update before installsudo apt install <package>
Install packages
Needs to install finger package first
finger \<username>
Can be used to inspect another user
man \<command>
Can get help with things that don't know
whatis \<command>
Faster than man command to get help
whereis \<command>
To findout where the command is
wget \<link>
Help to get stuff from the internet (download)
curl \<link>
Help to get stuff from the internet
zip \<zip file> <file name>
Make a zip file
unzip <zip file name>
Unzip the file
less <file name>
Can read one page at a time. (substitution for cat command)
head <file name>
Output only the begining of the file
tail <file name>
Output only the ending of the file
cmp <file1> <file2>
Compare two files and check whether any differences exist.
diff <file1> <file2>
List the differences of the two files
cat <file name> | sort
The file is sorted in alphabatical order
sudo find <the directory> -name "<search key>"
Find the search keysudo find <the directory> -type f -name "."
Find all hidden filesfind <the directory> -type f -empty
Finds all empty directoriesfind <the directory> -perm /a=x
Finds all executable files
Change the permissions of the file
chmod <permission> <file name>
To change permission of the file.
Important
Here are the permission types
0 no permissions
1 can execute
2 can write
3 can write, execute
4 can read
5 can read, execute
6 can read, write
7 can read, write and execute
chown <user> <file name>
Changing owner of the file
Gives IP address of the machine
Returns the ip address
Note
Can also use the command grep
to only return ip address of a specific interface.
Ex: >ip address | grep eth0
Return only the ip address of ethernet 0.
Important
If only the ip address you want to return, use awk '{print $2}'
Ex: >ip address | grep eth0 | grep inet | awk '{print $2}'
Return information about the DNS server (including IP address)
Tip
cat /etc/resolv.conf
Return information about the DNS server
ping <name of the website/ipaddress>
Tip
Use ctrl+C to stop.
Note
To use only a specific number of response use ping -c <number> <name of the website/ipaddress>
To use only a specific size of packets use ping -s <number> <name of the website/ipaddress>
traceroute <name of the website>
To see the path through the internet to get to a website
To check what ports in use.
Tip
Modern version netstat -tulpn
Another command ss
or ss -tulpn
sudo iptables -I INPUT -p tcp -, tcp --dport <port> -j ACCEPT
To allow a specific port through the firewall
Tip
Easy command sudo ufw allow <port>
Important
To execute above command below command might need to execute first
sudo ufw enable
To check status use sudo ufw status
uname -a
To find information about the system.
Tip
Needs prettier version than above😀
Install neofetch sudo apt install neofetchf
Runneofetch
A quick little calendar :)
To check how much memeory available in system and swap space.
To check how much space available (To be more specific use df -H)
To list all processes
ps -aux
More details
List processes running in real time
Tip
htop
Much more prettier version of top.
kill -KILL <pid>
orkill -9 <pid>
To kill the process with given id.
Tip
Use pkill -f <name of the process>
In case the pid is not known.
systemctl stop <service name>
Stop a specific service.
systemctl start <service name>
Start a specific service.
systemctl restart <service name>
Restart a specific service
Tip
systemctl status <service name>
To check the status
Use sudo
if necessary when using systemctl
command
Return a list of commands used.
sudo reboot
To reboot the system
sudo shutdown
To shutdown the system after 1 minute
sudo shutdown -h now
To shutdown the system now