Terminal

Linux - History Command Tutorial - How to Run Previous Commands and Clear History

The history command is very useful for people who use the command line. If you haven't used it before, now is a great time to make it a habit, as it can save you time.

The history command by itself will provide a numbered list of previously executed commands:

history - tutorial run previous commands 1

To execute one of the previously ran commands, use the exclamation mark followed by the number of the command (no spaces):

!3

history - tutorial run previous commands 2

To clear the history, run the following command:

history -c

history - tutorial run previous commands 3

To simply run the last ran command again, run the following command:

!!

Hope this helps some of you become more proficient in the command line!

Linux - Change to Home Directory From the Command Line Terminal

A lot of people don't know you can do this, or don't know how. Obviously to change directories you use the cd command. To change to your home directory, run the following command:

cd ~

Change_to_home_directory_linux_terminal

You can also use this method to reference files or folders in your home folder. For example:

cat ~/Documents/send-connector.txt

is the same thing as this:

cat /home/user/Documents/send-connector.txt

Linux - Log out of Unity or Gnome from Command Line Terminal

To log out of Gnome or Unity from the command line, simply run this command:

gnome-session-quit

It will prompt you to click the 'log out' button. To log out without being prompted, run this command:

gnome-session-quit --no-prompt

This should work in any Linux distribution (Ubuntu, Debian, openSUSE...) that is using Unity, Gnome, or a Gnome based desktop environment.

Ubuntu Linux - How to Find IP Address from Terminal and GUI

Finding your local LAN ip address in Ubuntu Linux is very easy. There are 2 ways to find it, from the command line or from the GUI.

Command Line:

Just open the terminal and run this command: ifconfig

Ubuntu Linux - Find IP Address 1

 

GUI:

Right click on the Network Manger icon in the top right corner and click on "Connection Information". You will then see a window displaying your ip address and other useful network information:

Ubuntu Linux - Find IP Address 2

Ubuntu Linux - Find IP Address 3

Ubuntu Linux - How to Restart or Reboot System from Command Line Terminal

 

Restarting or rebooting an Ubuntu Linux computer or server from the command line is very simple. Just run the following command:
 
sudo reboot
 

Ubuntu Linux - How to Shutdown System from Command Line Terminal

Shutting down an Ubuntu Linux computer or server from the command line is very simple. Just run the following command:

sudo shutdown -P 0

-P means 'Power Off' and 0 is the number of seconds to wait before powering off.

How to Get and Download all File Type Links from a Web Page - Linux

This tutorial explains how to take a URL and get all of the links for a specific file type (pdf, jpg, mp3, wav, whatever extension you want) exported into a list and download all of the links in Linux. In my example, I have a web page with over 20 links to pdf files. Instead of downloading them individually and manually, this script will allow me to download all of them at one time, and give me a list of each link.

You need to have lynx and wget installed before running this script. To install, run the following command:

Ubuntu: sudo apt-get install lynx-cur wget

openSUSE: sudo zypper install lynx wget

Save the following text as link-dl.sh and execute it by running "sh link-dl.sh":

 

#! /bin/bash
lynx --dump http://www.appassure.com/resources/technical-documentation/ | awk '/http/{print $2}' | grep pdf > /tmp/file.txt
for i in $( cat /tmp/file.txt ); do wget $i; done

Linux - How to Find the Hostname

Finding the hostname in Linux is very simple and basic. The method is the same, regardless of your Linux distribution (Ubuntu, openSUSE, Fedora...) Here are 2 ways to find the hostname:

Run the command "hostname":

hostname

Read the contents of "/etc/hostname":

cat /etc/hostname

Linux - How to Find Kernel Version from Terminal

To find out the Linux kernel version in use on a Linux system (should work on any Linux distribution, including Ubuntu, openSUSE, Fedora, or whatever), just run the following command:

uname -r

uname -r

Linux - Find OS Version in Ubuntu and openSUSE from Command Line Terminal

To find the operating system version number and name from the terminal in Ubuntu and openSUSE (should work in other Linux operating systems as well, but may need to install the package), you need to run the lsb_release command. Here are a few examples:

 

lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise
 
or
 
lsb_release -r
Release: 12.04

 

Pages

Subscribe to Terminal