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.

mv - Move All Files Including . Hidden Files - How To for Linux Unix

By default, the mv command will not move files in the source directory that begin with . (also known as hidden files). If you want to move all files (including hidden files that begin with a dot .), run mv like this:

 mv ./{*,.*} /destination/directory/here 

 ​Below are some examples of a directory structure before and after running mv:

./
├── level1
│   ├── 1
│   │   ├── one.txt
│   │   └── .two.txt
│   ├── 2
│   │   ├── .four.txt
│   │   └── three.txt
│   ├── five.txt
│   └── .six.txt
└── level2

mv ./level1/* ./level2/

./
├── level1
│   └── .six.txt
└── level2
    ├── 1
    │   ├── one.txt
    │   └── .two.txt
    ├── 2
    │   ├── .four.txt
    │   └── three.txt
    └── five.txt

As you see ./level1/.six.txt did not move because it was in the source directory and it was a hidden file. If you were to move it the correct way, it would work and look like this:

mv ./level1/{*,.*} ./level2/

.
├── level1
└── level2
    ├── 1
    │   ├── one.txt
    │   └── .two.txt
    ├── 2
    │   ├── .four.txt
    │   └── three.txt
    ├── five.txt
    └── .six.txt

 

Pages

Subscribe to Command Line