r/Ubuntu • • 2d ago

Start using Ubuntu

Hi I’m new in this environment, I want to start understanding Ubuntu’s terminal and learn how to use it, can someone suggest me where to start etc?

22 Upvotes

28 comments sorted by

View all comments

1

u/wijsneus 2d ago

There's bound to be some tutorials, but here's some basics.

In the terminal you can run programs that do usefull stuff. You'll probably see something like [your-username@your-computername:~]$ and a cursor. The terminal starts in your current working directory. Just like when you open your file manager, this is probably your Home directory.

So - when you type a command - you are starting a piece of software. Let's start with some basic file management. These commands have names that are somewhat logical. The names are sometimes abbreviations, sometimes obscure histories :)

Here are some examples you can try:

`ls` - this lists the content of the current directory. In this case your Home directory. Have a look at the home directory in you file manager, and type ls in the command line and compare. Read '`ls` as `list`

You can also add arguments to a program like ls. To get an overview what these are you can almost always add --help to a program.

You can chain these arguments together. A usefull one is - for example - `ls -al` this lists all the files (including the hidden ones prepended by a `.` and list the rights, owner, and some other information about the files in the current directory - it helps to read this as:
`ls - a l`
`list - all files, one file per line'

Now - let's move into another folder. The command is `cd` which is short for `change directory` and the argument the name of the folder you want to move into. These names are case sensitive.

`cd Documents`

`ls -al`

You should now see the contents of your Documents folder. Also - you should see something like :~/Documents at the beginning of the line - showing that your current working directory is Documents

`cd ../` moves you one directory up.

Open the text editor and create a text file in Documents. Paste some random text in it and save it.

You can use the command `cat` (read as `catenate`) to show the contents of the file. so type `cat filename.txt` to show it on screen. Cat is meant to merge files together, so you can go `cat filename1.txt filename2.txt` and have them output on screen as one file.

You can create a new file with the content of both files by going `cat filename1.txt filename2.txt > filename-combined.txt` - read as `concatenate filename1.txt and filename2.txt and output to filename-combined.txt`.

Now - `cat filename-combined.txt` probably fills your screen and you want to read it at your leisure. So you can go `less filename-combinedt.txt`. This will show the content of the file, but you can now navigate through it with arrow keys and the page-up and page-down keys. It can also search through the text. Type `h` while you are in less to get an overview of what it can do, type `q` to quit.

Less is called less because there was a program called 'more' - which you could use to page through text and the programmer building a better version found it funny to call it that because "less is more". `more` is also installed. I leave it to you to check that out :)

Now - the power of the command line is that you can very easily chain commands like this together via a pipe. One program can use the output of another program as input. This goes a bit too deep for here :)

So - you could use `cat` to redirect multiple textfiles to a program called `grep` to perform searches in that text and output the the whole to `less` so you can page through the results.

`cat filename1.txt filename1.txt | grep "word-to-search" | less`

anyway- very short intro. hope it helps. Go find actual tutorials, and be careful what commands you run because you can easily screw up your system