RK !

Let's make comprehension easy ...

Ubuntu Quick Reference Commands

Author: Romaan, Last Updated: Jan. 5, 2021, 6:50 a.m.

Ubuntu is an open source software platform that runs everywhere from IoT devices, the smartphone, the tablet and the PC to the server and the cloud. If you use Ubuntu, then mostly you also use bash terminal and would like to do many things using commands. Below I have summarized a list of commands that we commonly use to accomplish our tasks. They include software management, file management, process management, network management, storage management and so on.

Software Management:

apt-get

APT package handling utility.

Associated files and directories:

  • /etc/apt

Example 1: apt-get update           # Resynchronies the package index files from their sources

Example 2: apt-get upgrade         # Install the newest versions of all packages currently installed on the system

Example 3: apt-get dist-upgrade   # Does upgrade and also intellingently handles changing dependencies with new versions of packages

Example 4: apt-get install <package-name>    # Install a package

Example 5: apt-get purge <package-name>     # Removes packages and also its related configuration files

Example 6: apt-get download <package-name>   # Will only download the package without installing into the system

Example 7: apt-get check                 # Diagnostic tool to update the package cache and checks for broken dependencies

add-apt-repository

Adds a repository into the /etc/apt/sources.list or /etc/apt/sources.list.d or removes an existing one

Associated files and directory:

  • /etc/apt/sources.list.d

Example: sudo add-apt-repository --remove ppa:<source-name>/ppa     # Removes the source from list

dpkg

Package manager for debian

Example 1: dpkg --list   # List all the packages installed

update-alternatives:

Maintain symbolic links determining default commands.

Associates files and directories:

  • /etc/alternatives/           # The default alternatives directory
  • /var/lib/dpkg/alternatives/      # The default administration directory

Example 1: sudo update-alternatives --query editor

Example 2: sudo update-alternatives --config java                  # Configure default java

Example 3: sudo update-alternatives --display java                # List alternatives for java

Services and Process Management

init service

Run a System V init script

Associated files and directories:

  • /etc/init.d              # Directory containing System V init scripts
  • /etc/init                # The directory containing upstart jobs

Example 1: service --status-all    # Shows list of all services

Example 2: service <service-name> restart

systemd server

Running a service: systemctl start <sevice-name>.service

Stopping a service: systemctl stop <service-name>.service

Reloading a service: systemctl reload <service-name>.service

List all unit files: systemctl list-units

List dependency of service: systemctl list-dependencies <service-name>.service

To see low level details of service: systemctl show <service-name>.service

To view the log files for the service: journalctl 

To view the log files from the time of boot: journalctl -b

The service files will be located in /lib/systemd/system/ .

Archive, Backup and Restore

tar:

Example 1: tar -cvf output.tar dir-1 dir-2 dir-3         # Create a tar file

Example 2: tar -xvf output.tar      # Extract archive

Example 3: tar -xvf output.tar file-name   # Extract particular file

Example 4:  tar -t output.tar           # List contents of archive

Example 5: tar -u output.tar dir-1        # Append files newer than copy in archive

Grub (Grand Unified Bootloader)

grub-reoot:

Set the default boot entry for GRUB, for the next boot only

Example: sudo grub-reboot <number> && sudo reboot

List grub entries from command line:

awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg

Update settings file in grub:

sudo update-grub

Certificate Management

Create a directory for extra CA certificates:

sudo mkdir -p /usr/share/ca-certificates/extra

Copy CA .crt file to directory

sudo cp foo.crt /usr/share/ca-certificates/extra/foo.crt

Let ubuntu add .crt file's path to relative to /usr/share/ca-certificates to /etc/ca-certificates.conf

sudo dpkg-reconfigure ca-certificates

In case of .pem file on ubuntu, it must first be converted to a .crt file

openssl x509 -in foo.pem -inform PEM -out foo.crt

Disk Management

fdisk # Manipulate disk partition table

mount # Command that shows list of all mounts

df -h # List the disk space

/etc/fstab # List of drives that will be mounted on boot

/etc/mtab # List of drives that are currently mounted

badblocks -v /dev/sdb1 > badsectors.txt   # List bad block sectors

e2fsck -l badsectors.txt /dev/sdb1    # Instruct OS not to write to these badsectors for ext2, 3 and 4

fsck -l badsectors.txt /dev/sdb1        # Instruct OS not to write to these badsectors

lsbk -f    # List filesystem type and UUID

Popular Tags:


Related Articles:


Comments: