You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
7.8 KiB

5 years ago
= An Introduction to Linux !
Apostolos rootApostolos@swarmlab.io
// Metadata:
:description: Intro and Install
:keywords: Linux, apt
:data-uri:
:toc: right
:toc-title: Πίνακας περιεχομένων
:toclevels: 4
:source-highlighter: highlight
:icons: font
:sectnums:
include::header.adoc[]
{empty} +
[[cheat-Docker]]
== Install swarmlab-ls (Home PC)
HowTo: See http://docs.swarmlab.io/lab/sec/sec.adoc.html
.NOTE
[NOTE]
====
Assuming you're already logged in
====
== Absolute basics
.Absolute basics
[options="header,footer"]
|=======================
|Command| Meaning
|ls| Displays a list of files in the current working directory, like the dir command in DOS
|cd directory| change directories
|passwd |change the password for the current user
|file filename| display file type of file with name filename
|cat textfile| throws content of textfile on the screen
|pwd| display present working directory
|exit or logout| leave this session
|man command| read man pages on command
|=======================
5 years ago
=== Key combinations
5 years ago
.Key combinations
[options="header,footer"]
|=======================
|Key or key combination| Function
|Ctrl+C| End a running program and return the prompt
|Ctrl+Z| Suspend a program
|ArrowUp and ArrowDown| Browse history. Go to the line that you want to repeat, edit details if necessary, and press Enter to save time.
|Tab| Command or filename completion; when multiple choices are possible, the system will either signal with an audio or visual bell, or, if too many choices are possible, ask you if you want to see them all.
|Tab Tab| Shows file or command completion possibilities.
|Shift+PageUp and Shift+PageDown| Browse terminal buffer (to see text that has "scrolled off" the screen).
|=======================
5 years ago
=== ls -l
5 years ago
[source,bash]
----
5 years ago
# ls -al
drwxrwxr-x 4 zeus zeus 4096 Οκτ 23 21:55 .
drwxrwxr-x 9 zeus zeus 4096 Οκτ 15 14:28 ..
drwxrwxr-x 8 zeus zeus 4096 Οκτ 23 21:55 .git
drwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install
crw------- 1 root root 5, 1 Οκτ 23 21:22 console
lrwxrwxrwx 1 root root 11 Οκτ 23 21:21 core -> /proc/kcore
drwxr-xr-x 4 root root 100 Οκτ 23 21:22 cpu
crw------- 1 root root 10, 59 Οκτ 23 21:21 cpu_dma_latency
crw------- 1 root root 10, 203 Οκτ 23 21:21 cuse
-rw-rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md
-rw-rw-r-- 1 zeus zeus 33883 Οκτ 15 14:28 LICENSE
-rw-rw-r-- 1 zeus zeus 691 Οκτ 17 11:13 README.md
5 years ago
----
5 years ago
==== File types
5 years ago
5 years ago
This table gives an overview of the characters determining the file type:
5 years ago
5 years ago
NOTE: **d**rwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install
5 years ago
5 years ago
.File types in a long list
[options="header,footer"]
|=======================
|Symbol| Meaning
|-| Regular file
|d| Directory
|l| Link
|c| Special file
|s| Socket
|p| Named pipe
|b| Block device
|=======================
5 years ago
5 years ago
NOTE: -**rw-**rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md
5 years ago
5 years ago
==== Access rights
5 years ago
5 years ago
.Access rights
[options="header,footer"]
|=======================
|Code| Meaning
|0 or -|The access right that is supposed to be on this place is not granted.
|4 or r|read access is granted to the user category defined in this place
|2 or w|write permission is granted to the user category defined in this place
|1 or x|execute permission is granted to the user category defined in this place
|=======================
5 years ago
5 years ago
==== User group codes
5 years ago
5 years ago
.User group codes
[options="header,footer"]
|=======================
|Code| Meaning|
|u| user permissions|-**rw-**rw-r--
5 years ago
|g| group permissions|-rw-**rw-**r--
5 years ago
|o| permissions for others|-rw-rw-**r--**
|=======================
5 years ago
5 years ago
==== Exercises
5 years ago
[source,bash]
----
5 years ago
touch example
chmod 400 example
ls -l example
chmod 500 example
ls -l example
chmod 600 example
ls -l example
chmod 644 example
ls -l example
chmod 660 example
ls -l example
chmod 700 example
ls -l example
chmod 755 example
ls -l example
chmod 775 example
ls -l example
ls -l example
chmod 777 example
ls -l example
5 years ago
----
5 years ago
== Linux file system layout
5 years ago
5 years ago
.Subdirectories of the root directory
[options="header,footer"]
|=======================
|Directory| Content
|/bin| Common programs, shared by the system, the system administrator and the users.
|/boot| The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
|/dev| Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
|/etc| Most important system configuration files are in /etc
|/home| Home directories of the common users.
|/lib| Library files, includes files for all kinds of programs needed by the system and the users.
|/mnt| Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
|/opt| Typically contains extra and third party software.
|/proc| A virtual file system containing information about system resources.
|/root| The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
|/sbin| Programs for use by the system and the system administrator.
|/tmp| Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
|/usr| Programs, libraries, documentation etc. for all user-related programs.
|/var| Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.
|=======================
5 years ago
5 years ago
== Find and grep
=== find
The find tool, known from UNIX, is very powerful. This command not only allows you to search file names, it can also accept file size, date of last change and other file properties as criteria for a search.
The most common use is for finding file names:
NOTE: find <path> -name <searchstring>
This can be interpreted as "Look in all files and subdirectories contained in a given path, and print the names of the files containing the search string in their name" **(not in their content).**
[source,bash]
----
find /etc -name "*.conf"
----
=== grep
grep is used for filtering input lines and returning certain patterns to the output.
NOTE: grep "string" path/to/file
[source,bash]
----
grep "root" /etc/passwd
----
=== find and grep command together
find . -name "*.conf" -exec grep -Hns "conf" {} \;
.Explanation
[source,bash]
----
-H, --with-filename
Print the filename for each match
-n, --line-number
Prefix each line of output with the 1-based line number within its input file
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
----
5 years ago
5 years ago
== Find IP
5 years ago
[source,bash]
----
5 years ago
# ifconfig
5 years ago
5 years ago
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.21.0.2 netmask 255.255.0.0 broadcast 172.21.255.255
ether 02:42:ac:15:00:02 txqueuelen 0 (Ethernet)
RX packets 61 bytes 9309 (9.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
5 years ago
5 years ago
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 248 bytes 14260 (14.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 248 bytes 14260 (14.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
----
5 years ago
5 years ago
TIP: inet ***172.21.0.2*** netmask 255.255.0.0 broadcast 172.21.255.255
5 years ago
:hardbreaks:
{empty} +
{empty} +
{empty}
:!hardbreaks:
'''
.Reminder
[NOTE]
====
:hardbreaks:
Caminante, no hay camino,
se hace camino al andar.
Wanderer, there is no path,
the path is made by walking.
*Antonio Machado* Campos de Castilla
====