Your Go-To Guide for Common Linux Commands
Master the Linux Command Line: A No-Nonsense Guide to Upskilling
It's easy to forget how much technology has evolved. We're so used to navigating computers with colourful graphics and intuitive mouse clicks. But before all of that, there was the command line.
Imagine a time before fancy user interfaces. How did people create, save, or edit files? They used the command line interface (CLI) – a tool that allowed them to interact with their computers by typing commands.
While grahical user interfaces (GUIs) have made computing more accessible, the command line remains relevant, especially for engineers. It offers a level of precision and control that's hard to beat. Think of it like this: a GUI is like driving a car with automatic transmission, while the CLI is like driving a manual. You have more control and understanding of what's happening under the hood.
So, why should you care about what programmers and techys used in, what feels like ages ago? Because those command-line skills are still vital today. Mastering the CLI can make you a more efficient and effective engineer.
In this weeks newsletter, we'll explore some essential commands to boost your command-line journey.
Terminal Commands
Essential Terminal Commands
1. alias
This command lets you create shortcuts for frequently used commands.
Syntax:
alias [name]='command'
Example:
alias hi='echo Good Morning'
Now, typing hi
in your terminal will print "Good Morning". To list all aliases, simply type alias
. To remove an alias, use unalias [name]
.
2. rm
rm
stands for remove. It deletes files permanently.
Caution: This command is not declarative; it won't ask for confirmation before deleting.
Safer alternative:
rm -i
prompts you before deleting a file.Pro tip: Create an alias like this:
alias rm='rm -i'
to always enable the prompt and prevent accidental deletions.
3. at
This command allows you to schedule tasks to run at a specific time.
Syntax:
at time [date] commands
Example:
at 10.44 -f test1.sh > out1
This runs the scripttest1.sh
at 10:44 and redirects the output to a file namedout1
.To list scheduled jobs:
at -l
To remove a scheduled job:
at -r [job_no]
Creating files
4. cat
This command displays the contents of a file in the terminal.
cat -n
: Shows line numbers.cat -A
: Shows all characters, including hidden ones like end-of-line markers.
5. more
This command displays the contents of a file one screen at a time, making it easier to read long files.
6. touch
This command creates an empty file.
7. nano
and vim
These are popular text editors within the terminal. nano
is generally considered more beginner-friendly, while vim
is known for its power and flexibility.
Navigating your directory
8. cd
This command changes your current directory.
cd
: Takes you to your home directory.cd /
: Takes you to the root directory.cd ~/folder1/folder2
: Navigates to a specific directory path.
9. pwd
This command displays your current working directory.
10. cp
This command copies files or directories.
11. ls
This command lists the files and directories in your current location.
ls -a
: Shows hidden files (those starting with a dot).
12. cmp
This command compares two files.
cmp -b
: Prints the differing bytes.cmp -l
: Outputs byte numbers and differing byte values.cmp -s
: Suppresses output; useful in scripts.
File permissions
Every file has permissions that control who can read, write, and execute it. These permissions are set for the user, group, and others. Understanding file permissions is crucial for system security.
For each set, the file permission is represented by a 3 bit binary number
Most significant bit == read 1
Middle bit == write 0
Least significant bit == executable 1
Conclustion
This is just a glimpse into the world of command-line interfaces. There are countless other commands to explore and master. Embrace the CLI, and you'll unlock a new level of efficiency and control in your computing experience.
Thank you for taking the time to read my journey! This newsletter was deliberately kept short to avoid overwhelming you with information. If you enjoyed it, I encourage you to consider subscribing and leaving a comment with your thoughts. I'd love to hear what topics you’d like to see explored in future editions!