10 USEFUL LINUX COMMANDS!
Tags: ubuntu, linux
Published: 2021-09-29 16:17:40

## New to linux?

I'm someone who is now using Linux as my main OS but remember quite well how difficult it was to get my head around the workings of Linux my first few weeks.

So today i'm going to share a number of helpful commands to get you on your way!

### cd (Change Directory)

Does exactly what it says on the tin.... it helps you change your directory in the company line. So for example, if you want to go into your download directory you can do the following;

    cd /home/username/Downloads/

You can also  use  the shorthand  version;

    cd ~/Downloads

The important bit of the second command is the ~ and the /

The tilde (~) is the Linux shortcut for the home directory whereas ~/ references the start of a directory in the logged in users folder.

![Output](https://raspada-blog.co.uk/storage/wink/images/XKZfnDb59WuQumFYNXCXpNcdJDMtAMqeTgmtD4Qh.jpg)

Want to go back 1 folder? you can do the following instead of typing the whole path again:

![Output](https://raspada-blog.co.uk/storage/wink/images/LYtcfYkXkf11sPniZl0AhFfec1PzKccR5jS5K99p.jpg)

### ls (List)

I use this an awful lot on my server when navigating through folders to see if I'm in the right folder or not. Another thing i tend to do is use the -l option on the command to get the permissions of the files and folders. the -l option essentially means show me the long format of the list with permissions.

![Output](https://raspada-blog.co.uk/storage/wink/images/q0dRp1PyIk1vCJL9WFeZppaWOsd8iaGDSHWnG3Vz.jpg)

If you take a look at 10 lines down in the above window it shows "total 8". What this is actually doing is counting the number of files in the 2 sub folders  **_Example-Folder-1_** and **_Example-Folder-2_**

There is a fair few more options for the list command like  `ls -r`  which will display the files in reverse order or  `ls -S`  which will sort the files by file size.

### pwd (Print Work Directory)

When it says Print it means to the terminal output not a piece of paper :P other than that.... it does exactly what it says on the tin.

![Output](https://raspada-blog.co.uk/storage/wink/images/79ZoJR3KVKGJV5NrNFNLI2CR7PLWjIzluffIJr9d.jpg)

I use this sometimes if i need to find out what the current directory is and run a command that requires the pull path.

### mkdir & rmdir (Make and Remove directory)

These 2 commands are great for quick editing through the terminal of folders.

if you use the  `mkdir`  command it will create a folder for you with the relevant file with  **Read**,  **Write**  &  **Execute**  rights to your user and group and  **Read**  &  **Execute** for the "other". I'll be going through the file permissions in a future post so stay tuned.

![Output](https://raspada-blog.co.uk/storage/wink/images/JeafT9psnTm4cFTBve6HBKi2wzJncda0TFnVgXoV.jpg)

### shutdown

I don't think this one needs much introduction but it does actually come with a few options.

    sudo shutdown now

This shuts down the computer right now.

    sudo shutdown -r now

This shuts down the computer in the correct manner and then restarts it again.

Alternatively you can use:

    sudo shutdown -r 0

which does the same thing.

Want to schedule a shutdown? no problem the below command shuts down the PC in 15 minutes from when enter is hit on the command.

    sudo shutdown -h 15

﻿ or if you want to shutdown at a specific time of the day you can do so by passing the 24 hour timestamp u want.

    sudo shutdown 16:00

Mistype your shutdown schedule command? thats fine too... you can simply cancel it with the following command.

    sudo shutdown -c

### touch

this is another handy command if you want to create empty files on your system, like if you want to create an empty text file you can do with this command.

![Output](https://raspada-blog.co.uk/storage/wink/images/EQj3ghGYdjm3Ob6ZuxwcSDPjYYlnQivlfcrTg6c5.jpg)

You can also use this to create files which are hidden as standard by the Linux OS (files starting with .)

![Output](https://raspada-blog.co.uk/storage/wink/images/yyIUThPh198U5KpOxLV4N5eYTr75fvkcmIJfwpof.jpg)

Notice that when i do the ls command the file is hidden but when i do the ls -a (all, shows hidden files) it displays the file we just created.

### head & tail

The commands are very hand if like me you are in and out of lots of text files in the Linux terminal. (Tail is the handier of the two)

so i have generated a file with random text in it to demonstrate the following commands.

![Output](https://raspada-blog.co.uk/storage/wink/images/ptOMem1c9vRYql5OOn2oWipWnhRWfgXfI5GS5I8T.jpg)

As you can see  from  the screenshot  when  you time  `head`  the command looks at the first  10  lines  of  the file *(this is specified with the -n option)*  the same is for the tail it starts at the tail end of the document and the number of lines is specified exactly the same as the head command with a -n

I use tail a LOT on my web-server when i'm checking logs which in some cases can become thousands and thousands of lines long. Generally i only want to see the last 100 lines of a log (if you need more than that there is a serious problem :P) and what i do is output them lines to a text file on its own.

    tail -n 100 headandtail.txt > lastonehundred.txt

Lets break the command down

Look at the last 100 lines of the headandtail.txt file and output the result to lastonehundred.txt

### mv  (MoVe)

The move command is essentialy the cut tool from Windows it cuts/removes the file from its currently location and is output to the specified folder. in the previous example i tailed some text from headandtail.txt but meant to put it in the Example-Folder-1 so now i can use the mv command to do this, see screenshot below.

![Output](https://raspada-blog.co.uk/storage/wink/images/sLgXL24FNv3R6AncEiauUvKrbCiGIEJnCXGtWduM.jpg)

### cp (CoPy)

This command goes hand in hand with the move command in some sense but it leave a "copy" in the location its already at. as an example il copy the file lastonehundred.txt file back to the root folder.
![Output](https://raspada-blog.co.uk/storage/wink/images/HSmTrZ7WEIcANb7a9fPw6SsC1DHQvvvp4AV75kqa.jpg)

### clear

i mean this command is very simple but helps a lot when trying to focus in the terminal. type  `clear`  in your terminal that has lots of terminal text going on and it will remove it all and give you a terminal as if you just opened it up.

### Conclusion

I hope these snippets have been helpful for you all! if you found this post useful please consider following me on twitter  [@skino2020](https://twitter.com/skino2020)  and if you found it really helpful consider buying me a coffee  [here](https://www.buymeacoffee.com/skino2020).

Also please check out [www.raspada-blog.co.uk](www.raspada-blog.co.uk) for more tutorials!