Skip to content

sandeshgit/LinuxGuideForAll

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Linux Guide For All

Table of Content

Before You Begin!



What Is Unix

Unix comes before linux, so if you know a little bit, it will be great for you. Unix is an operating system whose development started in 1969 for multi-user, multi-tasking. Unix is not free and open source os. It can be only utilized by its copywriters. So linux came into the picture. Some examples of unix operating systems are: SunOS, Solaris, SCO Unix, HP/UX.

What Is Linux

To understand simply, like Windows, Mac, Linux is an operating system [OS] based on Linux Kernel. Operating systems lie between computer hardware and computer users, so that users can interact with computers easily. It was developed by Linus Torvalds in 1991. It is free and open source means you can use it for free, view its source code. We can change the source code of linux and use it for personal as well as commercial purposes.

E.g: Ubuntu, Arch Linux, Debian GNU etc.

Where Is Linux

  • TV
  • Mobile Phones
  • Self Driving Car
  • Plane
  • Rocket
  • Super Computers
  • Servers (Many websites are hosted on Linux.)

Who Uses Linux

  • US Government
  • Top Tech Companies like Google, Microsoft, Amazon by various means
  • Hackers and cybersecurity experts
  • Financial Institutes
  • Computer Programmers and Researchers
  • Those who want to acquire high technical knowledge

Some Linux Distro

  • Ubuntu
  • Fedora
  • Elementory OS
  • Red Hat OS
  • Cent OS
  • Kali Linux
  • Arch Linux
  • Gentoo Linux
  • Void Linux
  • Linux From Scratch (LFS)

Linux Vs Windows

  • Linux runs for months or years without reboot, but in windows often reboot is required.
  • Most of the software is available for windows but not in linux.
  • Linux is Secure than windows.
  • Linux is Fully Customizable but Windows is not.
  • Linux is Free and open source But Windows is Paid and proprietary (closed source).
    Are all linux based OS free? No, not all linux based OS are free. Enterprise level linux based operating systems are paid. E.g Red Hat Enterprise Linux(generally used at servers) is a paid OS; if we have a problem the Red Hat team will support and provide us a solution.

Windows Filesystem Vs Linux Filesystem

windows vs linux file system image

Points To Remember While Using Linux

  • Folder in linux is called directory and shortly denoted as dir.
  • Linux is a case sensitive System. A is different than a. E.g: linux.txt and Linux.txt are two different files in linux.
  • Avoid using filename as space.
  • Super Admin/Super User is also called root who can do anything.
  • Software is called a package.
  • Be careful while using sudo command. Don't use sudo unless you know what does the command actually do. Wrong commands with sudo can break your system. Eg: sudo rm -Rf / removes everything from your system including your operating system.

File System In Linux

linux file system explained

Linux File Hierarchy Standard

Path Content
/bin Binaries (User)
/root Files of root user
/boot Static boot loader files
/etc Host specific configs
/lib Shared libraries and kernel modules
/sbin Binaries (System/root)
/var Varying files (e.g. Logs)
/usr 3rd party (User Installed) software
/proc Pseudo file system
/sys Pseudo file system
/mnt Mountpoint for internal drives
/media Mountpoint for external drives
/home User homes
/run PID files of running processes


Linux Commands For All

NOTE: Emojis ⚪ and ⚫ are used only to easily differentiate between different commands and make the reading easy. They do not have anything to do with the actual commands.

Help And Manuals

Command Example Description
man <command> man cd
man ls
Read help/manual of a particular command.
(close with q)
<command> --help
<command> -h
ls --help
cd -h
Also help.
sudo <command> sudo reboot
sudo rm a.txt
Run commands as super user/Forcefully do a task.
⚪ Forcefully restart your system.
⚫ Forcefully remove a.txt.
sudo is basically used to perform tasks
that cannot be done by a regular user.
Tab (1x or 2x) cleTab
cd DowTab
Auto completion.
⚪ when pressed cleTab,
it autocompletes the command to clear
⚫ when pressed cd DowTab,
it autocompletes the command to cd Downloads/
  See previous command.
Ctrl+C Kill the current process or command.
Ctrl+R Search through your history.
Start typing and it will auto-complete.
Hit Ctrl+r again,
and it will cycle though the other auto-completion options.
Hit Enter and the command will execute.
Hit , to edit commands.

Basic Commands

Command Description
whoami Display current user name
hostname Display current host name
date Display current date and time
clear Clear Screen (Clear contents in currently open terminal emulator)
users Display Currently logged in user/s
reboot Restart your machine
poweroff Shut down your machine
pwd Display Current/Working directory

Linux Everyday Commands

Command Example Description
mkdir mkdir LinuxGuide
mkdir a b c d
mkdir {A..Z}
mkdir -p Linux/Guide/Pdfs
⚪ Create a directory named LinuxGuide.
⚫ Create directories a, b, c,d.
⚪ Create directories from A to Z at once.
⚫ Create directories with parent/s (directory inside a directory).
cd cd LinuxGuide
cd Linux/Guide/Pdfs
cd ..
cd ../..
cd ~
cd -
⚪ Navigate to LinuxGuide directory.
⚫ Navigate to Linux/Guide/Pdfs directory.
⚪ Navigate one directory backward.
⚫ Navigate two directories backward.
⚪ Navigate to home.
⚫ Navigate to last directory.
ls ls
ls -a
ls -l
ls -r
ls -R
ls -S
ls -t
⚪ List all the contents of the directory.
⚫ Show hidden items.
⚪ Format as lists.
⚫ Invert Order.
⚪ Recurse. (Quiet similar to tree listing)
⚫ Sort by size.
⚪ Sort by date modified.
ls -Sal Different options can be combied.
Here ls -Sal shows all contents in the directory
including hidden items in a list format according to size.
rmdir rmdir Linux
rmdir -p Linux/Assets/Pdfs
⚪ Remove an empty directory named Linux.
⚫ Removes Pdfs directory & its ancestor dirs
(empty dirs only)
echo echo "Hello!" Displays Hello!(Display a line of text)
touch touch a.html
touch ch{1..9}.txt
Change timestamps of any kind of file.
⚪ Create a file a.html.
⚫ Create files ch1.txt to ch9.txt.
Update the access and modification times
of each FILE to the current time.
cat cat a.txt Print content of file a.txt (top to bottom)
tac tac a.txt Print content of file a.txt in reverse (bottom to top)
cp cp source destination
cp -r source destination
⚪ Copy file from source to destination location.
⚫ Copy folder (recursively)
mv mv sourcefile destination Move file and folders from source to destination.
rm rm a.txt
rm -r Linux/
rm -rf Linux/
rm *.jpg
⚪ Remove file a.txt
⚫ Remove non-empty direstory Linux.
⚪ Force remove non empty directory Linux.
⚫ Remove all .jpg files within the directory.
find find -iname filepattern
find -mmin n
find -mtime n
find -regex pattern
find -size n[kMG]
find ! searchparams
⚪ Search dir/file case-insensitive
⚫ Last modified n minutes ago
⚪ Last modified n days ago
⚫ Path matches pattern
⚪ By file size (-n less than; +n greater than)
⚫ Invert search
locate locate file find your file by name(faster than find)
(Must run sudo updatedb before using this command)
sort sort file
sort -ru file
⚪ Display sorted contents of file.
⚫ Print sorted descending without dublicates.
uniq uniq file Hide consecutive identical lines.
wc wc file
wc -l file
⚪ Count Lines, Words, Chars (Bytes) in file
⚫ Count Lines in file. (-w/-c for words/characters)

Stream Redirection

STDOUT (Standard Output Stream)

  • > overwrite
  • >> append

STDIN (Standard Input Stream)

  • < input

For examples:

Command Description
echo "I LOVE LINUX" > a.txt Creates a.txt if it doesn't exist and writes I LOVE LINUX inside a.txt
If a.txt exists already, overwrites the content inside it with I LOVE LINUX.
echo "LINUX IN NEPALI" >> b.txt Creates b.txt if it doesn't exist and writes LINUX IN NEPALI inside b.txt.
If b.txt exists already, it appends LINUX IN NEPALI to a new line
without overwrithing/erasing the previous contents in the file.
wc -l < a.txt As you should know what does wc -l do,
it shows the number of lines in a file.
Here wc -l takes a.txt as input file to count the lines of.

Check Memory Stats and CUP Stats as Linux Admin

Command Example Description
free free -m
free -g
free -h
⚪ Display amount of free & used memory in Megabytes.
⚫ Display amount of free & used memory in Gigabytes.
⚪ Display amount of free & used memory in human readable format.
vmstat vmstat -a
vmstat -d
vmstat -D
⚪ Display active/inactive/virtual memory status.
⚫ Display disk stastistics.
⚪ Display summarized disk stastistics.

Add And Remove User Account In Linux

Linux is a multi-user operating system, which means that more than one user can use Linux at the same time. Linux provides a beautiful mechanism to manage users in a system. One of the most important roles of a system administrator is to manage the users and groups in a system.

Super User permission is required to add/remove user; So, sudo should be used before following commands:

Command Example Description
useradd useradd brp Create a new user account named brp.
passwd passwd brp Add/change password for user brp.
userdel userdel -r brp Delete user named brp from the system.

About

Linux Basics for Beginners!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published