Skip to content

Instantly share code, notes, and snippets.

@UtkarshYadav01
Last active December 28, 2024 02:40
Show Gist options
  • Save UtkarshYadav01/b4cd47a258585848c333a27d9cc28bb2 to your computer and use it in GitHub Desktop.
Save UtkarshYadav01/b4cd47a258585848c333a27d9cc28bb2 to your computer and use it in GitHub Desktop.

Bash Terminal Commands

The basic terminal commands for navigating and manipulating directories and files are as follows:


File Content Commands

cat Command

The cat (short for concatenate) command is used to display the contents of a file in the terminal. It can also be used to concatenate multiple files into one. By default, it outputs the contents of the file(s) to the terminal.

# Display the contents of a file
cat filename.txt

# Display the contents of multiple files
cat file1.txt file2.txt

# Concatenate files into a new file
cat file1.txt file2.txt > combined.txt

Navigation Commands

Print Working Directory (pwd)

Use the pwd command to display the current directory:

pwd

List Files (ls)

Use the ls command to list the contents of the current directory:

# Simple list
ls

# Detailed list with more information
ls -l

# List including hidden files
ls -a

Change Directory (cd)

The cd command is used to change directories:

# Go to a specific directory
cd directoryPath

# Go to the previous directory
cd -

# Go up one directory level
cd ..

Directory Management

Create a Directory (mkdir)

To create a new directory:

mkdir newDirectoryName

Remove a Directory (rmdir)

To delete an empty directory:

rmdir directoryName

File Management

Create a New File (touch)

To create a new empty file:

touch filename.txt

Remove a File (rm)

To delete a file:

rm filename.txt

Rename or Move a File (mv)

To rename a file or move it to a new location:

# Rename a file
mv oldFileName.txt newFileName.txt

# Move a file to a different directory
mv sourceDirectory/filename.txt destinationDirectory/filename.txt

Happy Scripting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment