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.
 
 
 

200 lines
5.6 KiB

= An Introduction to Linux !
Apostolos rootApostolos@swarmlab.io
// Metadata:
:description: Intro and Install
:keywords: Linux, apt
:data-uri:
:toc: right
:toc-title: Table of contents
:toclevels: 4
:source-highlighter: highlight
:no-header-footer:
:nofooter:
:last-update-label!:
:icons: font
:sectnums:
{empty} +
== 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 <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 /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: