3_bash.pdf
Document Details
Uploaded by Deleted User
Full Transcript
👨🏻💻 3. Linux, shell and bash Presentation Shell shell is in general a user interface of OS either GUI, TUI, or CLI GUI = grafical user interface 3. Linux, shell and bash...
👨🏻💻 3. Linux, shell and bash Presentation Shell shell is in general a user interface of OS either GUI, TUI, or CLI GUI = grafical user interface 3. Linux, shell and bash 1 command-line user interface tui = text based user interface Linux: Bash, Wayland compositor, X window manager 3. Linux, shell and bash 2 bash wayland 3. Linux, shell and bash 3 x window Windows: Powershell, Windows shell powershell 3. Linux, shell and bash 4 windows shell macOS: Z shell, Quartz z shell 3. Linux, shell and bash 5 quartz Bash = Bourne again shell most common shell in Linux different distributions have different terminal emulators Secure shell protocol - SSH protocol for remote connection to computers replaced unsecure telnet used by evesy sysadmin remote computer is acting as server local computer is client can be used on Windows, Linux, Android, BSD, and even macOS 3. Linux, shell and bash 6 🕸️ SSH (Secure Shell) is a way to safely connect to another computer over the internet. It lets you control that computer as if you were sitting in front of it, using just text commands. SSH keeps your information private by encrypting the data, so no one can see what you're doing. It’s commonly used to manage servers and transfer files securely. PUTTY or windows terminal 3. Linux, shell and bash 7 putty 3. Linux, shell and bash 8 windows terminal putty - SSH client windows terminal - new terminal app for windows VPN is necessary for cennection to school server from outside of VŠE network username: your school user name password: your password to InSIS ssh [email protected] Opening terminal ctrl+alt+t opens terminal in ubuntu elements you see here: 3. Linux, shell and bash 9 username @ - at hostname ~ $ - regular user # - root blinking cursor Program/command execution 3. Linux, shell and bash 10 program + parameter + argument date displays the current date and time echo Hello prints hello to the terminal echo “Hello world” prints “Hello world” to the terminal, including the space between the two words echo Hello\ world prints “hello world” to the terminal, backslash is used to escape the space, allowing you to include it without quotes date —help - quick help for majorita of commands provides a quick help message that shows how to use the date command and its options 3. Linux, shell and bash 11 … man date - command man page opens the manual (man) page for the date command, providing detailed information about its usage, options and examples echo $PATH - write variable 3. Linux, shell and bash 12 prints the content of the PATH environment variable, which lists directories that the shell searched for executable files which echo - which program is used for command displacs the path of the program that will be executed when you type echo - this helps you identify which version of a command is being used pwd - print working directory prints the current working directory, showing where you are in the filesystem LS = list ls lists the files and directories in the current directory ls -a - list all lists all files and directories, including hidden ones 3. Linux, shell and bash 13 ls -l details lists files and directories in long format, showing detailed information such as permissions, number of links, owner, group, size, and last modified date ls/ -l - list root with details lists all files and directories in the root directory ( / ) with detailed information..- current directory youre in.. - one level up in FS ~ - tilde, home directory of current user Elementary navigation in FS - CD = change directory cd + name of directory or path absolute or relative path 3. Linux, shell and bash 14 🕸️ An absolute path is the complete address to a file or folder, starting from the root of the file system. On a Windows system, it might look like C:\Users\YourName\Documents\File.txt. On a Mac or Linux, it could be /home/YourName/Documents/File.txt. Imagine you want to find a book in a huge library. An absolute path is like having the full address of the library, telling you exactly how to get to the book no matter where you are. For example, it would be like saying, "Go to the main entrance, walk straight to the second floor, turn right, and find the shelf labeled ‘Adventure Books’ 🕸️ A relative path is a way to address a file or folder based on the current location you are in, without starting from the root. If you are in the Documents folder, you could just refer to the file as File.txt or../Pictures/Image.jpg to go up one folder and then into the Pictures folder. On the other hand, a relative path is like giving directions based on where you are right now. If you’re already on the second floor, you might just say, "Go to the shelf labeled ‘Adventure Books’." 🕸️ So, an absolute path gives you all the details from the start, while a relative path gives you shortcuts based on where you are. 3. Linux, shell and bash 15 cd. - change directory to current directory cd.. - go one level up in FS cd - - go back to previous place cd ~ - go to home directory of current user LS -L, files/folders - permissions ls -l command shows a list of files and folders with important details, including their permissions d - directory folder that can hold files or other folders l - symlink (reference) like a shortcut to another file or directory r - read/see files in folder allows you to see the files in the folder w - write/create, rename, delete files inside folder write permission, allows you to create, rename, or delete files inside the folder x - execute/enter folder (cd) execute permission allows you to enter the folder (using cd command) user, group, anybody else 3. Linux, shell and bash 16 File manipulation mv - move,rename cp - copy rm - delete rm-r - delete recursively - for folders delete everything inside it along with the folder itself rm -f - force - do not ask and ignore this command forces the deletion of files without asking for confirmation mkdir - create folder creates new folder rmdir - delete folder used to delete an empty folder Input and output echo hello > greetings - save output of echo to file greetings takes the text “hello” and saves it into a file called greetings if the file already exists, it will be overwritten with “hello” cat - print content of file prints the contents of a file to the terminal cat greetings - displays whatever is inside greetings cat < greetings - print greetings 3. Linux, shell and bash 17 also prints the contents of greetings to the terminal but it uses input redirection is means “take input from the greetings file and who it on the screen” cat < greetings > greetings2 - print file greetings and save it as greetings2 reads the content of the greetings file and saves it into a new file called greetings 2 so fi you had hello in greetings now greetings2 will also have “hello” echo hi >> greetings - append hi to the end of file greetings >> means add to the end instead of replacing the existing content Pipe cat hi | tail -n1 - shows last line of cat output first runs cat hi - displays the content of the file hi the pipe (rovna cara) takes this output and sends it to the tail -n1 command tail -n1 shows only the last line of the output so if the file1 had mutiple lines, this command would shows you just the last one ls -al / | tail -n1 > lastroot - saves last line of ls -al to file lastroot lists all files and directory in the root directory the output is the piped to tail -n1 which grabs the last line of this list the > operator saves this last line into a file calles lastroot curl --head --silent google.com | grep -i content-length | cut --delimiter=' ' -f2 &&, || AND ; 3. Linux, shell and bash 18 command1 && command2 - executes command2 only if command1 finishes successfully command1 || command2 - executes command2 only if command1 fails command1; command2 - executes both commands no matter what Filesystem / - root top-level directory of the file system all other directories branch off from here, like a tree /bin a /usr/bin/ - programs these directories contain essential programs and binaries that the system uses /bin has basic command-line tools needed for booting and repairing the system /usr/bin - contains addictional programs for general user tasks /boot - kernel and boot files holds important files for booting the operating system, including the kernel (the core of the OS) and initial boot files /dev - devices contains device files, which are special files that represent hardware devices so that software can interact with the, /home - home folders this is where the personal folders for regular users are stored /root - root home folder home directory for the root user, who has the highest level of access to the system its separate from the /home directory for regular users 3. Linux, shell and bash 19 /etc - folder with settings contains configuration files and settings for the system and installed programs its where you can modify how your system behaves /mnt - folder with connected drives used for mounting additional drives and file systems such as USB drives and external hard drives important temporary spot to access those devices /var - folder with logs, webs... hold variable files that change frequently, like logs, temporary files, and website data often where you find things like log files that track system activity /proc - current processes info (old)) contains information about currently runnings processes and system information virtual filesystem that provides a way to access system and process- related data /sys - current processes info (new) similar to /proc this directory provides information about current processes and system hardware, but its designed to give a newer and more organized way to access this data 3. Linux, shell and bash 20 ROOT = super user with great power comes great responsibility!!! sudo - temporary rights elevation temporarily elevates your user permissions to perform administrative tasks without switching to the root user, allows you to execute commands with superuser privileges sudo -i - interactive mode opens a interactive shell as the root user, allowing you to run multiple commands with superuser privileges until you exit the shell sudo su - switch to super user (root) this command switches you to superuser (root) account, it allows you to run commands as the root user directly when not absolutely necessary, we do not use sudo 3. Linux, shell and bash 21 apt install htop - fails you dont have necessary pemissions (sudo) notice # when you see # it usually means you are logged in as the root user APT = software installation sudo apt update - update software repository updates the local package index with latest information about available packages and their versions from the software repositories sudo apt install XYZ - install package installs a specific package sudo apt full-upgrade - update all SW upgrades all installed packages to their latest versions resolving dependencies and installing any new packages as needed sudo apt autoremove - remove unused SW removes packages that were automatically installed to satisfy dependencies for other packages and are no longer needed sudo apt autoclean - clean cache cleans up the local repository by removing downloaded package files that can no longer be downloaded, freeing up disk space there is also GUI program 3. Linux, shell and bash 22 Important programs Information htop - overview of running processes and use of resources real time view of running processes and resource usage (CPU, memory) uname -a/-r - kernel version displays kernel version information uname - a: shows all details (kernel name, version, machine hardware, etc.) uname -r: shows only the kernel version lsb_release -a - OS version provides information about the operating system version, including the distribution name and version number lscpu - processor info shows detailed processor (CPU) information, such as the number of cores, architecture, and clock speed lsusb - USB devices info lists information about usb devices connected to your system such as mice keyboards or external drivas lsblk - block devices info displays block devices (like hard drives and their partitions) in a tree-like format, showing how theyre mounted lspci - PCI devices info lists information about pci devices connected to the system such as network cards, graphics cards and more ip a - networking devices info 3. Linux, shell and bash 23 displays details about network intergaces (ip addresses, network configurations etc.) on your system Other reboot shutdown -h now - immediate shutdown exit - leave current terminal CTRL+ALT+F1-8 - changing terminals (only with physical access) find / -name "xy" - find file with name xy in root./program - executes file/program in current folder xdg-open - opens file in default program (while in GUI) edit text files echo touch - creates new empty file nano - simple text editor vi - for serious business Bash script text file with extension.sh always starts with #!/bin/bash (shebang), tells linux what to do with it to create a script, just put commands to text file on separate lines Exercise 3. Linux, shell and bash 24./script.sh - this is how you launch the script 3. Linux, shell and bash 25 chmod - changes permissions of file or directories, it controls who can read, write, or execute a file or a directory 3. Linux, shell and bash 26