Post

Learning Linux (CLI actually)

BLOG STILL IN PROGRESS

Learning Linux (CLI actually)

Starting to learn linux, again! Now in a structured way!

Actually it’s learning how to use shells and terminals.

Terminal - A visual window where I type my commands Shell - An Engine which process the commands or interprets it eg: Bash, zsh, Powershell

Main goals of the course are:

  1. Navigate through file system
  2. Install s/w through CLI
  3. Manage PATH & env variables
  4. Manage permissions and execute programs

Anfang! The Command Line

Main job of shells is to Read, Eval, Print and Loop (REPL). So what the shell basically does is, read the commands I type, evaluvate them, and print the output and prompt me to type another command & repeat.

expr command used to evaluvate expressions eg:

1
expr 123 + 789

expr

gives me an output of 912. After surfing the web about this, turns out expr is an ancient script, which is less used nowadays.

1
echo $((123 + 789))

The above command is used, which is not more easier compared to expr. Both the above commands are limited, because they only perform integer arithmetic.

GUI vs CLI

GUI - Graphical user interface, also called Goo-ye, basically involves graphics to do its bid, fancy stuff. CLI - Command line interface, does the same thing as GUI but offers more, flexibility and is versatile.

In this case it’s Ease of use vs Functionality, while both of them are two different sides of the same coin, I’m going to stay in the middle ground. (CLI is cool, I watched Mr. Robot, and he’s cool because he uses CLI). This might be a beginner’s take on GUI but, it is more easier and discoverable, compared to CLI, but there are trade-offs for both of them, depends on the user either they choose visually easier version or they want something that’s easier to automate.

I’m using Fedora KDE plasma, so Konsol Terminal by KDE and bash shell, I also have zsh shell with some customizations in it, which I tampered with the conig files, now it’s under repair (not working).

https://www.boot.dev/lessons/004ccd6e-6614-4468-bc74-51e3bb293011 (funny: “I pray you already know what you’re already using”)

Variables

This just works same as any other programming languages but without declaring the data type. just

1
2
name="sam"
echo $name

I declared the variable, and then called it used the echo command, so $ is kind of a prefix that helps to tie the variable to the command. Linking the variable to get an output is also easy

1
2
3
4
name="sam"
age="unknown"
born="unknown"
echo the unknown is being is called $name whose age is $age and its birth place is $born 

I am getting ideas!!

File Handling

Linux handles files using path system. There are 2 file path systems often used, they are Absolute path and Relative path.

  1. Relative path - this starts from the files current location to point the contents located in this particular folder. eg: Home has 3 folder Downloads, Documents and Music we are in Downloads pointing to some pdf, so the file’s location will be “Downloads/some.pdf”

  2. Absolute path - this path is sort of a definite path, that starts to locate a file from the root. eg: “/Home/Downloads/some.pdf” which has a “/” indicating that it started from root

cat command is used to read what’s inside the file

head and tail

These commands are used to view the head and tail of the file respectively, for example “head -n 10 file.txt” displays number (n) 10 lines from top, same goes for the tail command

Touch a file creates a new file, empty file, mkdir creates a directory/folder

mv command to move a file

  • mv draft.txt final.txt (renames)
  • mv draft.txt finalFolder/final.txt (move to different folder)
  • mv draft.txt ../draft.txt (moving to parent directory)

rm -r this will help remove a directory with all it’s contents inside cp for copy; cp -R, the r/R stands for Recursive. grep command for searching “grep “hello” words.txt” or in multiple files “grep “hello” words1.txt words2.txt” or grep -r “hello” in the entire directory.

Commands Learnt

  • expr => evaluvate expressions [Surprised me that it’s basically deprecated]
  • echo => Used to print eg ‘printf’
  • man => an interface to the system reference manuals
  • whoami => print effective user name
  • sudo dnf clean all => Clear DNF package cache
  • sudo dnf autoremove => Remove orphaned old kernel packages
  • sudo dnf remove $(dnf repoquery –installonly –latest-limit=-2 -q) => fedora keeps 3 kernels by default, so this will remove unnecessary kernels
  • du -sh ~/.cache => to get the size of the cache
  • rm -rf ~/.cache/* => to remove cache
  • cd => current directory
  • pwd => print name of working directory

References

  • https://www.boot.dev
  • https://www.geeksforgeeks.org/operating-systems/difference-between-terminal-console-shell-and-command-line/
  • https://man7.org/linux
This post is licensed under CC BY 4.0 by the author.