Skip to content

bash Linux command

The bash command is a critical tool in the Linux operating system, allowing users to interact with the shell to execute commands. It provides a versatile way to navigate directories, manipulate files, and automate tasks. By mastering the bash command, users can improve their productivity and efficiency in managing their system. With its wide range of features and capabilities, bash is an essential tool for both beginners and experienced users in the Linux environment.

bash Syntax:

Terminal window
rsync [option] [source] [destination]

Options:

OptionDescription
-aArchive mode
-vVerbose mode - increase verbosity
-zCompress file data during transfer
-rRecursive transfer
-uSkip files that are newer on the destination
-hOutput numbers in a human-readable format

Parameters:

ParameterDescription
sourceSpecifies the source file(s) or directory
destinationSpecifies the destination directory or location

Linux bash Examples:

List Files in a Directory

Terminal window
ls

Displays a list of files in the current directory.

Create a New Directory

Terminal window
mkdir new_directory

Creates a new directory with the name “new_directory”.

Copy a File

Terminal window
cp file1.txt file2.txt

Copies the file “file1.txt” to a new file named “file2.txt”.

Display Current Date and Time

Terminal window
date

Shows the current date and time.

Search for a Specific String in a File

Terminal window
grep "search_word" file.txt

Searches for the word “search_word” in the file “file.txt”.

Remove a File

Terminal window
rm unwanted_file.txt

Deletes the file named “unwanted_file.txt”.

How do I use bash in Linux?

To use the bash command in Linux, execute the following command:

Terminal window
bash

How can I run a script using bash in Linux?

To run a script using bash in Linux, use the following command:

Terminal window
bash script_name.sh

How can I change the default shell to bash in Linux?

You can change the default shell to bash in Linux by running the following command:

Terminal window
chsh -s /bin/bash

How do I check the version of bash installed on my system?

To check the version of bash installed on your system, you can use the following command:

Terminal window
bash --version

How do I execute a command in the bash shell and then exit?

To execute a command in the bash shell and then exit, you can use the following command:

Terminal window
bash -c "command_to_execute"

How do I create an interactive bash shell session?

To create an interactive bash shell session, simply run the following command:

Terminal window
bash -i

How can I use bash to redirect standard output and errors to a file?

You can use the following command to redirect standard output and errors to a file using bash:

Terminal window
command_name > output_file 2>&1

How do I set environment variables temporarily in a bash session?

To set environment variables temporarily in a bash session, you can use the following command:

Terminal window
export VAR_NAME=value

Applications of the bash Command

  • Running commands in the terminal
  • Writing and executing shell scripts
  • Automating tasks through scripts
  • Managing files and directories in the Linux system
  • Navigating and manipulating the file system