Command Line

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 List of All Groups in Domain from Command Line - Windows

To get a list of all groups in a domain and export them into a text file, run the following command (you need to have the appropriate permissions to run this command, a domain admin will work):

net group /domain > domain-groups-list.txt

This will export a list of all domain groups into a text file in the working directory. This should work in any Microsoft Windows Active Directory Domain.

How to Get List of All Domain User Accounts from Command Line - Windows

To get a list of all user accounts in a domain and export them into a text file, run the following command (you need to have the appropriate permissions to run this command, a domain admin will work):

net user /domain > domain-user-list.txt

This will export a list of all domain users to a text file in the working directory. This should work in any Microsoft Windows Active Directory Domain.

Linux - Find Total and Free Disk Space from Command Line or Terminal

To find the total and free disk space in Linux operating systems such as Ubuntu and openSUSE, you need to use the df command. Here is an example:

 

df -h
 
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       913G  481G  386G  56% /
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           807M  1.2M  805M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G  2.7M  2.0G   1% /run/shm
cgroup          2.0G     0  2.0G   0% /sys/fs/cgroup
 
If you run df without any switches, it will give you the same output, but in Kilobytes. If you want to learn how to find total and free disk space in Windows, check out this tutorial.

Find Total and Free Disk Space from Command Line Windows XP - 7 - 2003 - 2008

To find the total and free disk space in all modern versions of Microsoft Windows from the command line, you need to use the fsutil command. Here is an example:

fsutil volume diskfree c:

Total # of free bytes        : 11658346496

Total # of bytes             : 209712050176

Total # of avail free bytes  : 11658346496
 
Unfortunately, there is no way to change the output from bytes to megabytes or gigabytes. If you want to learn how to find total and free disk space in Linux, check out this tutorial.

Pages

Subscribe to Command Line