Common Terminal Commands

Update and Install

Command to update your sources:

sudo apt update

Command to check for available upgrades:

apt list -u

Or:

apt list --upgradable

Command to upgrade available packages on your system:

sudo apt upgrade

Upgrade as long as existing file deletion is not necessary

sudo apt dist-upgrade

Upgrade even if existing file deletion is necessary

sudo apt full-upgrade

Installing a package using sudo apt install that is already installed will mark the package as manually installed. The command apt-mark manual will also accomplish this task. This prevents a package from being removed by sudo apt autoremove

The apt-mark command is used to mark a package. Commonly, it is used to mark a package to be held at the current version. If you mark a package as hold and then run sudo apt full-upgrade, all available packages will be upgraded except for the held packages. For example, let's say you dislike the latest version of Gimp and you wish to keep it as it is without upgrading it, but wish to upgrade your system:

sudo apt-mark hold gimp

If you change your mind later and like the latest version, you can revert with:

sudo apt-mark unhold gimp

sudo apt-mark auto package-name

sudo apt-mark manual package-name

sudo apt-add-repository ppa-example

sudo add-apt-repository --remove ppa-example

Command to list all currently installed applications:
apt list --installed

This command show raw dependency information for a package

sudo apt-cache depends package-name

This command shows reverse dependency information for a package

sudo apt-cache rdepends package-name

Command for broken package holding up APT:

sudo apt --fix-broken install

Command to check if a specific package is installed and give its details and depends:

dpkg -s package-name

Basic command to install a package with apt (Advanced Package Tool):

sudo apt install package-name

Basic command to install a system recommended package with apt (Advanced Package Tool - Applies to apt-get and aptitude the same way):

sudo apt-get install --install-recommends package-name

To downgrade (Applies to apt-get and aptitude the same way):

sudo apt install package-name=version

Command to install a package with APT and grab any needed dependencies (Applies to apt-get and aptitude the same way):

sudo apt -y install package-name

Command to force install a package with APT(Applies to apt-get and aptitude the same way):

sudo apt install -f package-name

Command to reinstall a package with APT (Applies to apt-get and aptitude the same way):

sudo apt install --reinstall package-name

Command to remove a package with APT (Applies to apt-get and aptitude the same way):

sudo apt remove package-name

Command to remove a package with APT and remove any configuration files (Applies to apt-get and aptitude the same way):

sudo apt remove --purge package-name

Command to install a .deb package from terminal opened withing the directory containing the .deb package e.g. ~/Downloads (Applies to apt-get and aptitude the same way):
(If necessary to change directory - For example in Downloads Directory)

cd ~/Downloads

(Installation Command)

sudo dpkg -i package-name

System Management:

This command elevates you to Root Permissions but keeps the terminal in your Home Directory

sudo -s -H

or

sudo su

This command elevates you to Root permissions and elevates the terminal to top level Root directory:

sudo -i

This command spawns a root shell in the directory from which terminal is presently opened:

sudo sh

Use exit to exit the elevated terminal.

Command to show the Path of the Working Directory (Sometimes, you need to grab the path real quick):

pwd

Command for concatenate, to list the contents of a file on the standard output:

cat file.txt

Command to create a new blank document or file through CLI:

touch /home/$USER/Documents/file.txt

Command to locate a file by its specific name:

locate file-name.png

Command to find a file with terminal opened from within the searched directory:

find /home/$USER/Documents/file.txt

Command to search the contents of a given file:

grep file.txt

Commands head and tail are commands to view the first few lines or last few lines of text.

Command to compare differences between two files (USEFUL!):

diff

Example:

diff file1.ext file2.ext

Command to list directories or files contained within the directory from which the terminal was opened:

ls

Command to change directory

cd /path/to/directory

Command to make a new directory within the current directory or in the path provided in the command:

mkdir

mkdir /path/to/directory/location

Command to copy a file to same location as a back up or to a new location (EXAMPLE using config):

cp config config-bkp

Example:

cp image.png /path/to/new/location/image.png

Command to show Disk Usage:

du -sch

Command to show current date and time

date

Command to show User I.D.'s:

id

Command to show currently logged in user account:

whoami

Command to show free space on disk:

df -h

Command to show the Manual

man

man package-name

Command to show kernel version and architecture:

uname -a

uname -r

Command to add a user to a Group:

adduser user-ID

To find your Distro Name, Release and version:

lsb_release -a

Command to show free memory:

Free -m

Command to show highest to lowest CPU usage:

top

Command to show highest resource usage during boot:

system-analyze blame

Command to show user, pid, resource usage and child processes currently running:

ps auxwf

To see a list of all previously used commands (this is VERY handy when you used a command a week ago, need it now and cannot remember it):

history

To refresh or restart the terminal instance:

reset

To clear out the terminal without refreshing it:

clear

To exit from an elevated prompt (e.g. sudo -i):

exit

exit 0

#COMPRESSION AND ZIP

Tar xf

gzip /gzip -d

XRANDR COMMANDS

Command to have xrandr show display information:

xrandr

Command to disable a monitor (EXAMPLE using HDMI):

xrandr --output HDMI1 --off

Command to change resolution and resresh rate:

xrandr --output HDMI1 --mode 1024x768 --60hz

xrandr --output VGA1 --mode 1024x768

xrandr --output LVDS1 --rate 75

Command to show current monitor minimum, current and maximum resolution:

xrandr|head -1

Command to position the output of monitor in relation to a second monitor (EXAMPLE - VGA and HDMI - use actual values):

xrandr --output VGA1 --right-of HDMI1

xrandr --newmode

xrandr --addmode VGA1 1440x900

IMAGE CONVERT

From terminal opened within the directory containing the files (This command does not produce a printed output unless unsuccessful):

convert file.png file.svg

Create symlink (This command does not produce a printed output unless unsuccessful):

ln -s /path/to/file /path/to/new/location

(image or icon symlink in same directory)

ln -s file.png file-diff-name.png

Command to trace a symlink to the original file:

readlink -f symlink name

53 Likes

I took a quick look to make sure that there are not too many stickies posted.
Will try out making it a sticker. All Users feel free to add commands to this list.

9 Likes

If DPKG is interrupted or packages require reconfiguration:

sudo dpkg --configure -a

6 Likes

If the package system is locked close all package managers and use the following.
sudo fuser -vki /var/lib/dpkg/lock; sudo dpkg --configure -a

Clear Recent Items:
echo > ~/.local/share/recently-used.xbel

Show terminal history:
history

Clear terminal history:
history -c

3 Likes

Create system information text file in home folder:

sudo lshw -sanitize > lshw.txt

Create default package text file in home folder:

dpkg --get-selections > installed-software

Locate residual packages after removing software:

sudo dpkg -l | grep "^rc"

Remove residual packages:

sudo apt-get remove --purge $(sudo dpkg -l | grep "^rc" | awk '{print $2}' | tr '\n' ' ')

6 Likes

Awesome thread. I've relied heavily on command line usage in DOS/Windows, and have felt kind of helpless so far using linux terminal, except for the very basics. This info is just what I needed to get me going.

4 Likes

here's a question i've always wanted to ask - what is the difference between apt install and apt-get install?

1 Like

Hi,

This should help you to understand a little bit more why.

APT vs APT-GET: What's the Difference?

7 Likes

thanks.

2 Likes
1 Like

@Bourne, Why not post it in the existing topic ?

Also why post this in Feedback ? what feedback do these video's give about Zorin OS ?

1 Like

Because @Aravisian topic is diffrent with explanations and don't want broken when he worked and wrote that all. :grinning:

1 Like

I came across this article earlier today and spent some time trying out its various good suggestions:

My personal favorites are the 'bat" command and the "fd" command.

3 Likes

If you want to access root files for once, you can type
sudo thunar
That's it! Hope it would help someone :kissing_smiling_eyes:

2 Likes

BackUp Your Entire Hard Drive with TAR

You can back up your hard drive on Linux with TAR by compressing an exact copy of your entire Linux file system into a TAR archive.

This can be accomplished with just two commands. Open a terminal and enter the following:

cd /

The cd command puts us in the / directory (or root). This is the home to all files on your Linux installation. After that just run the backup command and sit back.

sudo tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /

Once the command above has finished its run, look for the backup.tar.gz file inside the / folder and save it to an external file system. If ever you lose some files that need to be restored, just run the following command to restore them:

sudo tar -xvpzf /path/to/backup.tar.gz -C /restore/location --numeric-owner

4 Likes

Oooh! I'm setting up a bash script to back up the contents of an entire partition, and this will do the job nicely. I was going to use zip or gzip, but there are caveats with their use.

I'm going to use the PARTUUID (partition UUID) for the source and the destination, so we're sure to have the correct partitions, no matter if the device path and node (for example: /dev/sdb2) changes when USB drives are plugged / unplugged.

I plan on setting it up so the file name is the date and time of the backup.

Here's what I've got so far... I've never made a bash script, so it's slow going. I had to add a period in front of comments so they didn't show up bolded.

#!/bin/bash

.# This script copies the contents of a source drive to a destination drive, zipping it.
.# Find the PARTUUID of the source and destination drives with: sudo blkid

.# Set up source drive using PARTUUID
sourcedrive = {PARTUUID OF SOURCE DRIVE}

.# Set up destination drive using PARTUUID
destinationdrive = {PARTUUID OF DESTINATION DRIVE}

.# Get device paths (ie: /dev/sdb1 or whichever)
sourcedevicepath = sudo blkid | grep $sourcedrive | sed -e 's/^(.):.$/\1/'
destinationdevicepath = sudo blkid | grep $destinationdrive | sed -e 's/^(.):.$/\1/'

.# Get mount paths (ie: /media/owner/BackUpDrive or whichever)
sourcemountpath = sudo mount | grep $sourcedevicepath | grep -o -P '(?<=on ).?(?= type)'
destinationmountpath = sudo mount | grep $destinationdevicepath | grep -o -P '(?<=on ).
?(?= type)'

cd $sourcemountpath

.# NOTE: Put your backup software command below

[EDIT]
So, something like this? Would this work?

sudo tar -cvpzf printf "%(%F_%H%M%S)T.tar.gz" --one-file-system $destinationmountpath

1 Like

Brilliant - it labels the date of the backup.
Along with this tip (it embarrassingly never occurred to me to limit that), I hope you continue to help on this forum.

1 Like

I think this gives a cleaner file name:
printf "%(%F_%H-%M-%S)T.tar.gz"

It'd look like this:
2022-12-23_16-10-08.tar.gz

YYYY-MM-DD_HH-MM-SS format.

That makes sorting the backups by date and time easy.

You can't use the colon ':' in the file name, as that is a special designator for a remote file.

2 Likes

For beginners, if you don't know, you can check version of some software installed. For instance, Zorin OS, as well as other Ubuntu-based OSes come pre-installed with Python3.
So you can use the command:

$python3

To check Wine :wine_glass: version, you'll use:

$wine

To install an .exe file using Wine from terminal, you may use:

$wine (filename).exe

1 Like