Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

unrigestered

Suspended
Original poster
Jun 17, 2022
879
840
relatively new Mac user here who thinks he's now become quite acquainted with the general workflow of the OS, but the terminal commands are still a complete mystery to me for the most part.

are there any good resources that can teach a complete newbie the basics?
 
thanks, i was suspecting that the terminal basically is the original UNIX OS without any GUI.
Never had any personal experience with UNIX (other than making my father angry when i tried things on his workstation when he was away and didn't know how to shut it down properly 😂)
But i was quite fit in MS-DOS once upon a time.
 
Yeah as someone that used Unix/Linux commands frequently that was a big selling point for me for moving from Windows to Mac. I've been using a terminal for so long that I don't know any good beginner tutorials.
 
I'd have a question (feeling kinda stupid asking 😳 )
when i do ls commands, is it correct that directories/folders aren't marked as such in any way?

sure, it's true that most of the time files will be having suffixes like .txt, etc. and the items listed without any suffix will be folders most of the time, but in let's say /bin/ there are files that seemingly have no suffix, making them look like a folder on a first glance

it's been a long time, but i think in MS-DOS, directories were marked with <DIR> or something like that

edit: i think i found something: ls -F does seem to indicate file and folder attributes
 
when i do ls commands, is it correct that directories/folders aren't marked as such in any way?
Not a silly question. The options for many commands are not obvious.
My goto ls command is `ls -la`.
The -l is long output - one file/folder per line. The -a is all - include hidden files. For what you want `ls -l`will do nicely.
Here is the output for a directory:
drwxr-xr-x@ 103 gilby staff 3296 30 Jul 17:32 Downloads
Notice the d at the front. The first character indicates type: d for directory, - normal file, l link/alias.
 
edit: i think i found something: ls -F does seem to indicate file and folder attributes
ls -p
From the man page:
−p Write a slash ( ‘/’ ) after each filename if that file is a directory.
−F Display a slash ( ‘/’ ) immediately after each pathname that is a directory, an asterisk ( ‘∗’ ) after each that is executable, an at sign ( ‘@’ ) after each symbolic link, an equals sign ( ‘=’ ) after each socket, a percent sign ( ‘%’ ) after each whiteout, and a vertical bar ( ‘|’ ) after each that is a FIFO.
 
  • Like
Reactions: splifingate
thanks both!

now i've found something else 🥸

when i do "clear" it clears everything on screen and puts the prompt on top of the screen as if i just started the terminal

but when i then do some commands that are producing some long-ish lists like ls, or defaults read, when i scroll up, all previous commands and lists reappear, making it a bit more difficult to navigate

is there a way that clear (or something similar) will make sure that the "history" before that command will not reappear?
 
thanks, that did it! 👍

in the meanwhile i just found out that you have to put man before the command and not the other way round like i tried before 🤦‍♂️
 
thanks, that did it! 👍

in the meanwhile i just found out that you have to put man before the command and not the other way round like i tried before 🤦‍♂️
See post 8, I find it easier to read in Preview. And you can search the text.
 
Not a silly question. The options for many commands are not obvious.
My goto ls command is `ls -la`.
The -l is long output - one file/folder per line. The -a is all - include hidden files. For what you want `ls -l`will do nicely.
Here is the output for a directory:
drwxr-xr-x@ 103 gilby staff 3296 30 Jul 17:32 Downloads
Notice the d at the front. The first character indicates type: d for directory, - normal file, l link/alias.

Good advice. There are also some "themes" you can install for your shell that will color the directories a different color so that they're immediately apparent.
 
I don’t have my Mac in front of me so I can’t check. GNU ls has that feature (like on Linux shells) but I don’t think the one on MacOS does by default. Maybe Homebrew? Not sure.
Good advice. There are also some "themes" you can install for your shell that will color the directories a different color so that they're immediately apparent.
 
Following up to this post, I just checked. MacOS 'ls' does contain the option for color output on Monterey anyway. The option is '-G'. And there's a '--color=' option where it looks like you can specify the colors for different file types. By default, directories are blue, executables are red based on the listing of my home directory.
 
  • Like
Reactions: unixfool
I don’t have my Mac in front of me so I can’t check. GNU ls has that feature (like on Linux shells) but I don’t think the one on MacOS does by default. Maybe Homebrew? Not sure.

Not by default, but the zsh has lots of themes that do it.

Following up to this post, I just checked. MacOS 'ls' does contain the option for color output on Monterey anyway. The option is '-G'. And there's a '--color=' option where it looks like you can specify the colors for different file types. By default, directories are blue, executables are red based on the listing of my home directory.

OP, another idea is to take this advice and make an alias. At the bottom of your ~/.zshrc file add something such as this:

alias myls="ls -l -G"

Then typing "myls" will get you color output of ls.
 
Thanks, great to know there are color options too, but i think I’m fine with just -F for my needs.
Will try this out though anyway 👍
 
I guess you are coming from Windows, which are quite (very?) different from UNIX-like systems like macOS. I think it will be useful to learn a few things about the UNIX philosophy before jumping into the actual programs/commands; that will give you the superstructure to put things in their places once you start learning the commands, and make things easier to remember given the historical context (e.g. why is a command called grep, why pipes not tubes, why awk etc.).

The Art of UNIX Programming is a good place to start. Brian Kernighan interviewed Ken Thompson about UNIX, pipes, grep etc., and I have watched the video many times. Brian Kernighan was in turn interviewed by Lex Fridman during which he talked about UNIX, C, AWK etc. There are also early papers about UNIX e.g. in the Bell System Technical Journal.

When it comes to functional specifics, some older titles are surprisingly useful. The UNIX Programming Environment provides an overview and written by the UNIX authors themselves. SS64 has manual-style documentation of macOS commands. Apple has quite extensive archival documentation about macOS commands. If you are willing to pay, some titles e.g. Take Control of the Mac Command Line With Terminal are accessible and handy. That should give you a flavour of how UNIX works, the most commonly used commands, the file structure, alias/symlinks, shell profiles and PATH, command syntax (command -options arguments), etc.

There are works covering individual programs (commands) in depth, such as grep and awk. (Regular expression is useful to make these commands do what you want.) You will be mind blown at just how powerful these commands are, even today (perhaps more than ever). It is also useful to check out package managers that allow you to install and update programs easily, e.g. Homebrew and MacPorts.

You can string everything together and have a blast using shell scripts. These are basically a series of commands that you program in advance and run in sequences to do things you want, and can leverage other tools and scripts in other languages e.g. Python - perfect for automation.

If you want to customise your terminal experience (hmm, that doesn't sound right), you can check out third-party terminal e.g. iTerm2.

Those are the resources I referred to when I was learning about UNIX and macOS command line. I hope that helps!
 
I guess you are coming from Windows, which are quite (very?) different from UNIX-like systems like macOS. I think it will be useful to learn a few things about the UNIX philosophy before jumping into the actual programs/commands; that will give you the superstructure to put things in their places once you start learning the commands, and make things easier to remember given the historical context (e.g. why is a command called grep, why pipes not tubes, why awk etc.).

The Art of UNIX Programming is a good place to start. Brian Kernighan interviewed Ken Thompson about UNIX, pipes, grep etc., and I have watched the video many times. Brian Kernighan was in turn interviewed by Lex Fridman during which he talked about UNIX, C, AWK etc. There are also early papers about UNIX e.g. in the Bell System Technical Journal.

When it comes to functional specifics, some older titles are surprisingly useful. The UNIX Programming Environment provides an overview and written by the UNIX authors themselves. SS64 has manual-style documentation of macOS commands. Apple has quite extensive archival documentation about macOS commands. If you are willing to pay, some titles e.g. Take Control of the Mac Command Line With Terminal are accessible and handy. That should give you a flavour of how UNIX works, the most commonly used commands, the file structure, alias/symlinks, shell profiles and PATH, command syntax (command -options arguments), etc.

There are works covering individual programs (commands) in depth, such as grep and awk. (Regular expression is useful to make these commands do what you want.) You will be mind blown at just how powerful these commands are, even today (perhaps more than ever). It is also useful to check out package managers that allow you to install and update programs easily, e.g. Homebrew and MacPorts.

You can string everything together and have a blast using shell scripts. These are basically a series of commands that you program in advance and run in sequences to do things you want, and can leverage other tools and scripts in other languages e.g. Python - perfect for automation.

If you want to customise your terminal experience (hmm, that doesn't sound right), you can check out third-party terminal e.g. iTerm2.

Those are the resources I referred to when I was learning about UNIX and macOS command line. I hope that helps!
I'd also recommend for the Apple Terminal https://ohmyz.sh
 
  • Like
Reactions: chengengaun
thanks chengengaun! 👍
i'm not sure yet how deep i really want to go into Terminal
never been a great programmer, even in the home computer days in BASIC.
stopped doing that altogether when i was trying to get into C when i got my first MS-DOS system and accepted that i'm just not intelligent enough for that kind of thing

i guess my goal is mainly being able to alter plists and stuff to make tweaks on macOS i'm not perfectly fine with, bypass some restrictions that prevent me from doing things like cleaning my system from "unnecessary" protectecd files, removing certain processes from running and starting altogether, etc., so basically stuff that the macOS UI is not good at, or too restrictive withouth blindly having to rely on internet research every time, and not cluelessly falling for some "advice from some funny guy" to "rm -rf /" when i was just looking looking for ways to prevent some background process from starting.

for most other tasks, at least for my needs, macOS is a great modern GUI centric OS that came pre-installed on my Mac too 😂

Of course i don't know where the journey will take me and what i will be requirig to achieve my goals though, so who knows 😇

regarding reading matter:
last time when i was visiting my parents, i "casually" asked my father, an ex system administrator who is now retired for 10 years, if he was still into UNIX, and to my surprise, he still is.
he gave me an old doorstopper from 1998 i think ("Linux - The Complete Reference), which should keep me busy for a while.
Didn't have much time in the couple last days though, but in the brief time i had a glimpse in, i already found something nice that you could simply use "." for the current directory in let's say copy command lines so you don't need to enter both directories in every situation, which i did in the MS-DOS days. not sure if it was possible, but at least i can't recall having been aware of that 😳

edit: scratch the last sentence... when i think about it, i believe i was using (x)copy <files> volume:\destination directory most of the time, so i basically copied outside from the current directory

to my defense, i think last time i was touching a DOS prompt was in 1995, before i started using Win 95
 
  • Like
Reactions: chengengaun
i guess my goal is mainly being able to alter plists and stuff to make tweaks on macOS i'm not perfectly fine with, bypass some restrictions that prevent me from doing things like cleaning my system from "unnecessary" protectecd files, removing certain processes from running and starting altogether, etc., so basically stuff that the macOS UI is not good at, or too restrictive withouth blindly having to rely on internet research every time, and not cluelessly falling for some "advice from some funny guy" to "rm -rf /" when i was just looking looking for ways to prevent some background process from starting.
You are most welcome! I use the sources I mentioned as references, so having them all in one message is handy for me too. One useful way of looking at hidden files e.g. plists is to display hidden files in Finder; just type Cmd + Shift + . (period) to toggle between showing and hiding the files.

for most other tasks, at least for my needs, macOS is a great modern GUI centric OS that came pre-installed on my Mac too 😂
Isn't it remarkable that one OS can cater to (almost) everyone - those who are comfortable with GUI only, to those who rely on UNIX-like functions?

regarding reading matter:
last time when i was visiting my parents, i "casually" asked my father, an ex system administrator who is now retired for 10 years, if he was still into UNIX, and to my surprise, he still is.
he gave me an old doorstopper from 1998 i think ("Linux - The Complete Reference), which should keep me busy for a while.
Didn't have much time in the couple last days though, but in the brief time i had a glimpse in, i already found something nice that you could simply use "." for the current directory in let's say copy command lines so you don't need to enter both directories in every situation, which i did in the MS-DOS days. not sure if it was possible, but at least i can't recall having been aware of that 😳
Yes, you can use . for the current directory, .. to go up one level, cd xx to go to a particular directory, cd ~ to go home (your personal directory), or cd / to go all the way to the top (usually that's 'Macintosh HD'). You can also use the 'autocomplete' feature by typing the first few letters of the file name, then press Tab to cycle through all the matches.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.