= 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. |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 |======================= === Key combinations .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). |======================= === ls -l [source,bash] ---- # 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 ---- ==== File types This table gives an overview of the characters determining the file type: NOTE: **d**rwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install .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 |======================= NOTE: -**rw-**rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md ==== Access rights .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 |======================= ==== User group codes .User group codes [options="header,footer"] |======================= |Code| Meaning| |u| user permissions|-**rw-**rw-r-- |g| group permissions|-rw-**rw-**r-- |o| permissions for others|-rw-rw-**rw-** |======================= ==== Exercises [source,bash] ---- 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 ---- == Linux file system layout .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. |======================= == 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 -name 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 /etc -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. ---- NOTE: This can be interpreted as + - "Look for *.conf files and subdirectories contained in /etc, and **if true** exec **grep -Hns conf** in the given file" TIP: Very powerful in bash scripts create a file test.sh .bash script [source,bash] ---- #!/bin/bash STRING=$(find /etc -name "*.conf" -exec grep -Hns "conf" {} \;) echo $STRING ---- exec it .bash script [source,bash] ---- chmod 700 test.sh ./test.sh ---- == Managing software === APT WHAT IS APT? A packaging system simply provides programs and applications for installation. APT(Advanced Package Tool) is a command line tool that is the most efficient and preferred way of managing software from the command line for Debian and Debian based Linux distributions like Ubuntu . It manages dependencies effectively, maintains large configuration files and properly handles upgrades and downgrades to ensure system stability. ==== Updating Package Database Before commencing any operations with apt, we need to ensure that our local copy of the database is up-to-date. Without this the system won’t know if there are newer packages available or not. [source,bash] ---- apt-get update ---- ==== Upgrading Package Database Once your package database has been updated, you can now upgrade the packages with updates installed on you machine. This will update any applications, and the Ubuntu core system to the latest versions available. [source,bash] ---- sudo apt-get upgrade ---- ==== SEARCH FOR PACKAGES WITH APT To search for a package you can use the following command: [source,bash] ---- apt search apache2 ---- ==== INSTALLING NEW PACKAGES If you are find the name of the package you want to install, you can install it by running this command: [source,bash] ---- apt install apache2 vlc ---- ==== REMOVING INSTALLED PACKAGES To uninstall a package from your system, you can use the following command: [source,bash] ---- apt remove vlc ---- NOTE: This command removes the package but keeps the configuration files. So in case you reinstall the same package, your configuration remains the same. If you want to remove both the package and its associated configuration files, you can run this command: [source,bash] ---- apt purge vlc ---- ==== clean up any unused libraries and packages [source,bash] ---- apt autoremove ---- This command automatically removes any packages that aren’t used or associated with any installed program. It’s a great way to clean up any unused libraries and packages you don’t need. :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 ====