Linux Basic Concepts

Linux Basic Concepts

·

5 min read

Linux Basic Commands

whoami                               - Current user name
pwd                                    - Current working dir
cd                                    - Change dir
ls                                    - List file or folder
ls -lrt                             - List file or folder with details
ls -a                               - List hidden files
mkdir dirname                       - Create a new directory
rmdir                               - Remove the diretory
rm filename                           - Remove file
rm -rf                                - Remove direcory forcefully
cp file name /destination           - Copy filename to /desination directory
mv filename1 filename1               - Rename filename1 to filename2
mv source destination                - Move the file source to destination
mkdir -p                            - Create subdirectory
touch filename                       - Create empty file
cat filename                        - Display the content of file
echo "hi"                           - Print the "hi" in the terminal
man ls                                - Display the manual
vi filename                            - Open file with editor
apt install tree                      - Install tree package
tree .                              - List subdirectry
rm -f                               - Force remove 
history                               - Display the command history
history > history.txt               - Copy the history to notepad 
cat /etc/os-release                   - About os information
uptime                               - Provide information system running
apt update                           - Update package lists (Debian/Ubuntu)
yum update                           - Update package lists (RHEL/CentOS)

scp localfile username@remotehost:/path/to/remote/directory/

sudo useradd sunil                         - Adds a new user named sunil.
cat /etc/passwd                             - Displays the contents of the /etc/passwd file, which contains user account information.
sudo passwd sunil                        - Sets or changes the password for the user sunil.
sudo useradd -s /sbin/nologin joe       - Adds a new user named lalith with the shell set to /sbin/nologin, preventing joe from logging in interactively.
cat /etc/passwd                            - Displays the updated contents of the /etc/passwd file.
su sunil                                - Switches to the user sunil.
sudo passwd joe                            - Sets or changes the password for the user joe.
sudo usermod -s /bin/sh joe                - Changes the shell for the user joe to /bin/sh, allowing them to log in interactively.
cat /etc/group                            - Displays the contents of the /etc/group file, which contains group account information.
sudo usermod -aG docker ubuntu             - Adds the user ubuntu to the docker group, allowing them to run Docker commands without sudo.
groups ubuntu                            - Displays the groups the user ubuntu belongs to.
getent group docker                     - Retrieves and displays the docker group entry from the group database.
sudo usermod -aG docker sunil            - Adds the user arunjai to the docker group.
getent group docker                     - Retrieves and displays the updated docker group entry.
sudo usermod -m -d /home/sunil sunil       - Moves the home directory of the user sunil to /home/sunil.
sudo usermod -d /home/sunil sunil     - Sets the home directory of the user sunil to /home/sunil (the -m option moves the contents of the old home directory to the new one).
sudo groupadd sai                       - Creates a new group named ramesh.
cat /etc/group                          - Displays the updated contents of the /etc/group file.
sudo init 6                                - Reboots the system (init 6 is equivalent to a reboot).
scp -i /path/to/your-key.pem /path/to/local/file username@remote_host:/path/to/remote/directory
sudo apt update
sudo apt install ufw

sudo apt-get install nginx
sudo yum install nginx
sudo service nginx start
sudo service nginx stop
sudo service nginx restart
sudo service nginx status

sudo systemctl restart nginx                  -  Restarts the Nginx web server
sudo systemctl start nginx                    - Starts the Nginx web server
sudo systemctl stop nginx                     - Stops the Nginx web server
sudo systemctl status nginx                   -  Checks the current status of the Nginx service
sudo systemctl enable nginx                   - Enable nginx in System startup

sudo ufw status                               - checks the Firewall rules (UFW) 
sufo ufw allow ssh                            - Enable the secure remote access via ssh
sudo ufw allow 'Nginx Full'                   - Enable http and https (80 *443) allow the traffice
sudo ufw enable                               - Enables the UFW firewall

ctrl l
cd /var/www/html
echo "helloworld"                            - Print terminal output has helloworld
sudo touch index.html                        - create the empty file html format
sudo echo "Helloworld" > index.html
sudo vi index.html                           - Editer text file change the content
sudo rm index.html                           - remove the files fromt the pwd

chmod - change the access permissions

Each group of three characters define permissions for each class:

  • Example : chmod 744 myCV.sh

  • chmod user=7, group =4 , other =4 myCV.sh

#SumrwxPermission
74(r) + 2(w) + 1(x)rwxread, write and execute
64(r) + 2(w)rw-read and write
54(r)+ 1(x)r-xread and execute
44(r)r--read only
32(w) + 1(x)-wxwrite and execute
22(w)-w-write only
11(x)--xexecute only
00---none

above example show chmod 744
user - can read, write and execute
group - can read only
others - can also have read access

Linux Directories

WindowsLinuxDescription
C:\Root Directory (/)The top-level directory-All other directories and files are contained within this root directory.
C:\users/homeContains user directories. For example, /home/username is where a user's personal files and settings are stored.
C:\Program Files/etcConfiguration files for the system and installed applications.
C:\Windows/varVariable data like logs, spool files, and databases.
%appdata%/usrUser programs and data. Includes /usr/bin (binaries), /usr/lib (libraries), and /usr/share (shared data).
C:\System32/binEssential command binaries.
C:\System32/sbinSystem binaries, used for system maintenance.
C:\Windows\Temp/tmpTemporary files.
C:\Windows\System32\drivers/devDevice files.
C:\System32\Taskmgr.exe/proc:Virtual filesystem providing process and system information.
C:\System32\msinfo32.exe/sys:Virtual filesystem providing information about the kernel, devices, and other system information.