Table of Contents
Ubuntu
If you exit your desktop environment to a shell or boot into a shell, you might want to start a desktop environment such as KDE, GNOME, LXDE, or XFCE.
X Server
Start the X Server (this will start your desktop environment as well if it is configured to do so) via the Ubuntu shell:
startx
Start XFCE 4:
exec startxfce4
Start KDE:
exec startkde
Start LXDE:
exec startlxde
In some cases, you may need to put those commands in your ~/.xinitrc file and then type ‘startx’ for them to work correctly.
Viewing & editing files
Displaying, Viewing, And Editing Files How to edit or view the contents of a file in Ubuntu via command line:
nano: Nano is a text editor that is often preinstalled on Linux distributions. You can create a new text file or edit an existing one (whether text or a configuration file). Here are two examples of its usage via the Ubuntu shell:
nano newfile.txt
nano .xinitrc
less: The ‘less’ command displays the contents of a file right there in the command prompt window, and you can scroll through it easily by pressing the enter button. An example of this command’s usage:
less filename.txt
echo: The ‘echo’ command can be used to print a value or a string to the screen, and it can also be used to write text to a file. For example, you can use it to write ‘Yay’ to a text file named yay.txt as shown below:
echo "Yay" > yay.txt
Converting a string to hexadecimal: You can convert a string to hexadecimal using the echo command as shown:
echo -n "This string will be converted to hexadecimal format" | od -A n -t x1
Software Installation
Adding Software: Ubuntu Commands For Package Installation How to install an app/program in Ubuntu via command line:
You might have to type sudo before some of these Ubuntu commands.
apt-get install: This command installs a package in Ubuntu.
sudo apt-get install nano
If you want to install a package, but want to get the exact package name needed for installation (we’ll use Chromium for this example, a browser), you can use apt-cache search as shown below.
apt-cache search chromium
That should return a list of Ubuntu packages matching those search terms (along with their descriptions, if you’re exploring and want to find new apps), and you’ll most likely see ‘chromium-browser’ in the results. That means you can install Chromium by typing:
apt-get install chromium-browser
Removing Software
Removing Packages/Uninstalling Software In Ubuntu How to uninstall an Ubuntu package via command line:
The apt-get remove command uninstalls packages in Ubuntu.
apt-get remove chromium-browser
Bear in mind that apt-get remove won’t always remove associated packages (dependencies, in this case) that may have been installed.
Another useful Ubuntu command is ‘apt-get autoremove’. The autoremove command cleans up Ubuntu packages left behind during the (sometimes) incomplete uninstall process mentioned above. Example Usage:
apt-get autoremove
Authentication
Ubuntu Authentication/User Account Commands login: The login command can be used to log into a user account via the command line on Ubuntu. Example Usage:
login
logout: The logout command logs you out of a user account via the command line/terminal. This is useful for ssh sessions if you want to get off a VPS that you’re logged into. Example Usage:
logout
Sudo
sudo: The sudo command lets a non-root account perform administrative tasks on Ubuntu (depending on whether they are in the sudoers file and the permissions set in the configuration) by typing sudo before commands they execute, and they normally have to enter a password to proceed.
This is useful if you want to let someone use your computer, while limiting their permissions. Example Usage:
sudo apt-get install package-name
su: The su command lets you quickly switch to the root account in an Ubuntu terminal window. Example Usage: type ‘su’ followed by the root password when it prompts you for it.
It is inadvisable to stay logged in as the root user on Linux.
Passwords
passwd: The passwd command changes a user password. Example Usage: Type ‘passwd’ and follow the provided instructions/enter your new password.
Generate a random password using OpenSSL:
openssl rand -base64 16
This can also be done with the GPG tool:
gpg --gen-random --armor 1 14
Clear terminal
Clear Scrollback/Erase Terminal Contents If you’ve typed a password or something confidential in the terminal and need to clear your scrollback or erase your terminal history, use the following command:
history -c
SSH
ssh: You can use this command to connect to your remote server or other machine (for example: a server on a VPS web hosting account) for shell access without having to use your browser. Example Usage:
ssh username@domain.com
OR
ssh username@ipaddress
Shut down your SSH server:
service ssh stop
OR to start your SSH server:
service ssh start
Permissions
chmod: The ‘chmod’ command changes permissions. You can use it to set read, write, and access permissions on a file.
chmod 754 filename.txt
chown: The ‘chown’ command changes ownership of a file or directory.
chown newowner plop.txt
chroot: This enables you to change the current root directory for the terminal window you’re in. Usage.
Users
users: The ‘users’ command in Ubuntu will list the users that are currently logged in. Example Usage:
users
adduser: The ‘adduser’ command in Ubuntu creates a new user.
Example Usage:
adduser newusername
userdel: The ‘userdel’ command allows you to delete a user. Example Usage:
userdel username
Sudoers
visudo: This Ubuntu command enables you to edit the sudoers file, which you may need if creating a new user and need to give them sudo or other administrative privileges. Example Usage:
visudo
Groups
groups: The ‘groups’ command lists user groups. It can also list the groups that a particular user is in.
groups username.
Download files
Download Files Via The Command Line On Linux ‘wget‘ is one of those useful Ubuntu commands (although not exclusive to Ubuntu) you can use to download files via the command line. It saves URLs to a file, for example performing wget on an HTML page will download it and save it to a file. This works on not only Ubuntu, but the rest of the Linux distributions as well.
Example Usage:
wget http://domain.com/filename.txt
curl: curl is not installed on all machines, but it is found on many. You can use it download and print the contents of a file to the screen, or for other purposes as well. Example Usage:
curl http://domain.com/filename.txt
Drives
Accessing/Manipulating Drives And Directories In Linux If you haven’t booted into a desktop environment and don’t see your partition, second hard drive, or external USB drive in Ubuntu (or any Linux distribution) you may need to mount the drive using the mount command.
‘’ refers to the number of the device. If you find the device and it is /dev/sda6, then you would simply replace the ‘’ with ‘6’. Example Usage: mount /dev/sda* /mnt/directory_you_created
An example Ubuntu command to unmount a drive:
umount /mnt/directory_you_created
Directories
Ubuntu command to enter a directory or mounted drive:
You can use the ‘cd’ command to enter a directory
cd directory_name
List directory contents:
You can list the contents of the directory you entered by typing one of the ‘ls‘ Ubuntu commands add -a to list the respective permissions.
ls -a
Remove a directory:
You can remove a directory using the ‘rmdir’ command if it is empty. In order to remove a directory that contains files, you can use the ‘rm’ command with the parameter ‘rf’.
rm -rf directory_name
Copying files
Copying Files And Moving Them In Ubuntu Linux You can use the ‘cp’ command to copy files or directories in Ubuntu or any other Linux distribution.
cp -R home/username/filename.txt /directory/subdirectory/filename.txt
The ‘-R’ option means recursive and copies files inside the directory.
RAM
Create A RAM Disk To Run Your Programs From RAM (Or Load Files From RAM) You can create a partition in RAM (use a portion of your memory as a drive) to store frequently-accessed files or programs. This will enable them to load much faster (as RAM is much faster than a hard drive).
Bear in mind that this has to be recreated every time your computer is restarted, so you may want to make these commands run on startup. You also need root priviledges to run the following commands (or the ‘sudo’ command).
mkdir -p /media/ramdisk
mount -t tmpfs -o size=1024M tmpfs /media/ramdisk
Networking
Ubuntu/Linux Networking Commands
ifconfig
This can be used to provide information about running network interfaces, including their IP addresses. This can be used to derive your computer’s IP address on your local network.
If it returns ‘eth0’, then you’re probably using an ethernet connection, hence the ‘eth’, and ‘wlan0’ refers to Wi-Fi (wireless LAN). It may also be both if you have both a wired and a wireless network interface card (NIC).
The ping command lets you ‘ping’ another machine such as a server to see if it responds. You can also use ping to determine if you have a working Internet connection. If you receive a response such as this:
PING google.com (IP Address) 56(84) bytes of data. 64 bytes from lga25s61-in-f14.1e100.net (IP Address): icmp_seq=1 ttl=57 time=2.17 ms from a website using this command, your Internet connection is working: ping google.com
ping
Start a network interface. Example Usage:
ifup
ifup eth0
ifdown: Stop a network interface.
ifdown eth0
The whois command can provide domain info by simply typing whois domain.com.
whois:
netstat: The ‘netstat’ command displays the Internet connections among other network statistics for your Ubuntu machine. Example Usage:
whois microsoft.com
netstat
The ‘traceroute’ command attempts to trace the route that a packet has to travel to get to the specified host.
traceroute domain.com
System management
Managing Processes, Closing Programs, And System Resources
The ‘crontab’ Ubuntu command is used to make programs run on startup in Ubuntu.
crontab
The ‘top’ command displays running processes and their system resource usage such as RAM and CPU usage. Just type ‘top’ to run it and Ctrl + C to exit.
top:
This Ubuntu command displays virtual memory statistics. Just type ‘vmstat’ to launch it.
vmstat
This shuts down processes by sending them the SIGTERM signal. Please be careful when using any kill commands. Learn about its usage thoroughly before trying it.
pkill
pgrep will list the IDs of processes with the name you provided. For example, if you want to see all the running mysqld processes, typing ‘pregrep mysqld’ will list the IDs of the running mysqld processes.
pgrep
w: The ‘w’ command lists users’ processes beside their usernames, their average system loads. Example Usage:
w
On and off again
Shutting Down, Rebooting, and Power Management shutdown: This Ubuntu command can shut down or reboot your machine. The ‘-h’ option powers off your Ubuntu machine, and the ‘-r’ option reboots it.
shutdown -h now
shutdown -r now
reboot: This reboots the computer. Example Usage:
reboot
Paths
Get the path of a command/get the path of a program
You can get the path of a command or find out where a program’s binaries are installed by using the ‘dpkg-query’ command:
dpkg-query -L programname
You may see many paths. For the binaries, look for the ‘usr/bin’ paths.
BIOS
Get BIOS info via command line in Linux (this works for other distributions as well)
Edit this page on GitHub
dmidecode