Linux/Unix commands with examples

Linux/Unix commands with examples 


Hello guys,

Welcome to MikeyToTech
If you want to learn Linux operating system then you should know Linux/Unix commands. If you are beginner or searching for kali Linux commands for Linux or hacking or penetration testing then read this post and practice by yourself.
In this post I have explained Linux/Unix commands with examples. Remember Linux/Unix commands are case sensitive.  


Linux SYSTEM commands 

uname -a :- It displays the all information of your Linux System.

uname :- It displays the name of your operating system.

uname -r :- by this command you can know kernel release information that you are using.

uname -v :- It displays the kernel version.

uname -n :- it displays the node host name. for example if you are using Kali Linux then it will display kali as node host name, if you changed you system hostname manually then it will display changed hostname. Here I have changed my system hostname that’s why uname -n displaying name MikeyToTech.

uname -m :- it displays information what kind of machine you are using.
  X86_64 means your system is a 64bit system.




uptime :- It shows how long this system has been running(active). It also displays the number of users with running sessions.

uptime -p :- It shows only running time of the system.

uptime -s :- It show the date/time since when the system has been running.



hostname :- it shows system host name. (here I have changed hostname, if you are using kali Linux then it will display kali as host name)

hostname -i :- it displays the IP address of the host.


last reboot :- It displays reboot history of system.


date :- It displays the current date and time of you system.

date -u :- It displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time) time zone.



cal :- It prints calendar of current month.

cal -y :- it prints current year calendar.

cal -m month_name :- It prints the calendar for given month_name.

cal  month_name year_name :- It prints the calendar for given month_name and year_name.





w :- It displays who is online, it displays name of online user.

w -h :- I displays name of online user but it don’t display header.

w -i :- It displays IP instead of hostname.



whoami :- It displays who are logged in as.


finger user:- It displays information of user.
 


DIRECTORY TRAVERSE 

cd :- It is used for go to home directory.


cd .. :- It is used for go up one level of the directory.

cd /dir_name :- It changes directory to dir_name.
 

  

HARDWARE COMMANDS 

dmesg :- It displays detected hardware and boot messeges.

  

cat /proc/cpuinfo :- It displays CPU model information.


cat /proc/meminfo :- It displays hardware memory information.
 

 
lsblk :- It shows block devices related information in Linx.



free -m :- It shows free and used memory in MB (-m for MB)

lspci -tv :- It shows PCI(Peripheral Component Interconnect) devices.



lsusb :- It displays list of USB devices.

dmidecode :- It shows hardware information from the BIOS(Basic Input Output Device).



hdparm -i /dev/sda :- It shows information about disk sda.

hdparm -tT /dev/sda :- It do a read speed test on disk sda.

badblocks -s /dev/sda :- It tests on unreadable blocks on disk sda.




USERS command 

id :- It displays the active user id with login and group.

last :- It displays last logins on the system.

who :- It shows who is logged in on the system.

groupadd admin :- It make group admin to “admin”.

useradd MikeyToTech :- It will add user “MikeyToTech”.

userdel MikeyToTech :- It will delete user “MikeyToTech”.

usermod :- It can modify information of user.



FILE commands

 
ls :- It displays list of directories.

ls -a :- It displays formatted list of directories. It also displays hidden directories.

ls -l :- It displays list of directories with it’s permissions.

ls -al :- It displays all information about files or directories.



pwd :- It displays the path of current directories.

mkdir directory_name :- It creates a directory in current directory.

touch file_name :- It creates or update, given named file. If given named file is not exists then it makes new file.

rm file_name :- It deletes, given named file from current directory.

rm -r directory_name :- It deletes, given named directory recursively.

rm -f file_name :- It removes, given named file forcefully from current directory.

rm -rf directory_name :- It removes, given named directory forcefully from current directory.


cp file1 file2 :- It will copy file1 into file2. It creates file2 if it is not exists.

mv file1 file2 :- It will move file1 into file2. It creates file2 if it’s not exists.

Cp -r directory1 directory2 :- It will copy directory1 into directory2. It makes directory2 if it is not exist.

mv directory1 directory2 :- It will move directory1 into directory2. It makes directory2 if it is not exist.

mkdir path :- It will create directory on given path.

cat > file :- It appends input in file.
 


more file :- It displays content of file.

head file :- It displays first 10 lines of file.

tail file :- It displays last 10 line of file.

gpg -c file :- It encrypts, given named file.

gpg file.gpg :- It decrypts, given named file.

wc :- It prints the number of bytes, words and lines in file.


FILE permissions commands

chmod octal file_name :- It changes the permissions of file to octal.
   Example:- chmod 777 test.sh :- It sets rwx permission for owner, group, world.
   chmod 755 test.sh :- It sets rwx permission for owner, rx for group and world.

chmod +x test.sh :- It sets executable permission to test.sh file.

chmod -x test.sh :- It removes executable permission to test.sh file.

chown owner_user file :- It changes the owner(owner user name) of the file.

chown owner_user_group file :- It changes the owner and group owner (owner user group name) of the file.

chown owner_user_owner_group directory :- It changes the owner and group owner of the directory.




PORCESS RELATED commands

ps :- It displays current active processes.

ps aux :- It prints all processes owned by user named ‘x’.

pmap :- It shows memory map of process.

top :- It displays all running processes.

kill pid :- It kills process with mentioned pid id.

killall proc :- It kills all processes named proc.

pkill process_name :- It sends signal to processes with it’s name.

bg :- It resumes suspended jobs without bringing them to  foreground.

fg :- It brings the most resent job to foreground.

fg n :- It brings job n to foreground.




NETWORK commands

ifconfig :- It displays all netwok interfaces and ip addresses.

ethtool eth0 :- It is linux tool to show ethernet status.

mii-tool eth0 :- It also show ethernet status.

pint host :- It sends echo requests to test internet connection.
 

whois domain :- It displays who is, information for domain.(example : type command ‘whois system_ip).

dig domain :- It provides DNS information for domain.

dig -x domain :- It is used for reverse lookup host.


hostname -i :- It is used for lookup local IP address.

wget file :- It is use to download file. (example – type command  

wget url  it start downloading file from given url).

netstat -tupi :- It lists all active listening ports.


COMPRESSION/ARCHIVE commands

tar xf file_name.tar :- It extracts the file from file_name.tar.

tar cf file.tar directoy_name :- It converts, given name directory int file.tar.

INSTALL/REMOVE app commands

sudo Apt install app_name :- It will install app_name app in you linux system.

sudo Apt remove app_name :- It will remove app_name app from you linux system.

sudo apt update :- It will update your linux system.

sudo apt update app_name :- It will update only app_name app.

SEARCH command

grep pattern files :- It searches for pattern in files.

grep -r pattern dir :- It searches for pattern in directories.

locate file :- It finds all instance of file.

LOGIN (SSH @ TELNET)

ssh user@host :- It connects the host as user.

ssh -p port user@host :- It connects the host as user using specific port.

telent host :- It connects the system using telnet.

DISK USAGES

df -h :- It shows free space on mounted filesystems.

df -i :- It shows free inodes on mounted filesystem.

fdisk -l :- It displays list of disks partitions size and it’s type.

du -sh :- It displays total disk usage on current directory.

mount device_path mount_point :- It mounts device on mount point.

Post a Comment

0 Comments