Start Coding

Topics

Bash Basic Commands

Bash, the Bourne Again Shell, offers a powerful set of basic commands that form the foundation of command-line operations. These commands enable users to navigate the file system, manipulate files, and manage system processes efficiently.

File System Navigation

Navigating the file system is a crucial skill for any Bash user. Here are some essential commands:

  • pwd: Print Working Directory - displays the current directory
  • ls: List - shows the contents of the current directory
  • cd: Change Directory - moves to a different directory

Example usage:


$ pwd
/home/user
$ ls
Documents  Downloads  Pictures
$ cd Documents
$ pwd
/home/user/Documents
    

File Manipulation

Bash provides several commands for creating, copying, moving, and deleting files:

  • touch: Creates a new empty file
  • cp: Copies files or directories
  • mv: Moves or renames files or directories
  • rm: Removes files or directories

Here's an example of file manipulation:


$ touch newfile.txt
$ cp newfile.txt backup.txt
$ mv backup.txt old_backup.txt
$ rm newfile.txt
    

File Content Viewing

To view file contents, use these commands:

  • cat: Displays the entire file content
  • less: Allows scrolling through large files
  • head: Shows the first few lines of a file
  • tail: Displays the last few lines of a file

System Information and Management

Bash offers commands for system-related tasks:

  • date: Displays the current date and time
  • whoami: Shows the current user
  • ps: Lists running processes
  • top: Displays real-time system statistics

Command Help and Documentation

When you need help with a command, use:

  • man: Displays the manual page for a command
  • --help: Shows a brief help message for most commands

For example: man ls or ls --help

Important Considerations

  • Always use caution with commands that modify or delete files, especially when using wildcards.
  • Some commands require superuser privileges. Use sudo when necessary.
  • Familiarize yourself with Bash Command History to recall and reuse previous commands efficiently.
  • Leverage Bash Tab Completion to speed up command typing and reduce errors.

Mastering these basic Bash commands is essential for efficient command-line operations. As you become more comfortable, explore advanced features like Bash Pipes and Bash Input/Output Redirection to enhance your command-line productivity.