Linux is a kernel and often a misnomer for an operating system that makes the life of engineers signifcantly easier.

The Relevance of Linux The foundation of OSS

Linux plays a significant role in OSS. That’s not to say that it is the only show in town–in fact, FreeBSD may have been even more pivotal in OSS. Linux seems to have merely led to wider-spread adoption.

Many of the utilities in the OSS world were designed on and/or for Linux or FreeBSD. These utilities include LibreNMS, Cacti, RANCID, TACACS+, and many more.

In addition, it hosts tools such as perl, sed, grep, and many others that can make filtering through information much easier. Languages such as Python and Perl make writing administrative scripts that automate changes or collect information a breeze.

Crash Course The way of the terminal

The terminal will be your friend. This article isn’t here to teach you the history of Linux or how to use ssh. I assume that you know how to SSH to a Linux server or how to open a terminal if you have GUI access to a Linux system.

If you’re using Ubuntu 12.04 (and presumably later and possibly earlier), you can press ctrl+alt+T to open a terminal

Now that you have your terminal open, here are a few commands that will help you out on your journey to becoming an OSS ninja.

Before we begin, you should know that a single “dot” or “period” (.) symbolically represents the current directory you are in, while two consecutive “dots” or “periods” (..) represents the parent directory, or the directory above your current directory.

A term in angled brackets (< and >) is optional. A term in square brackets ([ and ]) is mandatory.

ls list files

Format:

ls <options> <directory>

Options begin with a hyphen (-).

Example:

[email protected]:/opt$ ls
oss-conf  tac_plus  vagrant_ruby  VBoxGuestAdditions-4.2.0
[email protected]:/opt$ ls /
bin   dev  home        lib         media  opt   root  sbin     srv  tmp
vagrant  vmlinuz
boot  etc  initrd.img  lost+found  mnt    proc  run   selinux  sys  usr
var
[email protected]:/opt$ ls -R tac_plus/
tac_plus/:
bin  etc  include  lib  share

tac_plus/bin:
tac_plus  tac_pwd

tac_plus/etc:
tac_plus.conf

tac_plus/include:
tacacs.h

tac_plus/lib:
libtacacs.a  libtacacs.la  libtacacs.so  libtacacs.so.1
libtacacs.so.1.0.0

tac_plus/share:
man  tacacs+

tac_plus/share/man:
man5  man8

tac_plus/share/man/man5:
tac_plus.conf.5

tac_plus/share/man/man8:
tac_plus.8  tac_pwd.8

tac_plus/share/tacacs+:
do_auth.py  tac_convert  users_guide
[email protected]:/opt$

If you don’t specify a directory, the default is to list the contents of the current working directory (commonly represented as a single dot .).

cd change directory

Format:

cd <options> <destination>

Examples:

[email protected]:/opt$ cd
[email protected]:~$ cd /opt
[email protected]:/opt$ cd
[email protected]:~$ cd ..
[email protected]:/home$ cd ~
[email protected]:~$

The tilde (~) is a shortcut meaning “home directory”. The cd command by itself with no arguments changes to your home directory. The two dots (..) represents the parent directory.

cp copy

Format:

cp <options> [source] [destination]

Examples:

[email protected]:~$ ls
postinstall.sh  test
[email protected]:~$ cp /opt/tac_plus/etc/tac_plus.conf .
[email protected]:~$ ls
postinstall.sh  tac_plus.conf  test
[email protected]:~$ ls /opt
oss-conf  tac_plus  test  vagrant_ruby  VBoxGuestAdditions-4.2.0
[email protected]:~$ cp test /opt
[email protected]:~$ ls /opt
oss-conf  tac_plus  test  vagrant_ruby  VBoxGuestAdditions-4.2.0
[email protected]:~$ cp -R /opt/tac_plus/ .
[email protected]:~$ ls
postinstall.sh  tac_plus  tac_plus.conf  test
[email protected]:~$ ls -R tac_plus
tac_plus:
bin  etc  include  lib  share

tac_plus/bin:
tac_plus  tac_pwd

tac_plus/etc:
tac_plus.conf

tac_plus/include:
tacacs.h

tac_plus/lib:
libtacacs.a  libtacacs.la  libtacacs.so  libtacacs.so.1
libtacacs.so.1.0.0

tac_plus/share:
man  tacacs+

tac_plus/share/man:
man5  man8

tac_plus/share/man/man5:
tac_plus.conf.5

tac_plus/share/man/man8:
tac_plus.8  tac_pwd.8

tac_plus/share/tacacs+:
do_auth.py  tac_convert  users_guide
[email protected]:~$

The ls command is used to show contents before and after a cp command. The -R flag on the cp command means “recursive” and is necessary to copy entire folders.

mv move

Format:

mv <options> [source] [destination]

Examples:

[email protected]:~$ ls /tmp/
[email protected]:~$ mv test /tmp/
[email protected]:~$ mv tac_plus/ /tmp/
[email protected]:~$ ls /tmp
tac_plus  test
[email protected]:~$ ls
postinstall.sh  tac_plus.conf
[email protected]:~$

The mv command is very similar to the cp command, except that it does not require a recursive option to move folders, and when the file is moved, it no longer exists at the source location.

rm remove

Format:

rm <options> [file|directory] ...

Examples:

[email protected]:~$ ls /tmp
tac_plus.conf  test  test2  test3  test4
[email protected]:~$ rm /tmp/tac_plus.conf
[email protected]:~$ ls /tmp
test  test2  test3  test4
[email protected]:~$ rm /tmp/test /tmp/test2
[email protected]:~$ ls /tmp
test3  test4
[email protected]:~$ rm /tmp/*
[email protected]:~$ ls /tmp
[email protected]:~$
[email protected]:~$ ls -R /tmp/
/tmp/:
test

/tmp/test:
happy  hello  sample

/tmp/test/sample:
goodbye  sad
[email protected]:~$ rm -r /tmp/test/
[email protected]:~$ ls -R /tmp/
/tmp/:
[email protected]:~$

The ls command is used to illustrate the effects of the rm command. The -r flag means recursive. You can specify single files, multiple files, directories (but must specify the -r flag), or wildcards (*).

rmdir remove directory

Format:

rmdir <options> [directory] ...

Examples:

[email protected]:~$ ls -R /tmp
/tmp:
test

/tmp/test:
hello

/tmp/test/hello:
goodbye

/tmp/test/hello/goodbye:
friends

/tmp/test/hello/goodbye/friends:
[email protected]:~$ rmdir /tmp/test/hello/goodbye/friends/
[email protected]:~$ ls -R /tmp/
/tmp/:
test

/tmp/test:
hello

/tmp/test/hello:
goodbye

/tmp/test/hello/goodbye:
[email protected]:~$ rmdir -p /tmp/test/hello/goodbye/
rmdir: failed to remove directory '/tmp': Permission denied
[email protected]:~$ ls -R /tmp
/tmp:
[email protected]:~$

Be careful of the “parents” options (-p). You can easily delete directories by mistake.

mkdir make directory

Format:

mkdir <options> [directory] ...

Examples:

[email protected]:~$ ls /tmp
[email protected]:~$ mkdir /tmp/test
[email protected]:~$ ls /tmp
test
[email protected]:~$ mkdir -p /tmp/test/hello/friend/nice/to/meet/you
[email protected]:~$ ls -R /tmp
/tmp:
test

/tmp/test:
hello

/tmp/test/hello:
friend

/tmp/test/hello/friend:
nice

/tmp/test/hello/friend/nice:
to

/tmp/test/hello/friend/nice/to:
meet

/tmp/test/hello/friend/nice/to/meet:
you

/tmp/test/hello/friend/nice/to/meet/you:
[email protected]:~$ mkdir /tmp/sad /tmp/happy
[email protected]:~$ ls -R /tmp
/tmp:
happy  sad  test

/tmp/happy:

/tmp/sad:

/tmp/test:
hello

/tmp/test/hello:
friend

/tmp/test/hello/friend:
nice

/tmp/test/hello/friend/nice:
to

/tmp/test/hello/friend/nice/to:
meet

/tmp/test/hello/friend/nice/to/meet:
you

/tmp/test/hello/friend/nice/to/meet/you:
[email protected]:~$

pwd present working directory

Format:

pwd

Examples:

[email protected]:~$ pwd
/home/vagrant
[email protected]:~$

sudo super-user do

sudo doesn’t actually mean “super-user do”. It means “su do”, but “super-user do” is frequently easier to remember when you’re starting out.

Format:

sudo [command]

Example:

[email protected]:~$ cd /usr
[email protected]:/usr$ ls
bin  games  include  lib  local  sbin  share  src
[email protected]:/usr$ touch test
touch: cannot touch 'test': Permission denied
[email protected]:/usr$ sudo touch test
[email protected]:/usr$ ls
bin  games  include  lib  local  sbin  share  src  test
[email protected]:/usr$ ls -l test
-rw-r--r-- 1 root root 0 Jan 19 01:49 test
[email protected]:/usr$ whoami
vagrant
[email protected]:/usr$

sudo is useful to run commands that require root privileges. It can also be configured such that a user can perform certain actions with elevated privileges but not all.

The above example uses numerous commands you’ve learned so far to help identify the effects of sudo. The -l option for ls is for “long”, which shows the user and group who owns the file. In this case, it is owned by the “root” user and group, even though you are “vagrant” (or whatever users you happen to be) as identified by the whoami command.

This shows one of the “gotchas” of sudo: it creates files as the root user.

curl client url request library

Format:

curl <options> [target] ...

Examples:

[email protected]:~$ ls
postinstall.sh
[email protected]:~$ curl -O
http://serpentorslair.com/wp-content/uploads/2013/10/darth-vader-16086-1680x1050.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time   Current
                                 Dload  Upload   Total   Spent    Left   Speed
100  397k  100  397k    0     0   305k      0  0:00:01  0:00:01 --:--:-- 493k
[email protected]:~$ ls
darth-vader-16086-1680x1050.jpg  postinstall.sh
[email protected]:~$ curl -o vader.jpg
http://serpentorslair.com/wp-content/uploads/2013/10/darth-vader-16086-1680x1050.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time   Current
                                 Dload  Upload   Total   Spent    Left   Speed
100  397k  100  397k    0     0   276k      0  0:00:01  0:00:01 --:--:-- 484k
[email protected]:~$ ls
darth-vader-16086-1680x1050.jpg  postinstall.sh  vader.jpg
[email protected]:~$

tar tape archive

Format:

tar <options> [archive] <files|directories> ...

Examples:

[email protected]:~$ ls
hello  test1  test3  world
[email protected]:~$ tar -czvf
.bash_history              hello                      test1
.viminfo
.bash_logout               .profile                   test3
world
.bashrc                    .ssh/                      .vbox_version
.cache/                    .sudo_as_admin_successful  .veewee_version
[email protected]:~$ tar -czvf home_dir.tar.gz test1 hello test3 world
test1
hello
test3
world
[email protected]:~$ ls
hello  home_dir.tar.gz  test1  test3  world
[email protected]:~$ rm hello test1 test3 world
[email protected]:~$ ls
home_dir.tar.gz
[email protected]:~$ tar -tzvf home_dir.tar.gz
-rw-rw-r-- vagrant/vagrant   0 2014-01-19 02:26 test1
-rw-rw-r-- vagrant/vagrant   0 2014-01-19 02:26 hello
-rw-rw-r-- vagrant/vagrant   0 2014-01-19 02:26 test3
-rw-rw-r-- vagrant/vagrant   0 2014-01-19 02:26 world
[email protected]:~$ ls
home_dir.tar.gz
[email protected]:~$ tar -xzvf home_dir.tar.gz
test1
hello
test3
world
[email protected]:~$ ls
hello  home_dir.tar.gz  test1  test3  world
[email protected]:~$

tar has a number of important options. The “verbose” (-v) flag prints output to your screen, the “file” (-f) tells tar which file, and the “gzip” (-z) tells tar to use “gzip” compression.

There are three action flags used as well. They are:

create” (-c): create the archive

extract” (-x): extract the archive

list” (-t): list the contents of the archive

vim Editing Files

vim is a power text-editing utility that can be difficult to master. Using it for basic purposes, though, is easy. Here’s a short list of commands:

vim is a great tool, but it is difficult to show in a text-based tutorial how it’s used (irony, huh?). I strongly recommend VIM Adventures to learn how to use vim properly.

The End

This was only a crash course on the very bare necessities you must understand to use Linux. More advanced tools, such as sed, awk, perl, cut, and more require entire posts to explain properly.

This will get you on your way. Look for future articles in the “Crash Course” series.