Linux Basics
echo "HEY GUYS WELCOME TO MY FIRST LINUX BLOG"
Linux is something I've always been around but never fully learned. If you're anything like me you probably love coding and want to start going down to the more hardware level and thought that Linux would be a cool introduction. Without further ado, let's get started!
History:
In 1969 Ken Thompson and Dennis Ritchie made something called the UNIXUNiplexed Information and Computing System operating system. Later Richard Stallman made GNUa recursive acronym for GNU's Not UNIX which was based on UNIX but completely open source. It wanted to have a kernel but was unable to complete it in time. Which now begs the question: what is the kernel?
What is the Kernel?
The kernel can control:
- CPU
- memory
- peripheral devices
- AND MORE
The kernel was made by Linus Torvalds which was called the Linux kernal. When GNU and the Linux kernel were combined that created what most people call Linux now (note that Linux does actually only refer to the kernel). Anything that uses a Linux kernel is a Linux distribution or "distro".
Different Distros
- Debian
- Open Source and Free
- Uses aptadvanced package library package manager
- Red Hat Enterprise Linux
- Used for enterprise commercial applications
- Ubuntu
- Build on Debian
- Uses aptadvanced package library package manager
- Easy to use and good for beginners
- Fedora
- Open source and free version of Red Hat
- Arch Linux
- Lightweight and very bare-bones, so you will learn a lot of Linux from it
- MANY MORE
The Shell
The shell is how we can type commands and have them executed on the operating system. Think of a command as no different than one you would give to your sibling or friend. If you ask your sister to give you a glass of water that is no different from us asking the operating system to ping an ip address. By using a GUIgraphical user interface we can open a shell session via applications like "Terminal" or "Console".
We are going to really dive into the BashBourne Again Shell application (note there are others such as the Zsh shell that Mac uses). Typically the line will start with a $ which indicates that the shell is ready to accept commands.
echo
this command just prints out whatever you input after
echo "Hello World!"Hello World!
pwdprint working directory
this command just prints out the current working directory
pwd/Users/aryanjain/Projects/kuiper-dashboard/infra
cdchange directory
this command is used to change the directory you are in
- cd . (current directory)
- cd .. (go back one folder)
- cd ~ (home directory)
- cd - (the previous directory)
Hey so honestly there are a lot of different commands I am learning these from here so I would look over that for all of them. I am now going to just go over a couple that I didn't know previously.
In Linux we can have a file called "banana.png" and it doesn't have to actually be a png so we can use the file command to see what file type banana.png is!
The difference between less and cat: cat you can look at a file and it will display the whole file. Less you can look at chunks. cat puts the whole file into the buffer and will scroll you to the very bottom of the file that is printed out in the terminal so if it is a super long file I would recommend less. less also allows you to search by using / (whatever you want to search for) and you can go to the next occurrences by pressing n and the previous ones by pressing N.
- history - just the history of your commands
- cp - copies a file to a location
- mv - moves a file to a location
cp text.txt ./data/text
mv other_text.txt ./data/text/morethe manmanual command is used to learn more about a command. whatis is a short one-line version of man.
man ls
man cd
whatis catstdout when you print stuff the stdout is where that information goes. To redirect that flow you can use either > or >>.
echo "Hello World" > cat.txt
echo "using the >> appends to the file instead of deleting it" >> cat.txtstdin - by default Bash gets its input from your keyboard, but we can make it so it takes input from a file source.
cat < cat.txtpipe - the pipe command (|) is used to take the stdout of one command as the stdin to another. This command is used to link together commands such that we can develop stronger more powerful outcomes.
ls -la /etc | lessgrepGlobal Regular Expression (if you take upper level CS classes at a university or if you know about regular expressions this term makes a lot of sense)
this is used to match a pattern in a file or find text in files.
grep fox sample.txtFINAL REMARKS
I used this blog mainly as a notes tab for myself so while I hope it was useful I do recognize that this isn't the best way to learn Linux. I think that you should look at this resource which is where I learned. Also as you develop as a CS student and developer you learn most of this stuff along the way. I would say the main thing you should learn is a general idea of what these commands do and then know what is the best command you need to research more to achieve what you need.