Linux Basic Commands


The command line is a text-based interface that can be used to take input from a user as an instruction to the computer system. In the Linux, the command line is provided by a program called the “shell”. There are so many shell program have been developed but “GNU Bourne-Again shell (bash)” is the default shell in some Linux distribution such as Centos and RHEL. Bash is an improved version of one of the most successful shells used on UNIX like the system the Bourne Shell (sh).
Using “bash” to execute command can be powerful. The “bash” shell provides a scripting language that can support the automation of tasks. The shell has additional capabilities that can simplify or can make some operation possible that are hard to accomplish with graphical tools.



Note: The “bash” shell is similar in concept to “cmd.exe” the command line interpreter of Microsoft Windows, although bash is a more sophisticated scripting language and it is also similar to “PowerShell”.

To access the terminal in a graphical mode of Centos and RHEL you just need to select Application > Utilities > Terminal or Just right click on an empty desktop > Open Terminal.

From the Activities Overview, select Terminal from the dash (either from the favorite’s area or by finding it with the grid button (inside utility grouping) or the search field at the top of the window overview).

Before starting to learn some commands let understand the difference between $ and #.
When a shell is used interactively. The shell displays a string when it is waiting for a command from the user. This is called the shell prompt. When a regular user starts a shell, it shows $ character to the end of the prompt by default.


The $ character gets replaced by a # if the shell is running as the superuser, root. This # character makes it more obvious that it is a superuser shell, which helps to avoid accidents and mistakes in the privileged account.


Linux Basic Commands
Let’s starts with simple Linux commands.

1. pwd command: “pwd” stands for present working directories that print the absolute path of the current working directories. 



2. cal command:  “cal” command display calendar of current month but by specifying month and year it will display a calendar of that specific month and year for example: “cal 5 2000”.



From the above example 5 stands for the month “may” and 2000 is the “year”. You can practice by specifying only a month after the “cal” command.

3. who command: “who” command displays all users who are currently logged in.




4. whoami command: “whoami” command displays the name of a current user who is logged-in into a particular terminal.



5. who am i command: There is a difference between “whoami” and “who am i” the command “who am i” display not only current user who is logged-in but also pseudo-terminal (pts), time and comment.



6. clear command: “clear” command is used to clear the current terminal.



7. date command: “date” command is used to displays the current date and time.


8. ls command: “ls” command display list of files and directories from current working directories, for example, if you are in the root directory and you type ‘ls” command then it will display all the files and directories under the root directory.



9. cd command: By using “cd” command you can change directory. For example: “cd /directory”.



10. touch command: with “touch” command you can create a file without any content. It extension can be .txt, .file, .zip, or etc. 



11. rm command: “rm” command stands for remove which is used to remove files, but not directories.



If you try to remove directory by just “rm “command it will give throw a message “cannot remove “dir”: Is a directory”.But if you want to remove directories you have to use –r (recursive) option.



12. mkdir command: when you want to make a directory then use “mkdir” to create directory and ‘mkdir” stands for make directory.



If you want to make subdirectory under a directory from a single command then use –p, this means parent option creates parent directories for the requesting destination.



13. rmdir command: To remove any directory you can use the “rmdir” command and “rmdir” stands for remove directory.



14. mv command: “mv” command is used to move files or directories from source to destination. The example for the command is “mv source destination”.



The move command can be used to rename the file or directories as well.



15. cp command: “cp” command is used to copy a file or directories from source to destination.




Useful command line-editing shortcuts
Shortcut
Description
Ctrl+l
Clear the current terminal.
Ctrl+a
Jump to the start of the command line.
Ctrl+e
Jump to the last line of the command.
Ctrl+u
Clear from the cursor to the start of the command line.
Ctrl+k
Clear from the cursor to the last line of the command.
Ctrl+left arrow
Jump to the beginning of the previous world on the command line.
Ctrl+right arrow
Jump to the end of the next word on the command line.
Ctrl+r
Search the history list of commands for a pattern.

                       



The Linux File System Types


The computer file system is the method of organizing how and where the data should be stored on the hard disk, accessed, and managed. The computer file system also provides the capabilities to modify, create, delete the files. Without the file system, the information which is stored would not be isolated into individual files and would be difficult to identify and retrieve.

The ext, ext2, ext3, ext4, and xfs are all the file systems created for the Linux operating system.

1. Ext - The ext stands for extended file system and first implemented in 1992 as the file system created specifically for the Linux. It was developed by Remy Card. Its metadata structure was inspired by the UFS (UNIX file system). It was designed to overcome the certain limitations of the MINIX file system. The individual file size can be 2GB.

2. Ext2 - The ext2 stands for the second extended file system and it was first introduced in 1993. It was developed to overcome the limitation of the ext file system. It was also developed by Remy Card. This file system does not support the journaling feature. This file system comes with the fundamental concept of inode number (index node number or index node). Every file in the file system is represented by an inode. The inode structure contains the pointer to the file system blocks which contains the details about the file and all the meta-data.  The individual file size can be from 16 GB to 2 TB maximum and the overall file system size can be from 2 TB to 32 TB.

3. Ext3 - The ext3 stands for the third extended file system and it was developed by Stephen Tweedie in 2001. It was introduced in Linux kernel 2.4.15 and available since then. It also introduces the journaling feature. Journaling is developed to prevent data from corruption through sudden power loss or system crashes. There is three types of journaling mode are available in the ext3 file system such as journal, ordered, and write back.
  • Journal - It provides the most secure data retention policy. Basically, it writes metadata and file content to the journal but reduces the performance.
  • Ordered - This is a default mode and all the metadata are journal only after writing the content to disk. 
  • Write back - This mode is faster but at high risk. It makes no guarantee as to when the metadata is committed to the journal. But allow the file to shows up after a crash and relies on kernel standard write back to flush buffers
The conversion from ext2 to ext3 the file system is possible directly without and backups or restore by using “tune2fs command”. 

4. Ext4 - The ext4 stands for the fourth extended file system it was developed in 2008 and introduced in Linux kernel 2.6.14 and available since then. It has a backward compatibility feature means the ext4 can convert into ext3 or ext2. There are several more features are introduced in the ext4 file system such as multi-block allocation, journal checksum, fast fsck (file system check), delayed allocation, etc. In the ext4 user have an option to turn off the journaling features. The maximum size of an individual file can be from 16 GB to 16 TB and the overall file system size is 1 EB (Exabyte) which is greater than 1 PB (Petabyte) = 1024 TB and 1 TB (Terabyte) = 1024 GB.

5. XFS - The xfs file system was developed by Silicon Graphics Incorporation (SGI) in 1994. This is a 64-bit high-performance journaling file system and introduces in SGI’s IRIX operating system but with version 5.3. This file system was introduced to the Linux kernel in 2001 but in 2014 the xfs file system is supported by most of the Linux distributions and some use as a default file system. The maximum size of an individual file is 8 EB (Exabyte) for the 64-bit file system. The xfs file system is highly scalable but its scalability is for only scaling up not for scaling down means once you create a file system with xfs you cannot reduce the size

Note: Microsoft’s FAT file system is also often an option when formatting a driver in the Linux

Linux File System Hierarchy


The Linux File System Hierarchy or FHS (File-system Hierarchy Standard) is a method that defines the file structure of the Linux operating system in which all the directories and subdirectories are organized in an inverted tree structure.
 In the inverted tree structure, the root is at the top of the hierarchy and the branches such as directories and subdirectories are stretch below the root that is why it is called an inverted tree. In Linux, everything is a file even printer and CD-ROM.
This file system was designed to be used by UNIX distribution developers, system implementers, and package developers.


( / ) The Root Directory: All directories, subdirectories, and files are located under ‘root’ which is represented by “/” (forward slash). Some people get confused between “/” and “/root”, well these two are not the same “/” is called a root directory where all other directories and files of the whole system descended and “/root” is just a root user home directory. The only root user has permission to write under this directory while other users have only read permission to this directory. The subdirectories under “/” are used for standardized purposes to organize files by their type and purpose.

(/bin) Essential User Binaries: This directory contains the executable files of Linux shell basic commands such as ls, cp, grep, cat, etc. Most of the programs in this directory are in binary format and they are accessible by all the users.

(/boot) Boot files: This directory contains the file needed in order to start the boot process, such as the kernel initrd (Initial RAM Disk image), Grub files, etc.

(/dev) Device files: This directory contains special device files that are used by the system to access hardware. This directory also contains some special files that are virtual files, not physically on the disk for example /dev/null.

(/etc) Configuration files: This directory contains configuration files specific to the system. This directory contains a services file, password file, networking file, etc. Basically, if you need to make some changes in the system configuration you can find the respective file under this directory.

(/home) User’s home directory: It is the directory where regular users store their personal data and user-specific configuration files. When you create a user on a Linux system, it generates a folder with user-name under /home directory which looks like “/home/user1”.

(/lib & /lib64) Shared libraries: The “/lib” directory contains shared library images which are need by the essential binaries in the “/bin” and “/sbin” directories. The difference between “/lib” and “/lib64” is that 64-bit version of libraries are stored in “/lib64” and 32 bit version of libraries is stored in “/lib”.

(/media) Mount point of removable media: When you connect any removable devices such as USB, DVD, or SD card, the system automatically creates a temporary mount point under this directory.

(/mnt) Mount point: In this directory system administrator has to create a mount point manually. A system administrator can use this directory to mount file systems, NFS, lvm, etc.

(/opt) optional software: The “/opt” directory is used for storing or installing the third party application which is not available in the official repository or proprietary software
.
(/proc) Process & kernel files: This is a special directory that contains information about the currently running process and kernel parameters. This directory is a virtual file system with text information about the system. For example, if you want to check CPU information then refer to the file /proc/cpuinfo.

(/root) Root user home directory: This is a home directory for the administrative superuser root.

(/run) Application state file: The “/run” directory contains runtime data for processes started since the last boot which includes process ID files and lock files, among other things.

(/sbin) System binaries:  The “/sbin” directory is similar to the “/bin” directory, but it contains the binaries that can run only by the superuser or root or sudo user.

(/srv) Service data: The “/srv” is a directory that contains data of varies services provided by the system. The full form of srv is service. If you are running an HTTP web server from your host system, then it is a good practice to store the website data like HTML file under “/srv” (“/srv/www” or “/srv/Http”).

(/sys) Virtual file system (sysfs): The kernel not only export information to “/proc” but also to virtual file system called sysfs. The sysfs file is mounted under “/sys” directory. The sysfs is created to clean up the “/proc” because much of the hardware information has been moved from “/proc” to “sysfs”.

(/tmp) Temporary directory: This directory is for temporary files. In Linux, many applications use this directory to store temporary files. But do note that files that have not been accessed, changed, or modified for 10 days are automatically deleted from this directory. There is another temporary directory inside the “/var” directory that is “/var/tamp”, in which files that have not been accessed, modified, or changed in more than 30 days are automatically get deleted.

(/usr)  User binaries:  This directory contains installed software, shared libraries include files, and static read-only program data. The important point is the four directories in “/” now have identical contents which are located under “/usr” such as,
“/bin” and “/usr/bin”,
“/sbin” and “/usr/sbin”,
“/lib” and “/usr/lib”.
                                                                                                                                         
(/var) Variable: This directory contains variable data specific to the Linux system that should persist between boots. Files that dynamically change like application files “/var/cache”, various log “/var/log”, user mailbox “/var/mail”, outgoing mail queue and print queue “/var/spool”, etc. found under “/var” directory.


Featured Post

Managing user and groups, UID and GID in Linux

What are users in the operating system? A user is a person who accesses or utilizes computer resources or network services. In order to ...

Popular Posts