NOTE

Assuming you’re already logged in

1. Absolute basics

Table 1. Absolute basics
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

1.1. Key combinations

Table 2. Key combinations
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).

1.2. ls -l

# 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

1.2.1. File types

This table gives an overview of the characters determining the file type:

drwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install
Table 3. File types in a long list
Symbol Meaning

-

Regular file

d

Directory

l

Link

c

Special file

s

Socket

p

Named pipe

b

Block device

-rw-rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md

1.2.2. Access rights

Table 4. Access rights
Code Meaning

0 or -

The access right that is supposed to be on this place is not granted.

4 or

read access is granted to the user category defined in this place

2 or

write permission is granted to the user category defined in this place

1 or

execute permission is granted to the user category defined in this place

1.2.3. User group codes

Table 5. User group codes
Code Meaning

u

user permissions

-rw-rw-r--

g

group permissions

-rw-rw-r--

o

permissions for others

-rw-rw-rw-

1.2.4. Exercises

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

2. Linux file system layout

Table 6. Subdirectories of the root directory
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.

3. Find and grep

3.1. 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:

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).

 find /etc -name "*.conf"

3.2. grep

grep is used for filtering input lines and returning certain patterns to the output.

grep "string" path/to/file
 grep "root" /etc/passwd

3.3. find and grep command together

find /etc -name "*.conf" -exec grep -Hns "conf" {} \;

Explanation
-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.
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"
Very powerful in bash scripts create a file test.sh .bash script
#!/bin/bash
STRING=$(find /etc -name "*.conf" -exec grep -Hns "conf" {} \;)
echo $STRING

exec it .bash script

chmod 700 test.sh
./test.sh

4. Managing software

4.1. 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.

4.1.1. 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.

apt-get update

4.1.2. 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.

sudo apt-get upgrade

4.1.3. SEARCH FOR PACKAGES WITH APT

To search for a package you can use the following command:

apt search apache2

4.1.4. INSTALLING NEW PACKAGES

If you are find the name of the package you want to install, you can install it by running this command:

apt install apache2 vlc

4.1.5. REMOVING INSTALLED PACKAGES

To uninstall a package from your system, you can use the following command:

apt remove vlc
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:
apt purge vlc

4.1.6. clean up any unused libraries and packages

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.




Reminder

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