Linux: More Basic Commands

Networking

Ping 1 Time

ping google.com -c 1 #c is abbreviation for count

Check Networking

ifconfig
ip addr

How to Check Open Ports

sudo netstat -tulpn #Shows address and port
System Admin

Emulate root

sudo -s #This prevents the system from asking for the sudo password after timer expires
exit #exit sudo mode

Emulate another user

su kimconnect #To become the user kimconnect
exit #end user masquerade

How to check kernel version

uname -a

Trigger a system checkup on next reboot

sudo touch /forcefsck

Timed Shutdown

sudo shutdown -h 5 #Shutdown. Halt everything in 5 minutes

Cancel Shutdown timer

sudo shutdown -c

Check CPU usage of PHP

ps aux | grep apached

Check CPU/Memory Usage of All Processes

top #preinstalled in most systems
htop #new top package, human readable

Check Services

service SERVICENAME status #Older unix command
systemctl status SERVICENAME #Systemd command

Stop Processes

killall PROCESSNAME #instantly halt a process and its related
pkill #similar to killall with more chances of success
File & Folder Manipulations

List hidden files

ls -la #long format, all files

Check Disk Space

df -ah #disk free all human readable

Check folder/directory size

du -sh /var/www/html #disk usage sum human readable

Find Universal Identifier for Drives (UUID)

sudo blkid

Check for Existing Mounts

mount

How to Create a Mount

mount /dev/sda2 /mnt #sda2 = disk 1 partition 2

Check for Persistent Mounts (Mounts at Bootup)

less /etc/fstab

Create a file

touch testfile.txt #This command also updates the last modified time attribute

Move and rename a file

mv file1.txt ~/file1.txt_backup #Move file1.txt into home directory and rename it with a _backup suffix

Find the directory where an App is installed

which google-chrome

less is the same as more + cat

less somefile.txt
cat somefile.txt | more

Search for a phrase inside a file

grep -i kimconnect.com domains.txt  #Ignore case during grep
strings domains.txt | grep kimconnect.com | less #Alternative method

Count lines, words, and letters

wc domains.txt

Switch between different files

vi text1.txt
Keys Combo: Control+Z
vi text2.txt
Keys Combo: Control+Z
jobs  #Shows tasks in the background
fg %2  #Join the job index

 

Posted on Categories Linux

Leave a Reply

Your email address will not be published. Required fields are marked *