The terminal can be an intimidating place for anyone, like me, who has spent most of their life living in a โจGraphical User Interfaceโจ paradise.
...
For further actions, you may consider blocking this person and/or reporting abuse
touch
is actually for updating the file access or modification time. The fact that it happens to create the file if it doesn't exist is merely a convenient side effectOh shoot. My course did not share that fact. Thanks, Jon!
Thank you so much, Jon Randy! I appreciate that you took the time to comment.
I like that you use the word "commandments" instead of commands. At least these are not written in stone tablets....
It might help to mention that this goes only for POSIX compliant operating systems. Not for Powershell or DOS prompts.
But I agree that it can be daunting to start working with the terminal on UNIX/Linux/OSX/FreeBSD etc.
However, the power lies in the fact that these commands can be executed from scripts and thus you can program any flow of execution. This can't be done in a GUI without bothering setting up some advanced GUI interpretation tool. Which doesn't scale properly is mundane and error prone when the GUI changes.
The terminal hardly changes. These tools have been around for decades and decades.
To me, the productivity rises when I can automate stuff from the terminal using scripts. Heck, this is where most DevOps etc. finds its own roots.
Nice to see that even newbies dare to look into it, picking it up and even writing posts about it!
You know the sensation when you need to re-execute that very complicated command you run few days or week ago and you cannot remember anything but a word?
history | grep that-word
saved my life a lot of timeIn Bash you are also able to search in your history with CTRL+r :)
I have to remember this one, thanks
Some more very useful things on the terminal. Be ready, since these might shock you!
The
history
command has been mentioned before. It will indicate also a number in front of the commands entered. If you take this number after the exclamation mark it will execute that command again. You can evenpipe
these.Let's say from Taylor's
history
command we take entry14
and15
, to create the folder and to list the content inside the current folder:It should execute both commands (
mkdir myFolder
andls
) consecutively. The&&
is used to make sure the command ends properly first before trying to execute the next command. This is somewhat advanced Bash, but still very helpful to understand and use.Ok, another useful feature in Bash, is the
up
arrow. This way you can "browse" a bit in yourhistory
. Probably you already know this, but if not this is a God send! This way you can find the command that was working, edit it a bit and hitENTER
again to execute it. If you have to do some commands over and over again a couple of times with some slight changes, this helps out a lot of the repetitive and boring things. Boring means loss of concentration, loss of concentration means less fun. We don't want boring, we want productivity and results. We can do this!And never forget to use the
TAB
autocompletion functionality!For advance use of the terminal, the Z-shell (
zsh
) is quite powerful where most commands have autocompletion, syntax hightlighting and better display of common elements etc. This way, using Git will be a breeze because the autocompletion gives even suggestions to the possible arguments you might want to enter.Have fun and hack the planet!
Another neat trick you can use is
!!
to get the last command you executed before, this is pretty convenient whenever you want to execute it but with another command, example:you just used
git status
and now you want to add everything to stage and see the status you can type
git add . && !!
and the shell will "translate" it to
git add . && git status
This is very unclear on how to use
..
. It's not a command itself. If you try it, you'll just get a "command not found" error.You need
cd ..
Also,
cd
by itself will send you back to your home folder. Normally, you need to put the directory name in there:cd subfolder
I have recently started using the command line and this made me chuckle especially there 'where am i' and was extremely informative as well.
I've come across a problem I've yet to be able to fix, I wonder if you might have a solution.
When you're working with git and you're about to commit and type out a message but you forget one side of the "" around the message - my terminal goes wild and I haven't been able to figure out what to do except close and start again which is annoying.
Let's say I type git commit -m "initial commit
and press enter without closing the quotation mark I get just get
Most of the time you can just add the closing quotation mark. It might include the tailing carriage return/linefeed (\n) into the commit message, but that's not that much damage done right? You can also update the commit message, which I hardly do so I don't know how to do it without looking it up for you.
You can edit your last commit message with
git commit --amend
Have you tried
Ctrl + c
?
It should help i think
Hi Mikey, I know exactly what you're talking about and I have made the mistake of forgetting my ending quotation mark many times!
I agree with KamilZag, CRTL + C will allow you to return to the normal command line and get out of that weirdness.
I also just saw Aschwin's great explanation, yes, if you notice your error soon enough, I have found that I can add the ending " even if I've pressed enter. However, I did not know I could update my commit message, so thank you for that!
Thank you all so much for your help.
I've done it a few times and then I just end up staring blankly at the screen like 'WTF do I do' hit a few keys then close the terminal, but then I have to navigate all the way back to where I was because I don't know any other way. I contemplated Googling it but couldn't think of what to ask without writing an essay.
I appreciate the help! :)
Thank you for this article.
For me, the most indispensible commands (besides some of the ones in this article) are:
it's worth it...thumbs up
I think you've confused iTerm or Terminal.app with "terminal". Cmd-t is an iTerm (and other terminal emulator) shortcut for opening a new tab. It's not universal, and has nothing to do with the terminal itself, but rather, with the terminal emulator you're using.
These are some dope commandments, bruh. Unlike the Almighty, I shall follow you. Thanks for sharing.
No whereami,but you have whoami
alias whereami=pwd
How about "Commands newbies should never type." Or, most dangerous powerful commands.
rm (or anything with -r or -R)
chmod
chown
mv (You did mention it's use but not why to fear it.)
Nice post! My favorite is CTRL+R ๐ฅ
Nice read...it was worth it
Note: CTRL + C does not "clear" the terminal. It sends an "Interrupt" (SIGINT) signal to the current program. Also, the program can chose to ignore it.
thank you so much
A nice shortcut for exit is Ctrl+D - It is also satisfying for lazy people such as myself
I usually set IGNOREEOF=4 (or higher) due to having gotten logged out too many times accidentally. Type CTRL+D to exit an application and it seems unresponsive so I hit it again. Then it actually wakes up and I have entered two CTRL+D's with the net result being the shell getting the second CTRL+D LOL.