Starting with Linux
Feilke Tobias
Table of Content
Linux?
File Structure
Users & Groups
Commands / Tools
Combining Commands
Linux Training Page 2
Linux?
Linux is an Operating System
Linux is based on Unix
Linux is Open Source
Linux is available in a lot of different Distributions
Linux Training Page 3
Linux?
Some facts:
Linux exists since April 1994 (Version 1.0)
Developed by Linus Torvalds, a Finnish computer science
student
Linux is free available, can an should be copied
Worldwide hundreds of volunteer developpers
Linux Training Page 4
File Structure
There are only files on a Linux System
All devices are represented through files
Folders are files
All files can be mounted to every place in the System
Mounting doesnt depend on the physical location
The File system of one Linux machine can consist of
several devices and Computers
Linux Training Page 5
File Structure
Filenames are not limited by length
should be avoided
Special characters are not allowed up to a few exceptions
Files dont need special file extentions
Standard naming conventions should still be maintained
.c for C-Files
.cpp for C++ Files
.log for Logfiles
Linux Training Page 6
File Structure
Comparable to a Tree
etc/ dev/ mnt/ bin/ sbin/ usr/ home/
init.d/ X11/ passwd mkdir ls lib/ man/
shutdown halt sdd/ cwp/
Linux Training Page 7
Users & Groups
All users have an ID (UID)
User ID
All groups have an ID (GID)
Group ID
All users belong to at least one group
The initial group for all users is: users
All users can belong to more than one group
Linux Training Page 8
Users & Groups
User: root
Classification: Absolut System Administrator
Has control of all data
Has control of all processes
He is not subject of any restrictions
Has the group root
Linux Training Page 9
Users & Groups
User: default user
Classification: restricted user
Has control of his personal data
Has control of his processes
Has defined rights
Has a group
Linux Training Page 10
Short Break
Tea
Coffee
Linux Training Page 11
Commands
cd (change directory)
Changes your working folder
Examples:
cd /home/sdd/ change to folder sdd
cd .. change to upper directory
cd tools change to tools in lokal folder
cd - change to last folder
cd change to home folder
Linux Training Page 12
Commands
pwd (print working directory)
Shows local working folder
Example:
pwd
-> /home/sdd
Linux Training Page 13
Commands
ls (list)
Shows content of local folder
Parameter:
ls l shows file information (long)
ls a shows all files (even hidden/all)
ls al shows all files and information (all, long)
ls altr shows all files arranged by access time
ls lisa long, Inode, size, all
ls pr* shows all files starting with pr
Linux Training Page 14
Commands
mkdir (make Directory)
Creates a driectory
Example:
mkdir /home/sdd/pictures
Creates the directory pictures in folder /home/sdd
mkdir -p /Shortlog/SDD
Creates the directory Shortlog and in Shortlog, the folder
SDD
Linux Training Page 15
Commands
rm (remove)
Deleting files
rmdir (remove directory)
Deleting folders
Example:
rm SimpleFile delete Simplefile in local folder
rm Sim* delete all files in local folder
starting with Sim
rmdir SimpleDir delete directory Simpledir in local
folder
Linux Training Page 16
Commands
cp (copy)
Copy a file or folder
Example:
cp .bashrc mycopy creates a copy of .bashrc named
mycopy
cp -r <File> <Target> copy recursive
cp -rv <File> <Target> copy recursive and show log
Linux Training Page 17
Commands
mv (move)
Moves a file or folder
Example:
mv test /home move file test to /home
mv data/ incoming/ move local folder data to
local folder incoming
mv progA backup rename progA to backup
Linux Training Page 18
Commands
grep (Search content)
Searches in files for specific content.
Usage Example:
grep <text> <path>
grep -r date /log/* Searches for date in
folder log and its
subfolders
Linux Training Page 19
Commands
find (find)
Search for a specific file
Usage:
find <path> -name <filename>
Example:
find / -name services.cfg Searches for the file
services.cfg starting in the
base folder /.
Linux Training Page 20
Commands
chmod (change mode)
Change a files permissions
Usage:
chmod <parameters> <filename>
Example:
chmod 777 executeme.sh Changes the file
permissions, with 777
everyone can read write
and execute the file.
Linux Training Page 21
Commands
chgrp (change group)
Change the owner group of a file.
Usage:
chgrp <new group> <filename>
Example:
chgrp sdd log.txt Change the ownergroup of file
log.txt to sdd.
Linux Training Page 22
Commands
chown (change owner)
Change the owner of a file.
Usage:
chown <new owner> <filename>
Example:
chown sdd log.txt Change the owner of file
log.txt to sdd.
Linux Training Page 23
Commands
df ()
Display the amount of disk space available on the filesystem
containing each file name in the agrument.
Usage:
df <option> <filename>
Example:
df Displays the available space on all currently
mounted filesystems.
Linux Training Page 24
Commands
init (parent process)
Set a new runlevel.
Init 0 Reboot the system
Init S Single-User-Runlevel (Maintenance)
Init 1 Single-User-Runlevel minimal recourses
Init 2 Multi-User-Runlevel minimal recourses
Init 3 Multi-User-Runlevel without Xserver
Init 4 not defined
Init 5 Multi-User-Runlevel (normal)
Init 6 Reboot
Linux Training Page 25
Commands
mount ()
Make a storage device available to your system.
Usage:
mount <device> <mountpoint>
Example:
mount /dev/sdb1 /tmp/usb
Makes the storage device sdb1 available at the folder
/tmp/usb. For example a usb pendrive.
Linux Training Page 26
Commands
umount ()
Release a mount. Write changes to device.
Usage:
umount <mountpoint>
Example:
umount /tmp/usb
Release the mount of /tmp/usb. Now the device could be
removed secure.
Linux Training Page 27
Tools
vi (editor)
Simple editor available on all unix based distributions
Usage:
vi <file to edit> Open a file
Commands:
i Enter edit mode ESC to leave
:wq Save and exit
:q! Quit without saving
u Undo last action
/<txt> Searches in file for txt
Linux Training Page 28
Tools
less (reader)
Display content of a file
Usage:
less <file to view> Displays the file
Commands:
/<txt> Search and highlights txt
Arrowkeys to navigate
q Leave file
Linux Training Page 29
Tools
cat (print on std out)
Echos the filecontent
Usage:
Cat <file to view> Echos the file
Linux Training Page 30
Combining Commands
find /home/feilket/Lesson/* -name hosts.cfg
Searches all files named hosts.cfg in /home/feilket/Lessons
find /home/feilket/Lesson/* -name hosts.cfg |grep
nagios
Searches all files named hosts.cfg in /home/feilket/Lessons
and displays only files where nagios is contained in the path
The output from the first commant was is passed to the
second command as input
Linux Training Page 31
Combining Commands
cat $(find /home/feilket/Lesson/* -name hosts.cfg |
grep nagios)
The result of our search is now used as parameter for cat.
These hands the same result as these two commands:
cat /home/feilket/Lessons/CNMS/nagios/srv/hosts.cfg
cat /home/feilket/Lessons/CNMS/nagios/ws/hosts.cfg
Linux Training Page 32
Combining Commands
cat $(find /home/feilket/Lesson/* -name hosts.cfg |
grep nagios) | grep host_name
Now we used the filtered result of our search command to
display the files and afterwards we filtered the output from
cat
Linux Training Page 33
Combining Commands
cat $(find /home/feilket/Lesson/* -name hosts.cfg |
grep nagios) | grep host_name >> hostnames.txt
The entire result of our commands is now redirected to a
file.
>> leads output to a file appending
> leads output to a file overwriting
Linux Training Page 34
Training
Task 1
Go to the home directory.
Task 2
Create a textfile.
Task 3
Copy textfile to the desktop.
Task 4
Create a directory on the desktop.
Task 5
Move the textfile from the desktop to the new folder.
Task 6
Delete the file and the new Folder.
Linux Training Page 35
Training
Task 1
Find the file hosts.
Task 2
Get information about the file.
Task 3
List all files starting with z in the /sbin folder.
Task 4
Find the file which contains HelloWorld
Task 5
Copy the HelloWorld file to a usb pendrive.
Task 6
Output only the line containing the word solution from a
file named findme.txt on your local system.
Linux Training Page 36