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

22 Likes

10 posts were split to a new topic: Common Terminal Commands comments and issues

Split to keep the informational nature of the topic clean. Please post more commands but reserve comments and issues for the sister thread.

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.

5 Likes

If DPKG is interrupted or packages require reconfiguration:

sudo dpkg --configure -a

4 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

2 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' ' ')

4 Likes