Chapter 2 : Basics of Linux - Part 1

Linux File Structure

  •  Linux has the default file structure which can be seen in below image
  • To know about the different directories and their usage, hit the below command in your linux machine terminal
man hier
  • / - root directory where the whole tree starts. Only root user has write previleges here
  • /bin - contains binary executables. Common commands used in single user mode are available here. Eg : ps, ls, ping, locate, zip, grep, who
  • /boot - static boot loader files required during the boot process. Kernel initrd, vmlinux, grub files are located here
  • /dev - Device files which belong to ohysical devices.These include terminal devices, usb, or any device attached to the system
  • /etc - Configuration files of the machine are present here. This also contains startup and shutdown shell scripts used to start/stop individual programs
  • /etc/opt - host specific files of the add on softwares are present here
  • /etc/skel - When new user is created, files from here are copied into the user's home directory
  • /home - home directories for the users are present here
  • /lib - shared libraries that are necessary during system boot and while executing commands in root file system
  • /media - contains mount points for removable devices like cdrom and usb
  • /mnt - contains mount points for temporarily mounted file system
  • /opt - optional add on softwares installed by user are present here
  • /proc - mount point for proc file system, which has information about running processes and kernel. Its a pseudo file system
  • /root - home directory for root user
  • /sbin - executables needed during boot, these are typically not used by users but sys admins. Eg: ifconfig, reboot ,. etc
  • /srv - site specific data serverd by system
  • /tmp - location for temporary files which are deleted upon reboot or regular job
  • /usr - contains binaries, libs and documentation of second level softwares
  • /usr/bin - contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example:at, awk, cc, less, scp
  •  /usr/sbin - contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
  •  /usr/lib - contains libraries for /usr/bin and /usr/sbin
  • /usr/local - contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2
  • /var - contains files which change in size like spool and log files.This includes — system log files (/var/log), packages and database files (/var/lib), emails (/var/mail), print queues (/var/spool), lock files (/var/lock), temp files needed across reboots (/var/tmp).

What is Shell

  • Shell is the default user interface of linux. It accepts your commands and executes the commands. It is like a command line interpreter. Server distributions does not include GUI, it only has CLI whereas Desktop distro’s has both GUI and CLI.
  • Most systems have default shell as bash but sh (the original Bourne shell) and ksh (the Korn shell) are used on a few UNIX systems.
  • The default prompt for a regular user is simply a dollar sign. The default prompt for the root user is a hash sign
  • In most Linux systems, the $ and # prompts are preceded by your username, system name, and current directory name. For example, a login prompt for the root user with computer named localhost with root home directory as the current working directory would appear as
    [root@localhost ~]# pwd 
    /root
    • You can change the prompt to display any characters you like and even read in pieces of information about your system which will be discussed in shell prompt topic.

    Basic Linux Commands


    • arch Display print machine hardware name.
    • cal Show calendar.
    • cat Used to concatenate files and print them on the screen.
    • chsh Switch login shell.
    • clear Used to clear the terminal window.
    • date Show system date and time.
    • echo Send input string(s) to standard output i.e. display text on the screen.
    • exit Exit from the terminal.
    • export Used to set an environment variable
    • free Show free and used system memory.
    • halt Command used to halt the machine.
    • hash Shows the path for the commands executed in the shell.
    • history Shows the command history.
    • host A utility to perform DNS lookups.
    • hostid Shows host’s numeric ID in hexadecimal format.
    • hostname Display/set the hostname of the system.
    • ifconfig Used to configure network interfaces.
    • init Systemd system and service manager.
    • less Displays contents of a file one page at a time. It’s advanced than more command.
    • look Shows any lines in a file containing a given string in the beginning.
    • man Shows manual pages for Linux commands.
    • more Display content of a file page-by-page.
    • most Browse or page through a text file.
    • poweroff Shuts down the machine.
    • pwd Show current directory.
    • stat Display file or filesystem status.
    • su Change user ID or become superuser.
    • sudo Execute a command as superuser.
    • tac Concatenate and print files in reverse order. Opposite of cat command.
    • uname Show system information.
    • vmstat Shows information about processes, memory, paging, block IO, traps, disks, and CPU activity.
    • w Show who is logged-on and what they’re doing.
    • watch Runs commands repeatedly until interrupted and shows their output and errors.
    • whatis Display one line manual page descriptions.
    • whereis Locate the binary, source, and man page files for a command.
    • which For a given command, lists the pathnames for the files which would be executed when the command runs.
    • who Shows who is logged on.
    • whoami Displays the username tied to the current effective user ID.
    • whois Looks for an object in a WHOIS database

    Comments

    Popular posts from this blog

    Chapter 1 : Introduction to Linux

    Man Pages