The Shell Game:  Uncovering the Secrets of Command Line

The Shell Game: Uncovering the Secrets of Command Line

SHELL

As a software engineer, understanding the basics of shell commands and scripting is essential for automating tasks, managing and manipulating files and directories, and interacting with the operating system. Shell, also known as a command-line interface (CLI), provides a text-based interface to interact with the computer, making it a powerful tool for developers. Whether you are working on Linux, macOS, or Windows, mastering the shell is a valuable skill that can help you streamline your workflow and make your day-to-day activities more efficient. With a deep understanding of shell commands and scripting, you can automate tasks, simplify complex processes, and make your work easier and more efficient.

What is shell

Shell is a program that takes command from the keyboard and gives it to the operating system to perform.
Shell interacts from the terminal
There are basic shell commands to work with.

Navigation

This is using shell commands to navigate the terminal.
Before understanding this we must know the UNIX/LINUX file structure.
The Linux file system hierarchy is a standardized way of organizing and storing files and directories on a Linux operating system. The hierarchy starts at the root directory (represented by "/") and branches out into subdirectories. The main branches of the hierarchy include:

  1. /bin: Essential command binaries that need to be available in single user mode.

  2. /boot: Boot loader files.

  3. /dev: Device files that represent devices and physical hardware.

  4. /etc: System-wide configuration files and scripts.

  5. /home: User home directories, containing personal files and configuration.

  6. /lib: Essential shared libraries.

  7. /media: Mount points for removable media, such as CDs and DVDs.

  8. /mnt: Temporarily mounted file systems.

  9. /opt: Optional add-on application software packages.

  10. /root: The home directory for the root user.

  11. /sbin: System administration and system management executables.

  12. /srv: Service data for specific system services.

  13. /tmp: Temporary files.

  14. /usr: User-related programs, libraries, and documentation.

  15. /var: Variable data, such as log files and temporary files generated by system services.

Commands

  1. File Management
CommandsDescription
..Parent directory
.current directory
cd(-)Navigate the last directory
cd (~)/ cdNavigate to home
  1. File Listing
commandsDescription
ls-aList directory in long format
ls -ld dirList information about directory name instead of contents
ls -alist files including hidden
ls -ltsort with last time modification
ls -lhlist file size in human-readable format
ls -lrShow all subdirectories recursively

ls -f: is a special file listing command that needs a symbol to indicate the type

symbolsymbol name
@symbolic link
*executable
\=socket
>directory

Other Shortcuts to navigate the terminal

CommandDescription
CTRL+Ago to the beginning of the line
CTRL+Bmoves backward one character
CTRL+Cstops the current command
CTRL+Ddeletes one character backward or logs out of the current session
CTRL+Ego to the end of the line
CTRL+Fmoves forward one character
CTRL+Gaborts the current editing command and rings the terminal bell
CTRL+Kdeletes (kill) forward to the end of line
CTRL+Lclears the screen and redisplay the line
CTRL+Nnext line in the command history
CTRL+Rsearches in your command history
CTRL+Ttransposes two characters
CTRL+Ukills backward to the beginning of the line
CTRL+Wkills the word behind the cursor
CTRL+Yretrieves the last deleted string

Conclusion

The shell may present a challenging task to master, but it is worth the effort as it opens up a world of possibilities.

As we continue our journey in the world of shell, we will delve deeper into its secrets and discover new ways to utilize its capabilities. It is important to stay informed and updated on the latest developments in the shell world to fully unlock its potential. So let's keep learning and exploring the shell together!

Follow me on LinkedIn.