Useful Ubuntu Linux System and File Commands

This post is where I keep some useful Ubutu Linux commands that I use frequently in the command-line terminal.  I will organize this more later, it is a scratch pad for now.  ( To open your terminal, press Ctrl+Alt+T which will open the terminal which will be showing your user’s home directory. )



Add new linux user with home directory:

sudo useradd -m username

Add user to sudoers ( sudo ) user group:

usermod -aG sudo username

Show all processes currently listening on a port:

sudo lsof -i -P -n | grep LISTEN

Remove “snap” from Ubuntu ( link ):

Create a .zip file of a directory and all of it’s contents:

zip -r directory_name
# The next line unzips an archive to the current directory

List files with permissions in numeric/octal format ( 755, 644, etc. ):

stat -c '%A %a %n' *

Set file and folder permissions recursively, beginning in the current directory:
( if you are on shared hosting remove the “sudo” command from beginning of each line )

# The first line sets the permissions for files only
sudo find . -type f -exec chmod 644 {} +
# This next line sets permissions for the folders only
sudo find . -type d -exec chmod 755 {} +

Update the operating system and it’s installed applications and reboot the computer ( close all of your programs first ):

sudo apt update; sudo apt dist-upgrade --yes --force-yes; sudo apt autoremove --yes; echo "Rebooting..."; sleep 3; reboot;

Show running processes in order of CPU usage:

sudo top

Show interactive process viewer with pathnames of running process files:

sudo htop

Show where a user currently is and what they are running on the system, this example would look for the user ‘amrita’ and display the current activity:

sudo w amrita

Clear bash history:

history -cw


Leave a Reply