In the world of software development, Linux stands as the OS of choice, dominating 80% of the software development industry. Software developers find it very important to make applications on a Linux system due to several advantages. Linux allows developers to find and fix issues early on and test the software on their computers. This method makes the software development process more efficient and reduces error rates. Hence, Linux programming is very important for developers who want to make great and smooth software.
Introduction to Unix-based Operating Systems
Let’s learn about the most popular Linux distribution, or Linux distro for short, widely used in the software industry
Ubuntu OS:
- Ubuntu is a user-friendly Unix-based operating system that emphasizes ease of use and accessibility. Amongst its advantages, Ubuntu boasts large community support, regular updates, and huge pre-installed software.
Debian OS:
- Debian is a stable Unix-like operating system that serves as the foundation for several other Linux distributions, including Ubuntu. Known for its free and open-source software, Debian prioritizes stability and security.
Kali Linux OS:
- Kali Linux is a specialized Unix-based OS built for cybersecurity professionals and enthusiasts. It comes preloaded with a suite of devices for infiltration testing, moral hacking, and scientific examination, making it a go-to choice for security specialists.
CentOS:
- CentOS (Community Enterprise Operating System) is a free, open-source Linux distribution OS from the sources of Red Hat Enterprise Linux (RHEL). This OS is a popular choice for server environments due to its stability.
Red Hat OS:
- Red Hat Enterprise Linux (RHEL) is a commercially supported Unix-based operating system known for its robust performance and high-security features. Widely used in enterprise environments, Red Hat offers long-term support and a focus on scalability.
Cloud Custom Linux OS:
- Cloud Custom Linux (Amazon Linux) distributions are operating systems specifically designed for cloud computing environments. They often feature optimizations for virtualization, containerization, and seamless integration with cloud services for enhanced performance and scalability.
Rocky Linux OS:
- Rocky Linux is a community-based, open-source operating system developed as a free alternative to CentOS. It aims to provide a stable and reliable platform for users who prefer an earlier version of the CentOS’s development model.
For developers, the choice of the OS often depends on personal preferences, project requirements, and development environment considerations. However, certain distributions are commonly recommended for developers due to their features, support, and developer-friendly tools. Here, a popular choice is Ubuntu.
→ Why: Ubuntu is widely recommended for developers due to its user-friendly interface, reach package management system (apt), and a big community of users. It has excellent hardware compatibility, a rich repository of software packages, and is well-documented. Ubuntu is suitable for a wide range of development tasks and supports various programming languages.
Let’s talk about Linux insights
Linux File System:
A Linux file system is a way an operating system manages and organizes files on a computer’s storage devices. Several types of file systems are available for use in Linux, including ext, btrfs, and xfs. The choice of file system will depend on factors such as the intended use of the system and the type of storage device in use. It’s important to choose a file management system that is well-suited to your needs to ensure optimal performance and reliability.
Hence, Linux programming offers unique advantages due to its advanced file system architecture.
Linux file system hierarchy:
System Root (/):
Description: The /root directory is the top-level directory in the Linux file system hierarchy. It contains all essential system files, configuration files, and directories. All other directories and files are subdirectories or files within the root directory.
System Boot (/boot):
Description: The /boot directory contains files essential for the system’s boot process, such as the Linux kernel, initial ramdisk (initrd), and boot loader configurations. Separating boot files from the root directory can be helpful for system maintenance and troubleshooting.
System Configuration (/etc):
Description: The /etc directory stores configuration files for the system and installed applications. It plays a crucial role in system customization, allowing administrators to modify settings for various software components, services, and the overall system behavior.
System Variable (/var):
Description: The /var directory holds variable data that may change during the system’s operation. This includes log files, spool directories for mail and print queues, and temporary files. It allows for storing and modifying data during system runtime.
System Mount (/mnt):
Description: The /mnt directory is commonly used as a temporary mount point for external or temporary file management systems. When users need to access data from external storage devices, network shares, or other file systems, they often mount them under /mnt for the duration of their use.
Additionally, the directories in the root directory are typically named with a single letter, such as /bin, /dev, /home, /lib, /media, /opt, /proc, /root, /sbin, /srv, /sys, /tmp, and /usr. Each directory has a specific purpose. For example, the /bin directory contains essential user command binaries, the /dev directory contains device files, the /home directory contains user home directories, the /lib directory contains shared libraries, the /media directory is used for removable media, the /opt directory is used for add-on application software packages, the /proc directory contains process information, the /sbin directory contains system binaries, the /srv directory is used for data for services from the system, the /sys directory contains virtual files that represent the system hardware, the /tmp directory is used for temporary files, and the /usr directory contains user utilities and applications.
In conclusion, Linux programming offers distinct advantages, particularly when considering the Linux File System (ext4, xfs, btrfs, etc.). Understanding the Linux file system hierarchy is crucial for developers and system administrators as it facilitates efficient organization, navigation, and management of files and directories on the system.
Package Repository in Linux
Linux programming offers significant advantages, especially considering the Package Repository system. Package repository in Linux is like a digital store that has ready-to-install software packages and dependencies. It’s a central distributed repository where your Linux system can discover, download, and install new software applications or updates.
Comparison with Windows:
In Windows, you need to visit various websites to download software and install it manually. With Linux package repositories, it’s more like having a one-stop shop built into your system. You tell your Linux system what you want, and it goes to the repository, pulls it, and installs it, saving you the hassle of searching and downloading software from different pages on the internet.
The default repository paths for package management on various Linux distributions are as follows:
- Ubuntu:
- Default Repository Path: /etc/apt/sources.list
- Debian:
- Default Repository Path: /etc/apt/sources.list
- CentOS:
- Default Repository Path: /etc/yum.repos.d/
- Red Hat:
- Default Repository Path: /etc/yum.repos.d/
- Rocky Linux:
- Default Repository Path: /etc/yum.repos.d/
In these paths, you will find configuration files that specify the repositories from which the respective package managers (such as APT for Debian and Ubuntu, and YUM/DNF for CentOS, Red Hat, and Rocky Linux) fetch and install software packages. These configuration files list the URLs or locations of the repositories where the package manager looks for software packages and updates.
Package Manager and Update Process
Here’s a list of package managers associated with specific Linux distributions:
apt:
- Used By: Ubuntu, Debian, Kali Linux
Example Commands:- sudo apt update
- sudo apt install <package_name>
yum:
- Used By: Red Hat, CentOS, Cloud Custom Linux
Example Commands:- sudo yum update
- sudo yum install <package_name>
sudo yum update
sudo yum install <package_name>
dnf:
- Used By: Rocky Linux
Example Commands:- sudo dnf update
- sudo dnf install <package_name>
These package managers facilitate the installation, removal, and management of software packages on their respective Linux distributions.
Repository Update:
The commands you’ve provided are used to update the package repositories on specific Linux distributions. Here are the commands for repository updates:
- For Ubuntu, Debian, Kali Linux (using apt):
sudo apt update
- For Cloud Custom Linux, Red Hat, and CentOS (using yum):
sudo yum update
These commands refresh the local package repository information, ensuring that your system is aware of the latest available software packages and their versions. After running these commands, you can proceed to install or upgrade packages as needed.
Package/Software Installation:
Installation commands for different package managers on specific Linux distributions, as well as the installation commands for downloaded packages in different formats. Here’s a summary:
Package Installation:
- For Ubuntu, Debian, Kali Linux (using apt):
sudo apt install [Package Name]
- For CentOS, Red Hat, Cloud Custom Linux (using yum):
sudo yum install [Package Name]
Downloaded Package Installation:
For CentOS, Red Hat, Cloud Custom Linux (using RPM):
rpm -i [Package Name. rpm]
For Ubuntu, Debian, Kali Linux (using deb):
dpkg -i [Package Name. deb]
Linux Basic Command
Linux programming offers numerous advantages, particularly in its command-line interface (CLI). Here’s a list of command examples with short descriptions for various categories of operations when programming in Linux:
1. File and Directory Manipulation:
- Create a Directory:
mkdir [Directory Name]
- Copy a File:
cp [Source File] [Destination]
- Move/Rename a File or Directory:
mv [Source] [Destination]
- Remove a File:
rm [File Name]
- List Files and Directories:
ls
- To see also hidden file
ls -a
2. File Operations and Compression:
- Create a Tar Archive:
tar -cvf [Archive Name.tar] [Files/Directories]
Example:
tar -cvf archive.tar file1.txt file2.txt directory1
This command creates a tar archive named archive.tar containing file1.txt, file2.txt, and directory1.
Syntax Description:
- tar: The command for manipulating tar archives.
- -cvf: Options to specify the operation and additional settings:
- -c: Create a new archive.
- -v: Verbosely list files processed.
- -f: Use the specified archive file (followed by the archive name).
- [Archive Name.tar]: The name of the archive file to be created. This should end with the .tar extension.
- [Files/Directories]: The list of files and directories to be included in the archive.
- Extract from a Tar Archive:
tar -xvf [Archive Name.tar]
Example:
tar -xvf archive.tar
This command extracts all files and directories from the archive.tar file.
Syntax Description:
- tar: The command-line utility used for archiving and extracting files.
- -xvf: Options to specify the operation and additional settings:
- -x: Indicates that the operation is to extract files from the archive.
- -v: Verbose mode, which displays a list of files as they are extracted.
- -f: Specifies the archive file to operate on, followed by the archive name.
- [Archive Name.tar]: The name of the tar archive file from which files will be extracted. This should be provided as an argument to the -f option.
- Compress a File or Directory (gzip):
gzip [File/Directory]
Example:
gzip file.txt
This command compresses file.txt and creates a gzipped file named file.txt.gz.
Syntax Description:
- gzip: The command for compressing files or directories.
- [File/Directory]: The name of the file or directory to be compressed.
- Decompress a gzipped File:
gunzip [File.gz]
Example:
gunzip file.txt.gz
This command decompresses the file.txt.gz file and restores the original file.txt.
Syntax Description:
- gunzip: The command for decompressing gzipped files.
- [File.gz]: The name of the gzipped file to be decompressed.
3. Network and Connectivity:
- Check Network Configuration:
ifconfig
Or
ip addr
- Ping a Host:
ping [Host/IP]
- Check Open Ports:
netstat -lntu
4. Text Processing and Manipulation:
- View a Text File:
cat [File]
Example:
cat index.php
- Search for a String in a File:
grep [Pattern] [File]
Example:
grep "LARAVEL_START" index.php
This command searches for the specified pattern in the index.php and displays lines containing the pattern.
Syntax Description:
- grep: The command-line utility used for searching text patterns.
- [Pattern]: The string pattern or regular expression to search for within the file.
- [File]: The name of the file in which the search will be performed.
- Count Words in a File:
wc -w [File]
Example:
wc -w [index.php]
This command counts the number of words in the index.php and displays the count.
- Replace Text in a File:
sed 's/old-text/new-text/' [File]
Example:
sed 's/LARAVEL_STA/LARAVEL_START/' index.php
This command uses sed (stream editor) to search for LARAVEL_STA in the index.php and replaces it with LARAVEL_START. However, this command only displays the modified text on the terminal. To replace text in the file, you would typically use the -i option with sed:
sed -i 's/old-text/new-text/' index.php
This command replaces old text with new text in the index.php and modifies the file in place.
Syntax Description:
- sed: The command-line utility used for text stream processing.
- ‘s/old-text/new-text/’: The substitution command in sed syntax:
- s: Indicates that the following pattern substitution should be applied.
- old-text: The text or pattern to be replaced within the file.
- new-text: The replacement text.
- [File]: The name of the file in which the replacement will be performed.
5. User and Group Management:
- Create a User:
useradd [Username]
- Change User Password:
passwd [Username]
- Add User to a Group:
usermod -aG [Group] [Username]
- List Groups:
groups
6. Privilege and Security Management:
- Change File/Directory Permissions:
chmod [Permissions] [File/Directory]
Example:
chmod -R 765 /var/www/my-web
This command changes the permissions of the /var/www/my-web directory to rwxrw-r-x for the owner, rw-rw-r-x for the group, and r-xr-xr-x for others.
The -R option is used to recursively change permissions for all files and directories within /var/www/my-web.

- Change File/Directory Owner:
chown [Owner:Group] [File/Directory]
Example:
chown -R www-data:www-data /var/www/my-web
This command changes the owner and group of the /var/www/my-web directory to www-data.
The -R option is used to recursively change the owner and group for all files and directories within /var/www/my-web.
- Monitor Log Files:
tail -f [Log File]
This command continuously displays the last few lines of the /var/log/syslog file as new lines are added to it. It’s useful for monitoring
log files in real-time, especially for troubleshooting or observing system activity.
7. Process Management and Control:
- List Running Processes:
ps aux
- Kill a Process:
kill [PID]
- Background Process Execution:
command &
8. Data Backup and Synchronization:
- Create a Backup with rsync:
rsync -av [Source] [Destination]
- Create a Backup with tar:
tar -cvzf [Backup Name.tar.gz] [Files/Directories]
9. Basic System Administration and Control:
- Check System Information:
uname -a
- System Reboot:
reboot
Or
reboot now
- System Shutdown:
shutdown -h now
- Check Disk Space:
df -h
- Service restart:
systemctl restart [Service Name]
- Service Status Check
systemctl status [Service Name]
- Service Stop
systemctl stop [Service Name]
10. File and Directory Permission:
- Change Permissions to 777 (Read, Write, Execute for Owner, Group, and Others):
sudo chmod 777 [File or Directory Name]
In Linux programming, administrators utilize these commands to create users and groups, manage file and directory permissions, change ownership, and add users to specific groups on a Linux system. Keep in mind that using chmod 777 gives full read, write, and execute permissions to everyone, which may not be the most secure setting depending on the context. It’s recommended to use more specific permissions whenever possible.
11. File and Directory Ownership Change:
- Change Owner and Group:
sudo chown [UserName]:[GroupName] [File/Directory]
12. User Add to Group:
- Add User to Group:
sudo usermod -aG [GroupName] [UserName]
13. Soft link or symlink
- Create symlink
sudo ln -s [target] [ [link-name]
Example:
sudo ln -s /path/to/targetfile /path/to/symlink-name
Symbolic Links (Symlinks) notes:
- Symbolic links are essentially shortcuts or pointers to files or directories.
- They contain the path to the target file or directory.
- If you delete the original file or directory, the symbolic link will be broken.
- They can point to files or directories on different file systems.
14. Hard link
- Create a hard link
sudo ln <target> <link_name>
Example :
sudo ln /path/to/targetfile /path/to/hardlink-name
Hard Links notes:
- Hard links are direct references to the inode of a file. An inode is a data structure on a filesystem that stores information about a file or directory.
- They share the same inode and the same data blocks as the original file.
- Deleting the original file does not remove the hard link as long as there are other hard links pointing to it.
- Hard links cannot reference directories or files on different file systems.
- Hard links cannot cross file system boundaries or reference directories.
15. Remote access:
- Remote login with SSH:
ssh username@remote-SystemIP
ssh -i "public-key.pem" user@remote-server-ip
- File Transfer Local to Remote System with SCP
scp [Sourcefile] RemoteSystem@RemoteSystemIP:[Destination Path]
- File Transfer Remote System to Local with SCP
scp RemoteSystem@RemoteSystemIP:[File Path] [/Local System Path]
These commands cover a broad range of Linux operations and are foundational for system administrators and developers working on Linux systems.
Conclusion
Linux programming offers many advantages, especially due to its robust command-line interface (CLI). The powerful commands for file manipulation, network management, text processing, user administration, process control, and system maintenance makes Linux programming highly efficient and flexible for developers. From basic file operations to advanced system administration, Linux commands streamline workflows, enhance productivity, and ensure secure and reliable development environments. Additionally, features like symbolic and hard links enable efficient file referencing, while remote access commands facilitate seamless collaboration and deployment. Overall, Linux programming harnesses the full potential of its command-line interface, making it the preferred choice for developers seeking efficiency, flexibility, and security in their programming endeavors.
Required tools:
- Virtual Machine Download and Install for Practice
- Ubuntu ISO File to install on the VM (Virtual Machine)
- Installation Tutorial
- Remote SSH Login tools
This page was last edited on 13 June 2024, at 12:36 pm
How can we help you?























