# Linux ## Absolute Path vs Relative Path in Linux/Unix One of this blog follower asked us that whatâs the difference between absolute and relative path? To understand this we have to know what is a path in Linux. ### What is a path? A path is a unique location to a file or a folder in a file system of an OS. A path to a file is a combination of / and alpha-numeric characters. What is an absolute path? An absolute path is defined as the specifying the location of a file or directory from the root directory(/). In other words we can say absolute path is a complete path from start of actual filesystem from / directory. ### Some examples of absolute path: ```bash /var/ftp/pub /etc/samba.smb.conf /boot/grub/grub.conf ``` If you see all these paths started from / directory which is a root directory for every Linux/Unix machines. ### What is the relative path? Relative path is defined as path related to the present working directory(pwd). Suppose I am located in /var/log and I want to change directory to /var/log/kernel. I can use relative path concept to change directory to kernel changing directory to /var/log/kernel by using relative path concept. > $ pwd/var/logcd kernel Note: If you observe there is no / before kernel which indicates itâs a relative directory to present working directory. Changing directory to /var/log/kernel using absolute path concept. > $ cd /var/log/kernel Note: We can use an absolute path from any location where as if you want to use relative path we should be present in a directory where we are going to specify relative to that present working directory. Examples of relative path and absolute path for the same operation. # Basic Linux Command ## help - Man: an interface to the on-line reference manuals > $ man ls ## Wildcard * Show all picture (multiple char) > $ ls pic* ? show only picture between 50 and 59 (only one char) > $ ls pic5?.jpg [] show only if char in [p-P] > $ ls [pP]ic* ## Files and directory - ls: list directory contents > $ ls > args = -l -a -r -t -h --help - Pwd: output the current working directory > $ pwd - Cd: Change directory > $ cd back to previous folder > $ cd - - Mkdir: Make directory > $ mkdir test1 test2 test3 > $ mkdir -p lol/lol/lol -p to create parent directory if needed - Rmdir: Remove directory > rmdir filename > rm -rf filename - Mv: Move directory (can be used to rename a file) > mv file /opt/movedfile - Cp: Copy file or directory > $ cp file /opt/newcopiedfile - Touch: change file timestamps but it can also create files > $ touch nomdefichier.md > $ touch pic{00..99}.jpeg # does not work - Which: Searching the PATH for executable files matching the names of the arguments > $ which ls - File: file — determine file type > $ file myfile ## file viewer - More: file perusal filter for crt viewing > $ more filename - Less: opposite of more but Less is more ;) > $ less filename - Cat: concatenate files and print on the standard output > $ cat filename ## Users adduser, addgroup - add a user or group to the system > sudo adduser steve ```bash r4v3n@d3bi4n:~/Workspace/test$ sudo adduser steve [sudo] password for r4v3n: Sorry, try again. [sudo] password for r4v3n: Adding user `steve' ... Adding new group `steve' (1002) ... Adding new user `steve' (1002) with group `steve' ... Creating home directory `/home/steve' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully Changing the user information for steve Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y ``` user skeleton: skeleton files used for new user configuration > $ ls /etc/skel/ ```bash ─r4v3n at d3bi4n in /etc/skel ╰─» ls -a 0 (0.002s) < 05:21:24 ./ ../ .bash_logout .bashrc .profile ``` - Change user > $ su - marie ## Permissions - Chmod: change file mode bits A combination of the letters **ugoa** controls which users' access to the file will be changed: - the user who owns it (u), - other users in the file's group (g), - other users not in the file's group (o), - or all users (a). If none of these are given, the effect is as if (a) were given, but bits that are set in the umask are not affected. ![file permissions](./img/file_permission.png) ```bash marie@d3bi4n:~$ ls -l total 4 -rw-r--r-- 1 marie marie 12 Apr 7 05:44 test ``` > $ chmod o-r mysecret > -rw-r--**-**-- 1 marie marie 12 Apr 7 05:44 test > $ chmod o+**rw** myscret > -rw-r--**rw**- 1 marie marie 12 Apr 7 05:44 test Number alternatives: ### Groups Groups: print the groups a user is in > $ groups Adds user marie into steve group > $ adduser marie steve ```bash r4v3n@d3bi4n:~/Workspace/test$ sudo adduser marie steve Adding user `marie' to group `steve' ... Adding user marie to group steve Done. marie@d3bi4n:~$ groups marie steve ``` ## Sysadmin tools - Htop: Interactive processes viewer > $ htop ## text editor - Nano: Nano's ANOther editor, an enhanced free Pico clone (simple text editor for noobies) > $ nano > $ nano filename - VIM: vim - Vi IMproved, a programmer's text editor (PGM) > $ vim > $ vim filename # APT > $ apt install > $ apt remove > $ apt autoremove > $ apt update ## Display & Destop Manager * Architecture: > BIOS -> GRUB -> Display Manager -> Desktop Environement * Install Desktop Environement (GUI) > $ tasksel > $ apt install gnome > $ apt remove gnome * Reconfigurer le display manager > $ sudo dpkg-reconfigure gdm3 * Installer le display manager > $ sudo apt install lightdm > $ sudo apt install gdm3 * remove Desktop environement > $ sudo apt remove lightdm # Services - HTOP - dhclient > get ip - gnome networkmanager - wpa_supplicant > encryption @ wifi