Basic first
You can use up arrow to go to previous command.
If your system does not support up/down arrow key, you can use Ctrl-p or Ctrl-n.
reset
to reset.
Ctrl-c to break off command.
Read the docs
man
for getting help. E.g. man ls
to see info about ls
user commands.
Then press space
to move down, press b
to move up. /
for search, write the word then enter, n
to find next occurs.
q
to exit.
Anatomy of a command
- Words seperated by spaces
- First word: the command to run
- Other words: arguments
- Options are arguments starting with -
- It changes behavior of the command
Some for user interface:
Space bar
to move down,b
to move up a page./
for search,n
for next match.q
for quit.
Some commands
Navigate filesystem
pwd
: path to work directory.
ls
: list contents. ls -a
: list all files including hidden. ls -l
: long format.
a
and l
above called options. You can combine both by using ls -a -l
or just ls -la
.
cd somePathToDir
: change directory by go somePathToDir.
cd
: go to home directory.
To get the suggestion when cd
, use tab. E.g. in bash:
$ cd D# then hit tab twice
# shows all directories start with 'D'
Desktop/ Documents/ Downloads/
$ cd Doc# then tab
$ cd Documents/
With zsh, you only to tab once to show all suggestions, then continue to tab to choose the directory.
Work with text files
touch file1 file2
: create empty files.
If you want space in filename, use single quote or backlash \
escape
mkdir someDir
: create directory.
rm someFile
: delete file permanently.
List files
cat someFile
: show content of someFile. Use less someFile
if the file is large & complex (then you can use space
and b
to move around, etc.).
file someFile
: info of someFile.
open someFile
: open a file (macOS).
Edit with Nano
nano someFile
, it will show some instructions at bottom.
Edit with Vi
vi someFile
.
Vi has different modes:
- Command mode (default):
X
: delete a character.DD
: delete whole line.:
(shows:
at the bottomU, then do below before enter:w
: write (save file's changes).q
: exit vi.q!
: exit without saving changes.wq
: write and exit.
- Insert mode:
- Press
i
to enter this mode (at the bottom shows-- INSERT --
). - Press
esc
to exit this mode.
- Press
Case sensitivity in filenames
Default filesystem on macOS is not case-sensitive.
Characters to avoid:
- Quotes:
`` ' "
- Brackets, parens:
{} () <> []
- Interpunction:
! ? & | : ; \ ^
- Other:
$ @ ~ * #
- Whitespace: tab delete backspace newline
Log in to another system using SSH
ssh someLinuxServer
The prompt will also change corresponding to the session.
exit
, logout