Ubuntu Cheatsheet

Short, sharp and shiny reference to commands that I constantly have to look up while developing and administering Ubuntu systems.

New System

A few steps I tend to perform on a new system.

# Allow sudoers to elevate without typing in their password every time.
# Careful! This may be considered a security risk.
echo "%sudo ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers > /dev/null

Users and Permissions

Users and Groups

Add a user: adduser username

List a user’s groups: groups username

Assume a user’s identity: sudo su - -s /bin/bash username

Set a user’s home directory: sudo usermod --home /dir/dir username

Setting up a new user as an Administrator:

sudo adduser <username>
sudo adduser <username> sudo
sudo adduser <username> adm
sudo adduser <username> lpadmin

File/Directory Ownership

Set owner user/group: chown -R username:groupname directoryname/

Working with Files

Copy from one computer to another: scp  [user@]host1:]file1 [user@]host2:]file2


Apt (install software)

Update Lists: sudo apt-get update

Search packages: apt-cache search [search string]

Install Software: sudo apt-get install packagename


The following commands vary between daemons, but many actively maintained products are configured to work this way.

Start a daemon: /etc/init.d/servicename start

Stop a daemon: /etc/init.d/servicename stop

Query status of running services: service --status-all

Start a daemon (shorthand): service servicename start

Stop a daemon (shorthand): service servicename stop

Disk Drives and Storage

Get a summary of disk usage in the current folder:
du -s -m *

Find those files taking up all your valuable disk space! (my source: ref).

sudo find . -maxdepth 1 -type d ! -name . -exec du -sh '{}' \; | sort -h

List attached drives (my source: reference). I found this particularly useful when working with AWS.

xvda               8G
└─xvda1 ext4       8G /          cloudimg-rootfs
xvdb    ext3    15.3G /mnt
xvdc    ext3    15.3G

You can also try sudo fdisk -l for a similar result.

Another useful command is df -h.


Compile a single file of C++ code to an executable. This command compiles main.cpp to main.exe.

gcc -g -Wall -std=c++0x main.cpp

Append to a File with elevated permissions

echo “append this line of text” | sudo tee -a myfile.txt > /dev/null



Delete unversioned files

You can clean up any versioned files with svn revert, but how do you get rid of any files that are not under version control? Here’s how (my source: Guy Rutenburg).

The first command performs a dry run, simply listing the unversioned files. The second command pipes the result of the first to xargs to delete the file.

svn status --no-ignore | grep '^\?' | sed 's/^\? //'
svn status --no-ignore | grep '^\?' | sed 's/^\? //' | xargs -Ixx rm -rf xx


Tips & Tricks

Troll this Post

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s