Do not fear the terminal
I started using Linux last year at my current place of work. I had heard about the OS for a long time, but nothing ever spurred me over to switch until my boss recommended it, saying it was the industry standard for software development. Until that time, I was a lifelong tech-native, GUI-comfortable Windows user.
A central part of Linux operating systems is the command line. I remembered seeing my dad type commands on his DOS computer back when I was a kid, and had used a few in my coding bootcamp:
git pull
git add -A
git commit -m "write your message here"
git push origin main
npm -i
node
I had used these, but I didn't really understand them, and I didn't feel comfortable modifying them in any way. If I ever got an error from one of them I panicked and went online, hoping to find someone to gently walk me through my problem!
If the online help article got into things like flags, path variables, environmental variables, and permissions, panic set in as I felt like I was way out in the deep end of arcane computer science and could only struggle to stay afloat.
But on day in my internet searching, I found a book which has been making all the difference for me: The Linux Command Line, by William Shotts.
It's a walkthrough for people totally new to Linux who want to learn how to use their computer in a much more sophisticated way. You can buy a paper copy, but it is also available as a pdf completely for free at https://linuxcommand.org/tlcl.php!
(And if you have Windows or Mac, it's even possible to run Linux virtually on your machine within VS Code! You don't have to install the new OS to start out. There are plenty of tutorials available on youtube.)
One of the first important things I learned from this book is the structure of a command. In fact, most commands fit the following format:
command -options arguments
Where you see "command", that is the name of a program. After you name the program you want to use, there may be a series of options (or "flags") you can add to the command. These start with one or two dashes, like -A or --force. For example with git add, -A tells it to add all files which have been modified to the staging area. The "arguments" portion of the command is further information you need to supply to tell the command what to do. Thus, instead of writing git add -A, you could write git add file1 to tell it to only add "file1" to the staging area.
This knowledge demystifies a lot of commands! When you write git push origin main, you are telling your terminal to first use the git program, then specifically to do a git push, then you are telling it to push to the main branch of the origin remote.
Another one to experiment with is ls. This lists the contents of the folder that you are in. When you write ls, you are telling your terminal to use the "ls" program, which then reads and displays all the files in your current directory.
However, some folders may have hidden files. You can view these files by typing
ls -a
The -a flag tells your terminal that you want to see "hidden" items as well. When you run this command, you may see some new entries listed in the folder that you are in. Hidden files and folders all start with a period, so you might see something like .profile or .bashrc.
However, you can also use ls to view files of other directories. Imagine that you are in your home directory, and you want to view the contents of the "Documents" folder inside your home directory without navigating to it. In this case, you can pass the argument "Documents" to the ls command:
领英推荐
ls Documents
This will then tell you everything in that folder, but leave you right where you are! There are a lot more options to explore with that program! I recommend reading more about it in the book mentioned above.
One last cool thing I'll mention is alias. An alias for a person is a name which they go by. For example, the musician Robert Allen Zimmerman has performed for decades with the alias of "Bob Dylan." Well you can "rename" commands on your machine just as well!
For example, let's imagine that you find yourself writing over and over git push origin main. Same thing over and over. Even though it's not that much time to type, eventually you might wonder, isn't there an automatic way to do this?
Well, there is! You could make an alias for that command and call it, say gpom. To do this, you can just enter the following:
alias gpom='git push origin main'
This uses the alias program to create a new shorter command that your terminal will recognize! Now when you type gpom, the terminal will recognize that alias and run the command git pull origin main! That's pretty cool! As you get more advanced, you may find there are even more complicated commands and processes that you want to run repeatedly. Rather than having to remember the specific flags for those commands, or type the same long strings over and over, you can just make a quick alias and be done with it!
Remember how we said that all the things that come after the command name are options and arguments? Well what if we run the alias command without any arguments and options?
alias
If you do this, you'll get back a list of already defined aliases, and you may be surprised at what some of them are.
For example, on my terminal, I get this list:
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
Thus, some commands have already had aliases made for them. There appear to be several for something called "grep", and some big complicated thing about an alert.
And, surprisingly, there at the bottom, we find that ls itself is an alias! In this shell, ls has been aliased to call the ls program with a color=auto flag! So you have already been using an aliased command without knowing about it! There are other similar aliases already made for ls with different options. Thus, we could simply type la instead of ls -A any time we wanted a list of all files in our current directory.
I highly recommend all new developers get that book and read it. You'll become much more knowledgeable about how your computer works, comfortable with changing things, and impress your boss and coworkers to boot!