Home Download Ubuntu

Short command line tutorial in Ubuntu server

When you're just starting to work in command line (CLI), you will find yourself frustrated, because all the command you need to input to actually do something. But there are a some commands in terminal which will improve your experience.

1. To see the last commands for your username:

history


history introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly.
it saves the last x commands in a file called .bash_history (it's hidden, so you need to ls -al to see it) and is located in your home directory.

2. To move through the last commands:

you can move through the last input commands, by using:
a. up/down arrow keys - up is for previous and down is for next
b. ^p (CTRL+P) and ^n (CTRL+N) stands for previous and next

3. autocomplete:

yes, there is an input autocomplete in CLI. the magic key is TAB. you can use it by typing the first letters of a command or a file, then press TAB and it will complete your command or file.

to move to /var/www/ directory:
a. type cd /v and press TAB. you will have now cd /var/
b. type b and press TAB. you will have now cd /var/www/

4. sudo bang-bang:

as described in one of the previous tutorial, you can use the sudo !! command to have permission over a command, which you wrote without the sudo in front.

let's say your command was nano /var/www/index.php and your not the owner. you will receive a text, telling you that you don't have permissions to access that file. now you can enter sudo !! command.

5. CTRL+R:

this command is very usefull when you wanna find a past command. Just press ^r (CTRL+R) and start typing part of a command and you will see the suggestions.

0 comments:

Post a Comment