Linux Introduction Binder PDF
Linux Introduction Binder PDF
Linux: an introduction
A cheat sheet approach
1 Introduction ............................................................................................................. 5
Some warning on the linux command line interface ...................................... 5
2 Linux......................................................................................................................... 6
2.1 Kernel ............................................................................................................. 6
2.2 Shell ................................................................................................................ 6
2.3 Linux command .............................................................................................. 6
3 Getting help ............................................................................................................. 8
4 Working with files and directories ........................................................................ 9
4.1 The file system................................................................................................ 9
4.2 ls command ................................................................................................. 10
4.3 Navigating the file system ............................................................................. 13
4.3.1 Working with directories ..................................................................... 13
4.4 Viewing file content ....................................................................................... 14
4.4.1 Viewing commands ............................................................................ 14
4.4.2 Less command ................................................................................... 15
4.5 File manipulation........................................................................................... 15
4.6 Search files ................................................................................................... 16
4.7 Archiving and compressing files ................................................................... 17
4.8 Check disk space.......................................................................................... 19
4.9 Links ............................................................................................................. 19
5 The shell revisited ................................................................................................. 20
5.1 Various commands ....................................................................................... 20
5.2 Bash shortcuts .............................................................................................. 21
5.3 Bash variables .............................................................................................. 21
5.4 IO Redirection ............................................................................................... 22
5.5 Pipes ............................................................................................................. 22
Command lists .............................................................................................. 23
6 Text editing ............................................................................................................ 24
6.1 Nano Quick Reference ................................................................................. 24
7 File security ........................................................................................................... 26
7.1 File Permissions ........................................................................................... 27
8 Process Management ........................................................................................... 28
9 Useful links ............................................................................................................ 30
CONTENT | 3
1 Introduction
• The command line interface is case-sensitive, one wrongly typed character can
cause a lot of problems.
• There is no Recycle Bin, anything that you execute (run) in the command prompt
would need to be fixed manually. Double Check EVERY command that you type, to
make sure it is correct. The command line is a very powerful tool, and it requires a
little more finesse and learning than the GUI (Graphic User Interface).
INTRODUCTION | 5
2 Linux
The Linux operating system is not a monolithic block fixed once and for all. In reality,
many components work together, written by different people and assembled into
distributions. It is only from the outside that the Linux kernel appears to be an indivisible
unit. However, the distributions all have the same operating system kernel, and many
common applications.
2.1 Kernel
The kernel is the part of the code in memory. The kernel takes care of :
2.2 Shell
The shell is the most basic link between the user and the operating system. The
commands entered on the command line will be interpreted by the shell and passed on to
the operating system. There are several versions of the shell:
• bash This is the standard Linux shell the Bourne Again Shell.
• sh The original Bourne shell.
• csh The C shell uses a different programming interface to bash.
• ksh The Korn shell is one of the most popular shells on Unix. It is compatible with
bash .
• tcsh The enhanced C shell.
• zsh A bash compatible shell.
6 | LINUX
The anatomy of a command line interface is as follows:
A Linux command consists of 3 parts: the command itself, the command options, and its
arguments.
command [OPTIONS prefixed with – or --] [ARG1] […ARGX]
LINUX | 7
3 Getting help
Source: https://www.howtogeek.com/108890/how-to-get-help-with-a-command-from-the-
linux-terminal-8-tricks-for-beginners-pros-alike/
8 | GETTING HELP
4 Working with files and directories
Source: http://linuxsuperuser07.blogspot.be/2011/09/rhel-6-file-system.html
directory
/ The root directory contains all subdirectories.
/boot When the system boots, the boot program will
examine the /boot. Among the objects it looks
for is the map file, by which the Linux boot
manager will determine the location of the
kernel on the hard disk.
/bin The binaries directory contains the most
important commands.
/dev The device directory contains device files
through which you communicate with the
devices connected to the computer.
/etc Only the configuration files should be there:
passwd, group, hosts, etc.
/home The users home directory will often be under
the /home/yourname directory.The advantage
of this is that the user will have their own file
system.
/lib Directory for shared libraries.
4.2 ls command
Source: https://cheatography.com/davechild/cheat-sheets/linux-command-line/
Tip:
• use wildcards
source: https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm
A path is a sequence of nested directories with a file or directory at the end, separated by
the / character
/ : root directory.
Start of absolute paths for all files on the system
. Current directory
.. Parent directory
~ Home directory
/ Root directory
Changes the
current position to
the specified
directory
cd .. Go up one level
(parent)
cd - Switch between
current dir and
previous dir
Source: https://linuxize.com/post/less-command-in-linux/
q Exit less
or multiple sources
to directory
-r
Tar stands for tape archive, the archive itself is a single file that can represent many files.
tar files do not have to be compressed but they often are, even a not zipped tar file will
often use less disk space than the files stored individually.
-x extract an archive.
The files will
expand within the
current directory.
-k prevents existing
files being
overwritten.
Recipes:
tip:
the content of a tar file may be read directly with less , without extracting the file.
4.9 Links
Source: https://ostechnix.com/explaining-soft-link-and-hard-link-in-linux-with-examples/
A symbolic or soft link is an actual link to the original file (similar to a shortcut in
Windows), whereas a hard link is a mirror copy of the original file.
If you delete the original file, the soft link will be useless since it points to a non-existent
file, the hard link will still have the data of the original file because it acts as a mirror copy
of the original file.
Tip:
what is the difference between Hard link and the normal copied file?
• If you copy a file, it will just duplicate the content. So if you modify the content of
a one file (either original or hard link), it has no effect on the other one.
• However if you create a hard link to a file and change the content of either of the
files, the change will be seen on both.
Source: https://cheatography.com/davechild/cheat-sheets/linux-command-line/
history |
tail
Source: https://cheatography.com/davechild/cheat-sheets/linux-command-line/
!! Repeat last
command
Source: https://www.digitalocean.com/community/tutorials/how-to-read-and-set-
environmental-and-shell-variables-on-linux
5.4 IO Redirection
Source: https://www.howtogeek.com/435903/what-are-stdin-stdout-and-stderr-on-linux/
The > redirection symbol works with stdout by default. You can use one of the numeric
file descriptors to indicate which standard output stream you wish to redirect.
5.5 Pipes
Command lists
Nano is very much like ‘Notepad’ but without mouse support. All commands are executed
through the use of the keyboard, using the Ctrl-key.
• Ctrl+X Exit the editor. If you’ve edited text without saving, you’ll be prompted as to
whether you really want to exit.
• Ctrl+O Write (output) the current contents of the text buffer to a file. A filename prompt
will appear; press Ctrl+T to open the file navigator shown above.
• Ctrl+R Read a text file into the current editing session. At the filename prompt, hit
Ctrl+T for the file navigator.
• Ctrl+K Cut a line into the clipboard. You can press this repeatedly to copy multiple
lines, which are then stored as one chunk.
• Ctrl+J Justify (fill out) a paragraph of text. By default, this reflows text to match the
width of the editing window.
• Ctrl+U Uncut text, or rather, paste it from the clipboard. Note that after a Justify
operation, this turns into unjustify.
• Ctrl+T Check spelling.
• Ctrl+W Find a word or phrase. At the prompt, use the cursor keys to go through
previous search terms, or hit Ctrl+R to move into replace mode. Alternatively you can
hit Ctrl+T to go to a specific line.
Manual: https://www.nano-editor.org/dist/v4/nano.pdf
• Linux is a multiuser system, the files of all users are stored in a single file
structure
• Mechanism is required to restrict one user to access the files of another user.
User can impose access permission to each file to restrict its access
4 read (r)
2 write (w)
1 execute (x)
• symbolic format
o action: r (read), w (write), x (execute
o u (user), g (group), o (other), a (all)
Processes
Source: https://linuxjourney.com/lesson/process-states
in the STAT column, you'll see lots of values. A linux process can be in a number of
different states. The most common state codes you'll see are described below:
• S: Interruptible sleep, waiting for an event to complete, such as input from the
terminal
f = forest view