The basic terminal commands for navigating and manipulating directories and files are as follows:
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
Use the pwd
command to display the current directory:
pwd
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
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 ..
To create a new directory:
mkdir newDirectoryName
To delete an empty directory:
rmdir directoryName
To create a new empty file:
touch filename.txt
To delete a file:
rm filename.txt
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!