Search
ls
cd
pwd
mkdir
cp
mv
rm
touch
man
cat
find
grep
wget
unzip
echo
|
>
»
clang -Wall -pedantic -std=c99 printf.c -o main
Implement programs in exercises and programming Projects of Chapters 2 and 3 of the K.N. King textbook.
During presentation, professor Krajník recommended you some books. You should buy them in your favourite bookstore. You should not use your new gained skills and download some pirated pdf using for example:
pdf
$ wget http://datasets.chronorobotics.tk/s/S8kZk5fhIANDKBu/download -O cpl_recommended_book.pdf
.
Manual to (almost) every terminal program can be found using man:
$ man <program>
You shoud start working in linux terminal by asking, how to use manual
$ man man
To find out, where are you in the directory tree, use pwd:
$ pwd
To list files in your directory, use ls:
$ ls
There is also possibility to see a content of different directory
$ ls <relative/absolute address>
The useful parameters you should know are:
-a
-A
-l
-p
-S
-t
$ ls -Al
To change the directory use cd:
$ cd <relative/absolute address>
Go to the parent directory
$ cd ..
Go to the parent's parent directory
$ cd ../../
Go to the parent's parent directory and then to its child directory
$ cd ../../some_directory/
Go to the child's child directory
$ some_directory/some_subdirectory/
You can use absolute address:
$ /home/my_account/my_files/my_video/
There is also trivial way to your home directory:
$ cd
The manual is not presented, therefore use parameter –help to find out more
–help
$ cd --help
For fast navigation, use keypad Tab. Use it frequently.
If you want to create a directory, use mkdir:
$ mkdir <directory name>
and touch for file creation:
$ touch <file name>
Please, do not use spaces in your names:
$ mkdir "I have come here from some advertising environment called Windows" $ mkdir and\ I\ really\ like\ to\ troll
and if necessary, use _ underscore instead:
_
$ touch I_love_linux
Use mv for moving files or directories from one position in a directory tree to another:
$ mv <source> <destination> $ mv random_file.txt ~/random_directory/ $ mv random_directory/ ~/some_directory/some_subdirectory/
Note that character ~ stands for your home directory.
~
Use mv also for renaming the files:
$ mv obsolete_name much_better_name
Copying files can be done using cp:
$ cp <source> <destination> $ cp random_file.txt ~/random_directory/ $ cp random_file.txt ~/random_directory/better_name.txt
To copy whole directory, use -r recursive option:
-r
$ cp -r random_directory/ ~/other_directory/some_subdirectory/
You can delete file using rm
$ rm <file name>
Beware! It is very hard to undo!
Deleting whole directory and its content needs -r recursive option:
$ rm -r obsolete_directory/
It is also possible to delete file (or directory) at different position in directory tree:
$ rm ~/random_directory/random_file.txt $ rm ../../some_system_directory/some_essential_file
Please, read more about recommended terminal programs. Start with:
or
$ <program> --help
Peolple havily working in the terminal have to organize their work. One of very useful tools is a terminal multiplexer tmux.
tmux
Tmux is a tool run in the command line that allows you to do several important things. They are that you can have multiple terminals running inside one terminal, and also that you can disconnect and then reconnect to a termainal session. They can also be shared by many people.
To install tmux in Ubuntu, use a command:
$ sudo apt install tmux
Make sure, you have a root password. (It is not possible to install anything on school computers using your accounts.)
To start a tmux session, just run tmux in a command line.
Once you are inside a tmux session, to split the window into two panes, you can run tmux split-window, or for brevity, just tmux spl, to have one pane on top of the other. For them being side by side, add the flat -h (horizontal). You can do this repeatedly to have many panes. To remove one, its just like a normal terminal, so either type exit or Ctrl-D. Closing the last pane will end the session.
tmux split-window
tmux spl
-h
exit
Ctrl-D
To move between panes, press Ctrl-b, release, and then use the arrow keys.
Ctrl-b
To disconnect from a session, use Ctrl-b, release, and then press d. Note that if you don't release the Ctrl-b, this will adjust the size of the panes instead.
To reconnect, use tmux attach.
tmux attach
To open a new window, use Ctrl-b, release, and then press c. You will see all your windows numbered across the bottom. To move between them, use Ctrl-b, release, and then press the number corresponding to that window.
To scroll inside a window, use Ctrl-b, release, and then press [. Use Ctrl-c to go back to the normal terminal mode.
Ctrl-c
If you want to know more beginner's stuff, try this guide.
If you are not interrested in learning, try babtism by fire.
There is a plenty of text editors with different approaches and sets of tools. One of the most favourite ones is Vim. Vim is terminal-based text editor useful for programming on remote machines or through SSH onto a robot.
Vim
SSH
To install Vim in Ubuntu, type this command:
$ sudo apt install vim
To start editing a file, use:
$ vim <file name>
It is also possible to create and start editing a new text file:
$ vim new_file.txt
Vim has three different modes: normal (or command), typing, and visual.
You enter the insert mode by pressing 'i'. Then you can type normally onto the text. Go back to normal mode with esc. From normal mode, you can, for example, search through text by pressing / and then typing.
esc
/
To quit, make sure you're in normal mode (press esc), and then type :q. To save your changes :w. You can combine these using :wq, or quit without saving by :q!.
:q
:w
:wq
:q!
There is a huge amount of commands that helps experienced programmer to code efficiently. But Vim is also known for its steep learning curve. Before your final decision whether to code like a grown man or to stick with gedit, go through few links or read blogs from some enthusiasts.
gedit
Before using, we would recommend creating a file in your home folder called .vimrc, and adding this to it to add some nice defaults:
.vimrc
set number set autoindent set expandtab set tabstop=4 set shiftwidth=4 syntax enable set encoding=utf-8 "alternatively, you can try these "status bar set laststatus=2 "highlight search set hlsearch "turn off hlsearch by pressing backslash nnoremap <Bslash> :noh<CR><C-L> "distance to editing line set relativenumber
Do you feel overwhelmed? Try this game!
If you do not like reading manuals, try cheatsheet!