🐧 Important Linux
📁 Basic Linux Commands
ls lists directories and files
ls -R lists directories and files recursively means nested
files in folder
ls -a lists all files including hidden files
ls -l List files with permissions
cd <path> change directory
pwd print working directory or present working directory
mkdir <folder_name> creates a new directory/folder
rmdir <folder_name> removes the directory/folder
touch <file_name> creates new file
touch <file1, file2> creates multiple files.
cp <src_file> <destination/> copy a file or folder
mv <src_file> <destination/> move a file or folder to destination folder
rm <file_name> remove file
rm -r <folder_name> remove folder
cat <file_name> view content of file
nano <file_name> open file in code editor
code <file_name> open file in VS Code
clear clear the terminal screen.
-----------------------------------------------------------------------------------
-------------------------------------------------
🔍 File & Text Search
find <path> search folder
find <file_name> search file
grep "text" <file_name> search a pattern in file
locate <file_name> quick search file
head <file_name> show first line of a file
tail <file_name> show last line of a file
-----------------------------------------------------------------------------------
-------------------------------------------------
Users in Linux :)
1. Regular User / Normal User
Just Access of his/her home directory cannot see the home directory of other users.
Normal Access just modifies own data.
2. Root User / Super User
full access can control and see the home directories of other regular users.
[Admin]
Username : root
3. Service User
for background service
Example: www-data(web server), mysql(database),
but very rarely
Commands:
whoami -> Check current user "Who Am i"
sudo su -> Switch to Root user
exit -> UnSwitch to normal user
# = root
$ = normal user
-----------------------------------------------------------------------------------
-------------------------------------------------
Absolute Path vs Relative Path :)
Absolute Path: A full path that starts from the root directory / and points to a
file or folder, regardless of where you are in the system.
Example: /home/muneeb/projects/index.html
Relative Path: A shortcut path that starts from your current working directory, not
from the root.
Example: ./projects/index.html
. = current directory
.. = parent directory
~/ = your home directory (absolute shortcut)
-----------------------------------------------------------------------------------
-------------------------------------------------
Some Important Terminology in Linux
1.SUDO
sudo = super user DO
When we login into the system as normal user we have no access to admin level.
we can use "sudo" as temporary root (admin) to run powerful commands
like:
sudo apt update.
2.APT
apt = Advanced Package Tool
In Linux (Debian/Ubuntu based) systems we use apt to install, update, remove the
software for system.
Commands:
sudo apt update Refreshes the package list form Server.
sudo apt upgrade Update the existing packages to latest
version.
sudo apt install <package_name> Install new package in system
sudo apt remove <package_name> Uninstall the package from system
update vs upgrade
sudo apt update (list update) Just download the latest packages list form
internet
sudo apt upgrade (software upgrade) Install the latest version of package from
internet
-----------------------------------------------------------------------------------
-------------------------------------------------
📂 Permissions & Ownership
chmod 755 <file_name change file permissions (you can also use
chmod calculator for permissions) 755 is a permission value calculated based on
binary to decimal
ls -l list files along with their permission (-
rwxrwxrwx) three rwx first for user second for group and third of public
rwx read-write-execute (for files -rw-r--r--) (for
directories drwxrwxr-x) additional "d" which represents directory
chown <user>:<group> <file_name> change file owner
Tips:
chmod = change mode (change file or directory permissions in Linux, means who can
read, write and execute a file)
chown = change ownership (change the owner or group of a file or directory)
rwx = Read,Write,Execute Owner
rw- = Read and Write Group
r-- = Read only Others (public)
d = its for directory
-----------------------------------------------------------------------------------
-------------------------------------------------
💻 System Info & Management
uname -a shows system information.
top view real time system processes (Ctrl + q) for
exit.
htop interactive process viewer