After opening your terminal emulator of choice, you will see
Command prompt
user_name@computer_name:current_directory$
For example,
some_name@laptop:~$
Things to remember:
~
means home directory, so it is an alias to /home/some_name
.
/
means root directory.
.
means current directory.
..
means parent directory.
Running commands
Commands always consist out of a command name and arguments, delimited by space. Try the following, it will open a desktop pop-up:
notify-send Summary Body
and press Enter.
Many special characters have side effects, so if your arguments contain anything besides simple letters and numbers, better wrap them in single quotes:
notify-send 'Some summary with spaces' 'Body with some special chars !@#$%^&*()_'
You can press Tab while typing for autocompletion.
You can press Up and Down for navigating through your previously typed commands.
Interrupt command
Most commands finish immediately, but some are long-running, e.g.
sleep 1000
You can interrupt any running command by pressing Ctrl+c. In rare cases, it's q or Ctrl+d or typing :wq
(saving changes). If nothing helps, close the window or kill the process using task manager.
Copy paste
If you are accustomed to Ctrl+c/Ctrl+v being copy/paste keybindings, you cannot use them like this. You have to use the mouse or use the terminal emulator's special keybinding (typically Ctrl+Shift+c). Please be careful with pasting random online commands. The terminal has full control over your entire system.
List of commands you need
There are hundreds of commands available, and thousands more you can install.
From all of these, you will very likely need the following:
cd [path]
changes current directory. For example, go up one directory up:cd ..
or go to tmp folder:cd /tmp
ls -hal
lists all files in current directory. The options are optional.h
makes the command show file sizes in human-readable form,a
makes the command show hidden files as well (those starting with a dot.
) andl
adds various information like this:drwxrwx--- 17 username username 4.0K Jul 14 17:38 filename
d
means it is a directory,rwx--- 17 username
is mostly permission stuff and probably not relevant to you,4.0K
means it is 4 KB in size, andJul 14 17:38
is the last modification date.sudo
executes a command with root user permissions. Be careful when using this. E.g.sudo apt-get install nvidia-latest
If you want to know how to edit files, read files, move files, copy stuff, format text etc., check out other tutorials. You want to do that using graphical tools anyway.
Running scripts
Commands like notify-send
and sleep
are installed globally. You can also run local scripts by supplying their path. E.g. run a script called some-script
in the current directory:
./some-script.sh
Scripts are marked as not executable
by default. You can make it executable: Most file managers support that via right click. Alternatively in the terminal, run chmod +x filename
.
For repeated actions, you can even create scripts yourself: Simply write commands into a file.
Special characters
Just for reference, here are some commonly used special character meanings:
#
adds a comment (if proceeded by a space), e.g.echo "ab" # "cd"
only printsab
$
refers to variables, e.g.myvar=hello
andecho $myvar
|
"pipes" the output of one command to the other, e.g.echo "ab" | rev
printsba
>
redirects output into a file, e.g.ls -hal / > myfile.txt
writes the output of ls into a file.
,..
,~
(explained above)&
runs a command in background, e.g.sleep 10 &
runs the command but you can keep using the terminal;
delimiter for multiple commands, e.g.echo 1 ; echo 2
. Same as line break in between.&&
"and"-delimiter for multiple commands, e.g.ls /nonexisting/directory && echo 'success'
The second command will only be called if the error code of the first one was zero (success)||
"or"-delimiter for multiple commands. The second command will only be called if the error code of the first one was non-zero (failure)
Notes
~
cannot be used inside quotes- There are also double quotes
"
. These work similar to single quotes'
but some characters, most notably dollar sign$
, preserve their special functionality
Further reading
If you are interesting in learning more about Bash (scripting), check out Linux Fundamentals, it is a nice incremental guide by Philip Carinhas and much more concise than most others. It was written 2001 but virtually nothing has changed (not a joke), except ignore tcsh and that for text editing, your best bet will be to install the user-friendly micro
command line editor instead of using vi
.