GNU/Linux most wanted

[ GNU/Linux most wanted ]

Summary of most useful commands
©Copyright 2014-2005, Free Electrons.
Free to share under the terms of the Creative Commons
Attribution-ShareAlike 3.0 license
Translations, command and concepts details:
Thanks to Michel Blanc, Hermann J. Beckers and Thierry
Latest update: Jun 13, 2016

Download this PDF file.


Handling files and directories
Create a directory:

mkdir dir

Create nested directories:

mkdir -p dir1/dir2

Changing directories:

cd newdir
cd ..     #(parent directory)
cd -      #(previous directory)
cd        #(home directory)
cd ~bill  #(home directory of user bill)

Print the working (current) directory:


Copy a file to another:

cp source_file dest_file

Copy files to a directory:

cp file1 file2 dir

Copy directories recursively:

cp -r source_dir dest_dir
rsync -a source_dir/ dest_dir/

Create a symbolic link:

ln -s linked_file link

Rename a file, link or directory:

mv source_file dest_file
Remove files or links:
rm file1 file2

Remove empty directories:

rmdir dir

Remove non-empty directories:

rm -rf dir


Listing files
List all “regular” files (not starting with .) in
the current directory:

ls  #List files

Display a long listing:

ls -l

List all the files in the current directory,
including “hidden” ones (starting with .):

ls -a

List by time (most recent files first):

ls -t

List by size (biggest files first):

ls -S

List with a reverse sort order:

ls -r

Long list with most recent files last:

ls -ltr


Displaying file contents
Concatenate and display file contents:

cat file1 file2

Display the contents of several files (stopping
at each page):

more file1 file2
less file1 file2  #(better: extra features)

Display the first 10 lines of a file:

head -10 file

Display the last 10 lines of a file:

tail -10 file


File name pattern matching
Concatenate all “regular” files:

cat *

Concatenate all “hidden” files:

cat .*

Concatenate all files ending with .log:

cat *.log

List “regular” files with bug in their name:

ls *bug*

List all “regular” files ending with . and a
single character:

ls *.?


Handling file contents
Show only the lines in a file containing a given

grep substring file

Case insensitive search:

grep -i substring file

Showing all the lines but the ones containing a

grep -v substring file

Search through all the files in a directory:

grep -r substring dir

Sort lines in a given file:

sort file

Sort lines, only display duplicate ones once:

sort -u file   #(unique)


Changing file access rights
Add write permissions to the current user:

chmod u+w file

Add read permissions to users in the file group:

chmod g+r file

Add execute permissions to other users:

chmod o+x file

Add read + write permissions to all users:

chmod a+rw file

Make executable files executable by all:

chmod a+rX *

Make the whole directory and its contents
accessible by all users:

chmod -R a+rX dir   #(recursive)


Comparing files and directories
Comparing 2 files:

diff file1 file2

Comparing 2 files (graphical):

gvimdiff file1 file2
tkdiff file1 file2
meld file1 file2

Comparing 2 directories:

diff -r dir1 dir2


Looking for files
Find all files in the current (.) directory and its
subdirectories with log in their name:

find . -name “*log*”

Find all the .pdf files in dir and subdirectories
and run a command on each:

find . -name “*.pdf” -exec xpdf {} ';'

Quick system-wide file search by pattern
(caution: index based, misses new files):

locate “*pub*”


Redirecting command output
Redirect command output to a file:

ls *.png > image_files

Append command output to an existing file:

ls *.jpg >> image_files

Redirect command output to the input of
another command:

cat *.log | grep error


Job control
Show all running processes:

ps -ef

Live hit-parade of processes (press P, M, T: sort
by Processor, Memory or Time usage):


Send a termination signal to a process:

kill <pid>   #(number found in ps output)

Have the kernel kill a process:

kill -9 <pid>

Kill all processes (at least all user ones):

kill -9 -1

Kill a graphical application:

xkill   #(click on the program window to kill)


File and partition sizes
Show the total size on disk of files or
directories (disk usage):

du -sh dir1 dir2 file1 file2

Number of bytes, words and lines in file:

wc file   #(word count)

Show the size, total space and free space of the
current partition:

df -h .

Display these info for all partitions:

df -h


Compress a file:

gzip file   #(.gz format)
bzip2 file  #(.bz2 format, better)
lzma file   #(.lzma format, best compression)
xz file     #(.xz format, best for code)

Uncompress a file:

gunzip file.gz
bunzip2 file.bz2
unlzma file.lzma
unxz file.xz



Create a compressed archive (tape archive):
tar zcvf archive.tar.gz dir
tar jcvf archive.tar.bz2 dir
tar Jcvf archive.tar.xz dir
tar --lzma -cvf archive.tar.lzma

Test (list) a compressed archive:

tar tvf archive.tar.[gz|bz2|lzma|xz]

Extract the contents of a compressed archive:

tar xvf archive.tar.[gz|bz2|lzma|xz]

tar options:

c  #: create
t  #: test
x  #: extract
j  #: on the fly bzip2 (un)compression
J  #: on the fly xz (un)compression
z  #: on the fly gzip (un)compression

Handling zip archives:

zip -r    #(create)
unzip -t  #(test / list)
unzip     #(extract)


Send PostScript or text files to queue:

lpr -Pqueue f2.txt   #(local printer)

List all the print jobs in queue:

lpq -Pqueue

Cancel a print job number in queue:

cancel 123 queue

Print a PDF file:

pdf2ps doc.pdf

View a PostScript file:

xpdf doc.pdf


User management
List users logged on the system:


Show which user I am logged as:


Show which groups user belongs to:

groups user

Tell more information about user:

finger user

Switch to user hulk:

su - hulk

Switch to super user (root):

su -   #(switch user)
su     #(keep same directory and environment)


Time management
Wait for 60 seconds:

sleep 60

Show the current date:


Count the time taken by a command:

time find_charming_prince -cute -rich


Command help
Basic help (works for most commands):

grep --help

Access the full manual page of a command:

man grep


Misc commands
Basic command-line calculator:

bc -l


Basic system administration
Change the owner and group of a directory and
all its contents:

sudo chown -R newuser.newgroup dir

Reboot the machine in 5 minutes:

sudo shutdown -r +5

Shutdown the machine now:

sudo shutdown -h now

Display all available network interfaces:

ifconfig -a

Assign an IP address to a network interface:

sudo ifconfig eth0

Bring down a network interface:

sudo ifconfig eth0 down

Define a default gateway for packets to
machines outside the local network:

sudo route add default gw

Delete the default route:

sudo route del default

Test networking with another machine:


Create or remove partitions on the first IDE
hard disk:

fdisk /dev/hda1

Create (format) an ext3 filesystem:

mkfs.ext3 /dev/hda1

Create (format) a FAT32 filesystem:

mkfs.vfat -v -F 32 /dev/hda2

Mount a formatted partition:

mkdir /mnt/usbdisk  #(just do it once)
sudo mount /dev/uba1 /mnt/usbdisk

Mount a filesystem image (loop device):

sudo mount -o loop fs.img /mnt/fs

Unmount a filesystem:

sudo umount /mnt/usbdisk

Check the system kernel version:

uname -a

vi basic commands

[ vi basic commands ]

Summary of most useful commands

Download this PDF file.

©Copyright 2014-2005, Free Electrons, Latest update: Aug 11, 2015
Free to share under the terms of the Creative Commons Attribution-ShareAlike 3.0 license. Sources: http://git.freeelectrons.
com/training-materials. Updates: Thanks to: Liubo Chen.

Entering command mode
[Esc]     Exit editing mode. Keyboard keys now interpreted as commands.

Moving the cursor
h                   (or left arrow key) move the cursor left.
l                    (or right arrow key) move the cursor right.
j                    (or down arrow key) move the cursor down.
k                   (or up arrow key) move the cursor up.
[Ctrl]+f       move the cursor one page forward .
[Ctrl]+b      move the cursor one page backward.
^                   move cursor to the first non-white character in the current line.
$                   move the cursor to the end of the current line.
G                   go to the last line in the file.
nG                go to line number n.
[Ctrl]+G     display the name of the current file and the cursor position in it.

Entering editing mode
i                   insert new text before the cursor.
a                  append new text after the cursor.
o                  start to edit a new line after the current one.
O                  start to edit a new line before the current one.

Replacing characters, lines and words
r                  replace the current character (does not enter edit mode).
s                  enter edit mode and substitute the current character by several ones.
cw               enter edit mode and change the word after the cursor.
C                 enter edit mode and change the rest of the line after the cursor.

Copying and pasting
yy                copy (yank) the current line to the copy/paste buffer.
p                  paste the copy/paste buffer after the current line.
P                  Paste the copy/paste buffer before the current line.

Deleting characters, words and lines
All deleted characters, words and lines are copied to the copy/paste
x                 delete the character at the cursor location.
dw             delete the current word.
D               delete the remainder of the line after the cursor.
dd             delete the current line.

Repeating commands
.               repeat the last insertion, replacement or delete command.

Looking for strings
/               string find the first occurrence of string after the cursor.
?              string find the first occurrence of string before the cursor.
n             find the next occurrence in the last search.

Replacing strings
Can also be done manually, searching and replacing once, and then using
n                                   (next occurrence) and . (repeat last edit).
n,ps/str1/str2/g       between line numbers n and p, substitute all (g:
global) occurrences of str1 by str2.
1,$s/str1/str2/g        in the whole file ($: last line), substitute all
occurrences of str1 by str2.

Applying a command several times – Examples
5j                move the cursor 5 lines down.
30dd          delete 30 lines.
4cw            change 4 words from the cursor.
1G               go to the first line in the file.
[Ctrl]+l     redraw the screen.
J                   join the current line with the next one
u                 undo the last action

Exiting and saving
ZZ              save current file and exit vi.
:w               write (save) to the current file.
:w file       write (save) to the file file.
:q!              quit vi without saving changes.

Going further
vi has much more flexibility and many
more commands for power users!
It can make you extremely productive
in editing and creating text.
Learn more by taking the quick tutorial:
just type vimtutor.

Raspberry Pi Kernel-o-Matic

Raspberry Pi Kernel-o-Matic

Kreate Kustom Kernels Kwickly!


If you’re ever needed to compile the Linux Kernel on a Raspberry Pi, you’ve probably noticed that it takes a long time. We sure have.

If you have a desktop computer or a laptop with decent hardware specs, it seems like there ought to be an easy way to use all that processing power to generate a new kernel for your Pi, but it can be tricky to figure out the specifics. Enter theAdafruit Pi Kernel-o-Matic, which uses Vagrant to run a virtual machine pre-configured for compiling kernels and produces a package suitable for installation on a Raspbian machine.

Vagrant is for “creating and configuring virtual development environments”.  What does that mean?  Well, really, it’s a simple way to set up a virtual machine (VM) running an operating system of your choice. It uses VirtualBox to run VMs, and works on OS X, Windows, and Linux.

Getting a new kernel can be (almost!) as simple as:


  1. cd AdafruitPiKerneloMatic
  2. vagrant up
  3. vagrant ssh
  4. sudo adabuild

Interested? You’ll just need to install a bit of software. Read on for specifics.

What is this “Linux”, anyhow?




EDITOR’S NOTE: Hiya, Lady Ada here to introduce this tutorial! If you’re starting down the path to learning about electronics or computers, you may have noticed or heard about “Linux” – as in “this dev board is linux-based” or “this wearable runs linux” or “I wrote a linux script to control the barcode scanner”

And you might be wondering Well, what is this “Linux” anyhow? Does it matter to me?  and then maybe you asked someone and you got a long rant about stuff called kernels and bashed shells and now you’re wondering if it’s corn-related or is some sort of crab.

Being that this question and confusion is inevitable, and we’re getting so many people asking about this mysterious Linux, we at Adafruit thought we’d write up a series of tutorials to help you understand what linux iswhen you want linux and how to use it when you do.

This is the first in the series, take it away Brennen!