Common Terminal Commands

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.

7 Likes

If DPKG is interrupted or packages require reconfiguration:

sudo dpkg --configure -a

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

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.

2 Likes

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

Hi,

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

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

6 Likes

thanks.

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 ?

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

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:

1 Like

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

2 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

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.

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.

1 Like

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