An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
Bash commands introduction
I just learned about some basic terminal commands and it was a great experience!
It might not be as instinctive as a graphical user interface, still there are some good reasons to start using your terminal.
High performance
Real control of what is happening under the hood
Task automation
Note: We will only walk through the basic commands of Linux/macOS terminal.
Get started
If you are using Linux or macOS as your operating system, you are very likely to use bash shell which is the most widely used shell.
Once you opened up your terminal, should have something that look like this:
Navigation
The cd (change directory) command lets you navigate through your computer's file system.
# Go to target foldercd /target# Go to parent foldercd ..# Go to home foldercd ~
List
The ls (list) command print files and directories.
# Print files located in the current directory.ls# Print files located in the target directoryls targetparent/target
Options
You can add some options to most of existing commands by simply appending your command with -[option]
For example:
# Print files located in the current directory with more details.ls -l# Print every files located in the current directory (hidden files as well).ls -a
Make/remove file or directory
The mkdir (make directory) command create a new directory.
# Make a new directory in current directory.mkdir directoryName
The touch command create a new file.
# Make a new file in current directory.touch fileName
The rm/rmdir (remove) commands delete file/directory.
# Delete an empty directory.rmdir myDirectory# Delete a file.rm myFile# Delete a directory recursively.rm -r myDirectory
Where am I?
The pwd (print working directory) command display your current location.
# Display current location in terminal.pwd
File management
The cp (copy) command lets you copy and paste your files.
# Create a copy of a file to target location.cp myFile target/
The mv (move) command moves a file to another location OR rename it if you stay in current directory.
# move file to target location.mv myFile target/# rename file.mv myFile newName
Read/Edit file from the terminal
The head/tail commands print a part of the file.
# Print 10 first lines of a file.head myFile# Print 10 last lines of a file.tail myFile# Print 30 first lines of a file.head -n 30 myfile
The cat (concatenate) command can print content of a file, concatenate multiple files together, create and edit files, ...
# Print content of a file in terminal.cat myFile# Print content of a file with numbers.cat myFile -n# Combine multiple files ogether.cat fileOne fileTwo > target
Search
The grep (get regular expression) search for a given expression.
# Look for a word in a file.grep word fileName# Look for a word in a file without case sensitivity.grep -i word fileName
Here is my personal cheat sheet for bash commands!
Thank you for reading
Original Link: https://dev.to/killianfrappartdev/bash-commands-introduction-13e7
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To