Category: Linux Tutorial Series

  • Linux Tutorial Series – 47 – The su command

    Here is the video version, if you prefer it:

    The su command is used to start a shell as another user (most often the superuser). (Shotts, 2019)⁠ If you want to use it, this is what you’d write:

    su [-[l]] [user]

    This is some new notation? What does this mean? Everything enclosed in square braces is optional, meaning you can execute the command without writing any of it. (Barrett, 2016)⁠ Couple of examples of valid commands:

    su

    su -

    su -l

    su -l mislav

    su - mislav

    su mislav

    All are valid. If you don’t specify the user it is assumed you want to start the shell as the superuser. The -l option means you want to change to that user’s home directory. To enter the previous shell, type exit.

    The -c option is used to execute a command as another user like so:

    su -c 'command'

    but I have never used it. In general, I have never found myself using the su command – whenever I want to do something as the superuser, I use sudo.

    A caveat: If you switch to the superuser, your prompt will change from $ to #, like so:

    mislav@mislavovo-racunalo:~$ su

    Password:

    root@mislavovo-racunalo:/home/mislav#

    Hope you found this useful!

    References

    Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Pages 171-172

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 126-127

  • Linux Tutorial Series – 46 – The sudo command

    To refresh your memory, let me remind you that in Linux there are two kinds of users – regular users and superusers.

    What is the difference? The superuser is able to do more than the regular user, basically. If you attempt to do some things as a regular user, which you don’t have permissions for, you will not be allowed to do that. Permissions are a topic for a different post, but you can think of the difference between the regular user and the superuser as follows – both regular users and superusers are in a club. Superuser is in the VIP section and regular users are in the “normal” section. Superusers can walk from VIP to the “normal” section and reverse, but regular users can’t get to VIP, because bouncers would ask them for the “special bracelet” and they wouldn’t have it, so they would not be allowed in the VIP section.

    The sudo command allows regular users to execute commands which require superuser permissions. More technically, the sudo command allows you to execute commands as some other user, but in most cases that user is the superuser. (Shotts, 2019)⁠ The syntax is as follows:

    sudo someCommand

    Basically, you prefix whatever you want to run with sudo. Then you will be prompted for your password and once you enter it, voila – you have executed the command as the superuser.

    Why isn’t everyone the superuser? Fair question. There are two answers which make sense:

    • If multiple people are using the computer, then one person (the most responsible person) should be the superuser (the administrator) and others should just be regular users in order not to mess something up
    • Ever heard that Linux is pretty secure (as in, not a lot of viruses)? Well, that is because of the separation of superusers and regular users. Even if you download a certain malware (malware is a malicious program that tries to do harm to your computer), if you are a regular user, the malware won’t be able to execute all of the commands and access all files on your computer and therefore the damage will not be as devastating as if you were the superuser. Think of it like this – if a fight breaks out in our imaginary club (call it “The Penguin’s Hideout”), if it breaks out on the “normal” section there will be some damage, but not much. However, if there is a fight in the VIP section, oh boy! All of those expensive bottles of champagne and the crystal vases and the wonderful decoration are destroyed. Same as what happens in the computer.

    Hope you found this useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 127-128

  • Linux Tutorial Series – 45 – head and tail commands

    Here is the video version, if you prefer it:

    The head command is used to display the first 10 lines of a file. The tail command is used to display the last 10 lines of the file. (Barrett, 2016)

    Both of the commands have an option -n which control how many lines you want to output. By default it is 10, but you could write

    head -n 12

    and head would output 12 lines at the beginning of the file.

    A really cool thing about tail is that it has the -f option, which enables you to watch a file actively; you get new lines which are written to a file displayed. Why is this useful? Well, if you are watching some system file (a file which contains information about devices connected to your computer, for example), you could find out some information about the newly connected device.

    Hope you learned something new!

    References

    Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Pages 60-61

  • Linux Tutorial Series – 44 – The less command

    Here is the video version, if you prefer it:

    The less command is used to paginate through contents of a text file. (Ward, 2014)⁠ You navigate it by using the following keys (these are the most important):

    • Space for page down
    • B for page up (no need to keep Caps Lock on; just press B on your keyboard)
    • Q for quitting less

    As you can probably suppose, less is better to use when reading text files than cat, because it outputs them more conveniently; it doesn’t just dump the contents of the file to your screen like cat does.

    Fun fact: man uses less (“Does man command invoke less command to display manual contents?,” n.d.)⁠

    Hope you learned something new!

    References

    Does man command invoke less command to display manual contents? (n.d.). Retrieved January 8, 2020, from https://askubuntu.com/questions/322851/does-man-command-invoke-less-command-to-display-manual-contents

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 19

  • Linux Tutorial Series – 43 – Did you see it yet?

    Here is the video version, if you prefer it:

    Heya,

    did you notice the general command structure? To remind you, it looks like:

    command -options arguments

    Let’s take a look at the commands we learned so far, applying the abstract command structure over them:

    • cd arguments
    • pwd
    • man arguments
    • ls options

    I hope this helped shed light on the underlying general command structure.

    Talk soon!

  • Linux Tutorial Series – 42 – The cat command

    Here is the video version, if you prefer it:

    The cat command is used to view contents of a file. More specifically, the cat command reads the contents of one or more files and copies them to standard output. (Shotts, 2019)⁠ 

    Here is an example of its usage:

    mislav@mislavovo-racunalo:~/Documents$ cat test.txt

    Something

    Something on another line

    This was a short text file, but for large files, output of cat is messy. There are other commands (such as less) which also show you the contents of a file, but in a much more convenient fashion. We will talk about these other commands very soon.

    Hope you learned something new!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 83-85

  • Linux Tutorial Series – 41 – The echo command

    Here is the video version, if you prefer it:

    The echo command is used to print its arguments to standard output. (Ward, 2014)⁠ “Standard output” is, in most cases, another word for “your monitor”.

    It is used like this:

    echo somethingToEcho

    For example:

    mislav@mislavovo-racunalo:~$ echo Wondering my usefulness, reader? Well, I will be useful later on, for now, just remember that I exist!

    Wondering my usefulness, reader? Well, I will be useful later on, for now, just remember that I exist!

    Oh my God, the command can talk! It is actually accurate in what it said – it is useful, but later when you learn about things such as expansions of shell globs. But that’s for another post.

    Hope you learned something useful!

    References

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 16

  • Linux Tutorial Series – 40 – The rmdir command

    Here is the video version, if you prefer it:

    The rmdir command is used to remove empty directories. (Barrett, 2016) Its usage is as follows:

    rmdir emptyDir1

    or (for deleting multiple empty directories):

    rmdir emptyDir1 emptyDir2 …

    Note that rmdir only removes empty directories. To remove directories that contain files, use rm -r, but please do remember to use it with extreme caution!

    Thank you for reading and hope you learned something useful!

    References

    Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Page 55

  • Linux Tutorial Series – 39 – The mkdir command

    Here is the video version, if you prefer it:

    The mkdir command is used to create a directory (or directories). (Shotts, 2019)⁠ Its usage is as follows:

    mkdir dir1

    for one directory, or

    mkdir dir1 dir2 …

    for multiple directories.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 58-59

  • Linux Tutorial Series – 38 – The touch command

    Here is the video version, if you prefer it:

    The touch command is used for changing file timestamps (or creating new files). (“touch(1) – Linux man page,” n.d.)⁠ It is used as follows:

    touch fileName

    If the file named fileName does not exist, the file with the name fileName is created. If the file named fileName already exists, then only its modification time is modified to the current time.

    I have used the touch command a few times to create new files.

    Hope you learned something new!

    References

    touch(1) – Linux man page. (n.d.). Retrieved January 6, 2020, from https://linux.die.net/man/1/touch