50+ commands ChatGPT thinks you should know about Terminal aka Command Line
TL;DR
Hey there and happy Wednesday* 👋
*a day on which, historically, most people wed on; thus: Wed nes day
Not really, but it would be a fun fact actually 🙂
OK, back on point; in this post, I’m going to take you through the basics of using the Terminal aka (as the cool kids using Windows call it) the Command Line. We’ll cover some basic commands, why it’s super useful, and how you can start flexing your command line muscles in no time!
Reality Check
Nowadays, on your first day at a new tech job, you probably aren’t going to be asked to ‘just SSH into the server and deploy the latest build.’. However, that doesn’t mean that knowing the basics of moving around the Linux system is something you shouldn’t learn. If nothing else, it’ll give you additional knowledge; and that’s why you came into this industry, right?
Great, then let’s go 💪
Why Terminal, You Ask?
Yes, the command line can seem intimidating with its blinking cursor and lack of buttons, but it’s really not that scary. Think of it as a conversation with your computer – you just need to know the right words.
Installing the Terminal 😏
Usually, you don’t need to install it; it comes with your operating system. But if you’re on Windows, you might want to look into installing something like Git Bash or PowerShell for a better experience. Or, better yet (if you don’t have a Linux server handy), try it out in a sandbox…
Experimenting in the Sandbox
The best way to learn is by doing. Don’t be afraid to experiment with commands.
The worst that can happen? You might delete your whole system 🙂. So, I suggest using something like https://cocalc.com/ (there are many more options like this, Google them) to test it out in a so-called sandbox environment.
Essentials
1. Opening the Terminal
First things first. To start using the Terminal, you need to open it. On macOS, you’ll find it in Applications > Utilities
. Windows folks, look for Command Prompt
or
PowerShell`. Linux users, you probably already know what you’re doing 🙂
2. The Basic Commands
- pwd (Print Working Directory)
- This command tells you where you are. It’s like asking, "Hey Terminal, where the heck am I in this file system maze?"
- You’ll get an output something like:
/home/nikola
- ls (List)
- Want to know what files are lurking in the current directory? Just type
ls
. It’s like peeking into a room to see what’s inside.
- Want to know what files are lurking in the current directory? Just type
- cd (Change Directory)
- Need to move around? Use
cd
followed by the directory’s path. It’s your ‘teleport’ command. - If you press ENTER after just the
cd
command, it will place you in your home directory (/home/nikola
in my case)
- Need to move around? Use
- mkdir (Make Directory)
- To create a new folder, use
mkdir
followed by the name you want to give it. It’s like conjuring a box out of thin air. - For example:
mkdir newFolder
- To create a new folder, use
3. Editing and Viewing Files
- touch
- Create an empty file; for example:
touch file.md
- Create an empty file; for example:
- nano, vim, or emacs
- These are text editors available right in the Terminal. It might not be as fancy as your VS Code, but it gets the job done. For example, to open the file
file.md
typenano file.md
- If you’re really just starting out, go with
nano
, or be lost in vim forever - Jokes aside, there’s a certain level of satisfaction and productivity among folks that master vim
- These are text editors available right in the Terminal. It might not be as fancy as your VS Code, but it gets the job done. For example, to open the file
- cat (Concatenate)
- Want to quickly view the contents of a file?
cat
followed by the file name will display it for you. No need to open it in an editor. - Example:
cat file.md
- Want to quickly view the contents of a file?
4. File Manipulation
- cp (Copy)
- Use this to copy files or directories.
- Example:
cp file.md file-copy.md
- mv (Move)
- Use this to move or rename files or directories.
- Example:
cp file.md file2.md
- rm (Remove)
- ⚠️ Be careful with this one as it deletes files or directories. There’s no going back, so use it wisely!
5. Getting Help
- man (Manual)
- Stuck with what a command does? Type
man
followed by the command, and you’ll get a detailed manual. It’s like asking for directions. - Example:
man ls
will give you all the info about thels
command
- Stuck with what a command does? Type
6. The Power Moves
- echo
- output to the console whatever you put in quotes
- Example:
echo "testing"
will output ‘testing’ to the console output
- >
- redirect the output of a command to another file or program
- Example:
echo "testing" > file.md
will overwrite thefile.md
with the word ‘testing’ - If you want to append, instead of overwrite, use >>
- grep
- This command lets you search through files for specific text. It’s like having a searchlight.
- Example:
grep 'testing' file.md
- | (Pipe)
- This symbol is used to take the output of one command and use it as the input for another. It’s like connecting Lego blocks to build something cool.
- Example:
ls | grep "myFile"
- this command sequence will list all files and directories, but only display those whose names include "myFile".
7. SSH and Remote Servers
- ssh (Secure Shell)
- This is how you remotely log into another machine. It’s like teleporting to a different computer.
- Example:
ssh -p port_number username@remote_host
8. Understanding File Paths
File paths can be tricky for beginners. Remember, there are absolute paths (which start from the root directory aka /) and relative paths (which start from your current directory). For example, /Users/nikola/Documents
is an absolute path, while Documents
from your home directory is a relative path.
If you’re currently positioned in /var/www
, then doing cd Documents
will probably give you an error that the Documents
folder doesn’t exist. However, if you use the full path (cd /Users/nikola/Documents
), it will work.
9. Advanced File Operations
- find
- A powerful tool for searching files and directories. It’s like having a GPS for your files.
- Examples:
find . -name "filename.txt"
– find files by namefind /path/to/search -name "*.txt"
– find files with a specific partternfind /path/to/search -size +100M
– find files based on sizefind /path/to/search -perm 644
– find files with a certain permission
- locate
- Used for finding the location of files and directories
- Example:
locate filename.md
10. Networking Commands
- ping
- Check if you can reach another computer or server.
- Example:
ping example.com
- curl
- Fetch data from or send data to a server, especially useful for testing APIs.
- Examples:
curl http://example.com
– fetch a web pagecurl -O http://example.com/somefile.zip
– download a filecurl -d "param1=value1¶m2=value2" -X POST http://example.com/form
– send POST datacurl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://example.com/api/login
– pass headerscurl -b "name=value" http://example.com
– use cookies
Additional things that could be useful to you
11. Exploring Environment Variables
- Environment variables are key-value pairs used by your operating system to manage various system properties. They come in handy for storing data like file paths and configurations.
- Example: use
echo $VARIABLE_NAME
to view the value of an environment variable, andexport VARIABLE_NAME=value
to set one.
12. File Compression and Archiving
- tar, gzip, zip
- These commands are used for compressing and decompressing files. They are crucial for managing file sizes and preparing data for transfer.
13. Remote File Transfer
- scp (Secure Copy)
- A command for securely transferring files between your local machine and a remote server. It’s like FedEx for your files.
- Example:
scp username@remote_host:/path/to/remote/file.txt /path/to/local/directory
- rsync
- A utility for efficiently transferring and synchronizing files across computer systems.
- Example:
rsync -av /path/to/local/dir username@remote_host:/path/to/remote/dir
14. Monitoring Disk Usage
- df
- Displays the amount of disk space used and available on your file systems.
- du
- Estimates the space used by files and directories.
15. Managing Processes
- ps
- Reports a snapshot of the current processes.
- kill
- Send a signal to a process, typically used to stop a process.
16. Networking and Port Management
- netstat
- Displays network connections, routing tables, and interface statistics.
- ifconfig
- Used to configure, or view the configuration of, a network interface.
17. Exploring System Logs
- Logs are a goldmine of information. Use cat or less to view log files typically stored in /var/log and understand what’s happening under the hood.
18. Crontab for Scheduling Tasks
- crontab is used for scheduling tasks to run at specific times. It’s like setting a smart alarm for your scripts.
- Examples
- with
crontab -e
command, you’ll be able to edit the crontab file - if you want to run a script
/path/to/script.sh
every day at 5:30 PM, you would add the following line:30 17 * * * /path/to/script.sh
19. Command History
- Your Terminal remembers your past commands. Use the
history
command to recall previous commands orCtrl + R
to search through your command history interactively.
20. Linking Directories with Symbolic Links:
- ln -s
- create symbolic links to files and directories. It’s like creating shortcuts.
- Example:
ln -s /path/to/original.txt /path/to/link.txt
21. Managing Users and Groups
- useradd, usermod, groupadd
- These commands are used for creating and modifying users and groups. They’re important for managing access on multi-user systems.
22. Disk Partitioning and Mounting
- fdisk, mount
- These commands are for managing disk partitions and mounting filesystems. They’re essential for organizing and accessing different storage devices.
23. Networking with nc and telnet
- nc and telnet
- These tools can be used for various network operations like port scanning, sending raw data to ports, etc.
24. Advanced Text Processing
- cut, sort, uniq, tr
- These text-processing commands are powerful tools for data analysis and manipulation in the command line. Check them out
25. System Information Commands
- uname, lscpu, lshw
- These commands provide detailed information about your system’s hardware and software configuration.
26. Learn/Customize Terminal Shortcuts
- Learn keyboard shortcuts for your Terminal for efficiency.
- Examples:
- Ctrl + A to go to the beginning of the line
- Ctrl + E for the end
- Ctrl + K to delete from cursor to the end
27. Checking System Health and Resources
- vmstat, iostat
- Use these commands to monitor system performance and resource utilization.
28. Exploring System Services and Daemons
- systemctl, service
- These commands help you manage system services and daemons in Linux.
29. Filesystem Check and Repair
- fsck
- Check and repair Linux filesystems. It’s an essential tool for system maintenance.
30. Securely Deleting Files
- shred
- Securely delete files from your filesystem so that they are nearly impossible to recover.
13 additional things you could look into
- Customizing Your Terminal
- You can customize the look and feel of your Terminal. Play around with .bashrc or .zshrc (depending on your so-called shell) to change your prompt, add aliases for commands, or even add some fun colors.
- Or, just install Oh My ZSH!
- Scripting and Automation
- Once you’re comfortable, start exploring shell scripting. You can automate repetitive tasks with simple scripts, making your life a whole lot easier.
- Version Control with Git
- The Terminal is a friend of Git, a popular version control system. Here’s one tutorial I wrote: Learn Git fast as if your job depends on it
- Understanding Permissions
- Files and directories have permissions that determine who can read, write, or execute them. Commands like chmod and chown help you manage these permissions.
- System Information and Monitoring
- top or htop
- These commands give you a real-time overview of what your system is up to. It’s like a dashboard for your computer’s engine.
- Working with Text
- awk, sed
- These are text-processing utilities. They’re complex but incredibly powerful for manipulating text files.
- The Power of Wildcards
- Learn how to use wildcards (*** and ?**) for matching file patterns. It’s like casting a net to catch specific files.
- The Almighty Root User
- Be cautious with the sudo command – it gives you root (administrator) privileges. With great power comes great responsibility.
- Package Management
- Get familiar with package managers like apt for Ubuntu or brew for macOS. They are like app stores for your Terminal.
- Understanding Filesystem Hierarchy
- Explore the standard filesystem hierarchy in Linux/Unix systems (/etc for configurations, /var for variable files, /home for user directories). It’s like learning the layout of a new city.
- Understanding the Root Directory Structure
- Each directory under / (root) in Unix-like systems has a specific purpose (/bin for binaries, /lib for libraries). Knowing this structure helps you navigate the filesystem more efficiently.
- Exploring Regular Expressions
- Regular expressions are patterns used to match character combinations in text. They are a powerful tool in command-line text processing.
- Exploring Different Filesystems
- Learn about different filesystems (ext4, NTFS, FAT32) and their characteristics.
Conclusion
There you have it – an extensive beginner’s guide to the Terminal, pushing well past the basics.
Remember, it’s all about practice and exploration. The command line is a powerful tool in your developer toolkit, so embrace it, play with it, and watch as your computer skills reach new heights.
Welcome to the club of command line aficionados, and as always, happy coding! 💪
Leave a Comment