Return to Level1Techs.com

Linux Terminal Walk-through

linux
reference
terminal
#1

This wiki is meant to be referenced as a way to learn the Linux terminal. Covered will be:

  • File Browsing/Management

    • Viewing your current directory
    • Viewing the contents of a directory
    • Changing from one directory to another (Navigation)
    • Viewing directory permissions
    • Viewing file permissions
  • Permissions

  • Networking

  • Editing Text Files

    • Editing via Nano
    • Editing via vim
  • Getting Help

    • Reading the manual

… And much much more. As this is a Wiki, and the beauty of such thing, is that you will be able to expand upon what is already here. So if you would like to expand on this you are more then welcome to do so.

To be able to contribute to the wiki, all you have to do is click on the teal colored “Edit” button at the bottom right of this post. Then add what you would like to add and then click on the “Save Edit” button. Also, please be sure to add yourself to the contributors section for recognition.

Contributors

If you need a glossary there is one here. Or you can scroll down to post #3.

File Browsing/management

contents

When doing file browsing and management via a graphical interface normally you can see where you are and where you want to go to via the directory tree, usually located in the side-pane of your file browser.

However, when navigating from the terminal, there is no side-panel that can be easily referenced to see where you are in your directory (file) structure.

So from knowing this, how do I know where I am currently in the file system when navigating from the terminal?

Well you would use the command pwd which stands for “present working directory”. And the output of that command will tell you were you are in the file system. For example if I were to open a terminal and type in pwd I would receive the following response:


[email protected]:~$ pwd
/home/Goalkeeper

Which is my home directory. Because when we first start a terminal emulator our current working directory is set to our home directory by default.

So now we know what directory we are currently in in the file system. However, with that command, we can not see everything that is contained in that particular directory (folder). To be able to view the contents of a directory use the command ls. The ls command lists the contents of a directory.


[email protected]:~$ pwd
/home/Goalkeeper

[email protected]:~$ ls

Desktop

Documents 

Music

Videos

So now we know that inside the directory /home/Goalkeeper there are four sub-directories - Desktop, Documents, Music, Videos. Now lets say that we want to navigate to the Desktop directory. To change a directory use the cd command.


[email protected]:~$ pwd
/home/Goalkeeper

[email protected]:~$ ls

Desktop

Documents 

Music

Videos

[email protected]:~$ cd Desktop

[email protected]:~/Desktop$

Too verify that we are in the Desktop directory we can use the ‘pwd’ command.


[email protected]:~$ pwd
/home/Goalkeeper

[email protected]:~$ ls

Desktop

Documents 

Music

Videos

[email protected]:~$ cd Desktop

[email protected]:~/Desktop$

[email protected]:~/Desktop$ pwd
/home/Goalkeeper/Desktop

As you can see we have successfully changed directories (cd), from the home directory to the Desktop directory.

Copy and delete

IMPORTANT NOTE: Before we go any further, a word of advice. In graphical file browser if you delete a file, it may end up in your trash can, but when you manipulate your files from command line, changes are permanent. This means, if you delete files, they will not end up in trash can anymore, but will be deleted permanently. Thus always, ALWAYS, make sure you have back ups for your files.

When you want to copy and delete files in command line, you may do so with specific commands. cp is for copying files, rm is for deleting.

Syntax for copy command is $ cp oldfile newfile. Let’s say you have file name linux_essay.txt located on you desktop directory, and you want to make a copy of this file in command line. Here’s an example of how to do it.

[email protected]:~$ cp /home/even/Desktop/linux_essay.txt /home/even/Desktop/linux_essay_V2.txt

This will create new file named linux_essay_V2.txt to your Desktop directory. This is also handy, if you want to create the copy of your file to other directory. Like this:

[email protected]:~$ cp /home/even/Desktop/linux_essay.txt /home/even/Documents/linux_essay_V2.txt

Now the file copy is in Documents directory, while the original remains in your Desktop.

Now that you have made a copy, but realize you don’t need it any more and want to delete it. Syntax for delete or remove command is $ rm filename. Here’s example:

[email protected]:~$ rm /home/even/Documents/linux_essay_V2.txt

Note that you can always do these actions also by first navigating in your desired directory, and manipulating files without the need to specify the file path in your commands. If you are in your Documents directory, and want to delete file by first navigating there, you can do it like this:

[email protected]:~$ cd Documents

[email protected]:~/Documents$ rm linux_essay_V2.txt

Rename files using mv

mv command is for moving files, but it can also be used to rename files. Syntax is $ mv old_file_name new_file_name

Here’s example. We will rename .png picture file:

[email protected]:~$ mv picture.png picture1.png

Now if you go to check out, the file name is changed. Note, that above example assumes you have navigated to the directory where the file is located.

If you want, you can also rename files by adding the file path to your command. Then you do not have to navigate to the actual directory.

[email protected]:~$ mv /home/even/test1/picture1.png /home/even/test1/picture.png

Move files using mv

Syntax for moving files is similar to what you do when you want to rename files using mv. You can move files with the same syntax $ mv file destination

You can navigate to the directory where the file is located, and then simply specify the path to directory you wish to move the file:

[email protected]:~/extra_folder$ mv picture.png /home/even/picture_folder/

Above will move the file named picture.png to directory named picture_folder

If you do not want to navigate to the directory, you can also specify both the file path to the file you wish to move, and the file path to the directory you want to move the file:

This example will move file named picture.png from picture_folder -directory to extra_folder -directory.

[email protected]:~$ mv /home/even/picture_folder/picture.png /home/even/extra_folder/

Move files using rsync

I’ll write something about moving files with rsync later. - @Even747

Permissions

contents

Let’s start with the permission command you should never run: sudo chmod 777 {dir or file}
– everyone can read write and modify
(More to come later @Heimdallr

Networking

contents

Filler text. Add things here.

Editing Text Files

Nano

Editing via Nano

vim

Editing via vim

How-to Just Kill-it-on Linux!

That’s easy enough to remember, right? No?

Happy Just Keepin’ Linux!

Here, Just Kick Leaves

What do all of these words have in common? They start with the letters to control Vim!

The four basic movements:

H - Left
J - Down
K - Up
L - Right

If you want to move right 5 spaces:

5, then L

We’ll get more advanced in a second. By now you’re probably wanting to type something.

Normal/Command mode is the default starting mode in Vim. To enter Insert mode, press I.

image

image

Escape will put you back into Command mode.

To save your file, in Command mode, enter :w filename. Yes, the colon is important. If you already have a file name (mine is named test, as you can see above next to Normal and Insert), then :w! will suffice. You can quit with :q!, and you can save and quit/close the file with :wq. No exclamation point necessary. The ! is used to force an operation, which is important in quit or write so there is not a fragment buffer left over.

// TODO add more Vim awesomeness

Getting Help

Using the man pages

Meta Discussion thread: https://forum.level1techs.com/t/meta-discussion-for-linux-terminal-walk-through/137469

10 Likes

closed #2
0 Likes

#3

Glossary

cd

  • Change directory. man cd for more info.
1 Like