LINUX (Ubuntu) Basics & Advances

LINUX (Ubuntu) Basics & Advances

What is Linux?

Linux is a Unix-like operating system that was created by Linus Torvalds in 1991. It is a free and open-source operating system, meaning anyone can use, modify, and redistribute it without any restrictions. It is a very versatile operating system. It can be used on various devices, including servers, desktops, laptops, and mobile phones. It is also famous for embedded systems, such as routers and firewalls.

Linux Architecture:

Linux File system structure:

  • / (root file system): The top-level file system directory. It must include every file needed to boot the Linux system before another file system is mounted. Every other file system is mounted on a well-defined and standard mount point because of the root file system directories after the system is started.

  • /root: It's the home directory for a root user. Remember, it's not the '/' (root) file system.

  • /boot: It includes the static kernel, bootloader configuration, and executable files needed to start a Linux computer.

  • /bin: This directory includes user executable files.

  • /var: Here, variable data files are saved. It can contain MySQL, log files, other databases, email inboxes, web server data files, and more.

  • /etc: It includes the local system configuration files for the host system.

  • /media: A place for mounting external removable media devices like USB thumb drives that might be linked to the host.

  • /home: The home directory storage is available for user files. All users have a subdirectory inside /home.

  • /sbin: These are system binary files. They are executables utilized for system administration.

  • /usr: They are read-only and shareable files, including executable libraries and binaries, man files, and several documentation types.

  • /dev: It includes the device file for all hardware devices connected to the system. These aren't device drivers; instead, they are files that indicate all devices on the system and provide access to these devices.

  • /opt: It contains optional files like vendor-supplied application programs that must be placed here.

  • /lib: It includes shared library files needed to start the system.

  • /mnt: It is a temporary mount point for basic file systems that can be used when the administrator works or repairs a file system.

  • /tmp: The OS uses a temporary directory and several programs for storing temporary files. Also, users may temporarily store files here. Remember that files may be removed without prior notice at any time in this directory.

Basic Linux Commands

ls: Lists the contents of a directory.

To see the contents of the current directory, you can use the ls command. For example, to see the contents of the /home directory, you would run the following command:

 ls /home

  • This will list all directories and files in the /home directory.

  • Cd: Changes the current directory.

To navigate to a different directory, you can use the cd command. For example, to navigate to the /etc directory, you would run the following command:

cd /etc

Creating, Deleting, and Renaming Files and Directories

  • mkdir: Creates a new directory.

To create a new directory, you can use the mkdir command. For example, to create a new directory called my_directory, you would run the following command:

mkdir my_directory

  • rmdir: Removes an empty directory.

To remove a directory, you can use the rmdir command. For example, to remove a directory called my_directory, you would run the following command:

rmdir my_directory

  • touch: Creates a new file.

To create a new file, you can use the touch command. For example, to create a new file called myfile.txt, you would run the following command:

touch myfile.txt

  • cat: Displays the contents of a file.

To display the content of a file, you can use the cat command. For example, to display the content of a file called myfile.txt, you would run the following command:

cat myfile.txt

  • rm: Delete a file.

To delete a file, you can use the rm command. For example, to delete the file myfile.txt, you would run the following command:

rm myfile.txt

  • echo: Prints a message to the console.

You can use the echo command to print a message to the console. For example, to print a message "Hello there!", you would run the following command:

echo "hello there!"

  • mv: Renames a file.

To rename a file, you can use the mv command. For example, to rename the file myfile.txt to newfile.txt, you would run the following command:

mv myfile.txt newfile.txt

man: Displays the manual page for a command.

  man ls

Advance Commands

File Permission

chmod octal filename = Change file permissions of the file to octal

Example:

chmod 777 /data/test.c => Set rwx permissions to owner, group and everyone (everyone else who has access to the server)

chmod 755 /data/test.c => Set rwx to the owner and r_x to group and everyone

chmod 766 /data/test.c => Sets rwx for owner, rw for group and everyone

chown owner user-file => Change ownership of the file

Network

ip addr show => Displays IP addresses and all the network interfaces

ip address add 192.168.0.1/24 dev eth0 => Assigns IP address 192.168.0.1 to interface eth0

ifconfig => Displays IP addresses of all network interfaces

ping host => ping command sends an ICMP echo request to establish a connection to server / PC

whois domain => Retrieves more information about a domain name

dig domain => Retrieves DNS information about the domain

dig -x host => Performs reverse lookup on a domain

host google.com => Performs an IP lookup for the domain name

hostname -i => Displays local IP address

wget file_name => Downloads a file from an online source

netstat -pnltu => Displays all active listening ports

Compression/Archives

tar -cf home.tar home => Creates archive file called ‘home.tar’ from file ‘home’

tar -xf files.tar => Extract archive file ‘files.tar’

tar -zcvf home.tar.gz source-folder => Creates gzipped tar archive file from source folder.

gzip file => Compression a file with .gz extension.

Install Packages

rpm -i pkg_name.rpm => Install an rpm package.

rpm -e pkg_name => Removes an rpm package.

dnf install pkg_name => Install package using dnf utility.