-
Notifications
You must be signed in to change notification settings - Fork 84
Linux basics
If you need any help or have questions, talk to me on Discord, I'll be happy to help. :) Michael_Scopic.zsh#0102
Linux is an operating system, like Windows and Mac OS. Linux is actually a bit newer than MS DOS and Macintosh (not the modern Mac OS), as it first appeared in 1991. Linus Torvalds, a Finnish student created the Linux kernel originally as a hobby, and Richard Stallman helped him create his hobby into a functional operating system, providing utilities and tools.
A kernel is the heart of any operating system, and is the bridge between software and hardware. It controls hardware resources, I/O (Input/Output), network sockets, file systems, etc.
Linux came from Unix, which is an OS from ancient times. Unix was closed source, meaning that you couldn't look at the source code. Wanting a change, Richard Stallman created the GNU Project, which made free and open source software. But Stallman didn't have anything to run his software, and Linus didn't have anything to run on his new kernel; the perfect opportunity for collaboration.
And so the Linux that we know and love to this day was created.
Linux follows the FOSS (Free and Open Source Software) philosophy. "Free as in freedom." This philosophy gives users the freedom to do anything with software, which means Linux is fully controllable and extensible.
Linux is a very transparent and customizable operating system. It does not hide things from the user. (* ahem.. Apple and Microsoft. *)
This allows you to control every aspect of the operating system, from using different software to using different init systems, to different kernels, to different desktop environments. You want to get rid of your bootloader? Go for it. (Don't do this.) Want to remove everything in your filesystem? Sure. (Don't do this either.) Now compare that to Windows, which doesn't even let you uninstall the slow Edge browser it ships with.
This level of customizability allows users to make their desktop look like eye candy. This is known as "ricing" in the Linux community. If you want to check some of it out, look at r/unixporn on Reddit (no, it's not actual porn, don't worry).
Because Linux is community ran and open source, Linux is very stable and secure. You would think that because someone is able to look at the source code, there would be more viruses for it, but ironically this makes it more secure because people are able to review the code and patch vulnerabilities. Now, Linux isn't immune to viruses and malware, but there aren't that many viruses made for Linux.
Linux also focuses on user privacy. Most Linux distros (short for distribution), barely has any (if any) telemetry or spyware, unlike Windows and Mac OS. (Very few distros do have telemetry/spyware, like LinuxFX and some other sketchy distros). Tails Linux is a Linux distro that focuses solely on privacy, and aims to keep the user as anonymous as possible by putting all of the network traffic through Tor.
The shell/CLI is what Linux is most known for. The CLI (Command Line Interface) allows a user to enter commands that the computer recognizes. The CLI is very efficient, focused and fast. The shell is software that translates commands typed at a terminal into something the computer knows, just like programming language interpreters/compilers. When using EC2 in AWS, you use the CLI.
New users to Linux are often scared by the terminal, but it is very easy to learn and grow to love. The syntax is very simple and makes sense. When I (Michael S) first started using Linux, I would try to avoid the terminal if possible, but now I use the terminal as much as I can.
Knowing how to work in a terminal is extremely useful and may even save you hours of banging your head on the table, or could even save you your data!
-
Hint: You can run
man [command]
with any command that you want to know about (eg:man apt
). This will open the manual page for a command. -
Hint: You can also run
[command] --help
to show the help menu of a command. (eg:apt --help
)
apt [options] [subcommands]
# Debian/Ubuntu's package manager
# ex: apt list
sudo apt update [options]
# updates your package repositories
sudo apt upgrade [options]
# upgrades all your packages that you have installed
sudo apt install [options] [package]
# installs a package
# ex: sudo apt install -y neofetch
sudo [command]
# allows a user to run a command as root.
# ex: sudo echo "hello"
uname [options]
# Shows info about your Linux system, like your running kernel
# ex: uname -r # Prints your kernel
# ex: uname -a # Prints all info
Editing files
nano [path/to/file]
# OR
vim [path/to/file]
# edits a file
# ex: vim .bashrc
# ex: nano .bashrc
# Tip: Type in ':wq' to [w]rite and [q]uit in vim. Alternatively, you can type ':q!' to just quit vim.
cat [/path/to/file]
# Prints out the contents of a file as stdout (standard output)
# ex: cat .bashrc
Interacting with files and directories
cd [/path/to/directory]
# [c]hanges [d]irectory to a directory
# ex: cd .config/neofetch
# tip: running 'cd' without any arguments will change directory to your home directory (/home/$USER/)
rm [options] [file or directory]
# [r]e[m]oves a file or directory.
# note: you need to run 'rm -rf [directory]' to remove a directory that isn't empty
# ex: rm -rf test/
# ex: rm test.txt
mv [options] [file or directory]
# [m]o[v]es or renames a file/directory
# ex: mv test test-renamed # this renames a file/directory in the same directory
# ex: mv test.sh ~ # moves 'test.sh' to the user's home directory ('~' is the same as '/home/$USER')
cp [options] [source] [destination]
# [c]o[p]y a file or directory
# ex: cp test-dir/ path/to/new/dir
ls [options] [directory]
# [l]i[s]ts files in a directory
# adding the '-A' option to ls lets you view hidden files
# ex: ls -A
# ex: ls /etc
Changing permissions for files/directories
chown [arguments] [user:group] [file or directory]
# [ch]anges [own]er of a file or directory
# ex: sudo chown -R michael:michael yay-git/
chmod [arguments] [permissions] [file or directory]
# [ch]ange [mod]ifcations of a file or directory
# ex: chmod +x test.sh # makes the file executable
# ex: chmod -R 777 test/ # gives all permissions to everything in 'test/'
Misc.
echo [arguments] [message/input]
# does the same thing as 'print()' in python, useful for putting words/lines in a file without using vim or nano
# adding the -e option allows echo to interpret escape characters like '\n'
# ex: echo hello world!
# ex: echo "appending this line to a file" >> test.txt
# ex: echo "overwriting a file with this line" > test.txt
# ex: echo * # does the same thing as 'ls'
# ex: echo -e "Hello World!\n"
grep [options] [pattern] [source file]
# searches for a pattern in a file
# ex: grep "hello world!" test.txt # tries to find 'hello world!' in 'test.txt'
# ex: cat test.txt | grep "hello world!" # does the same thing as above, but we can use 'cat' to provide the input to grep with the use of '|'
clear
# clears the terminal
# you can also clear the terminal by hitting <ctrl> + <l> (that's L, not an i)
Unix like systems follow something called the "Unix filesystem hierarchy". This means that all directories are neatly organized.
Everything starts from the root directory, or /
.
/bin
: where all of your binaries exist. Running pwd
executes the pwd binary in /bin
.
/dev
: where every device is attached. In Unix, everything is a file.
/etc
: where system-wide configuration files are.
/home
: the home directory for system users. The home directory for the user "steve" would be /home/steve
.
/lib
: where the libraries are for binaries and functions.
/mnt
: for mounting drives or other media.
/proc
: this directory doesn't actually exist. It is a virtual directory. You should not need to go to here.
/root
: the home directory for the root user.
/sbin
: binaries that only the root can use. You can run these binaries by prefixing any command in /sbin
with sudo
.
/tmp
: temporary directory that is wiped upon reboot.
/usr
: user binaries, libraries, and configuration.